iteration
This commit is contained in:
parent
d0ea038cdb
commit
f63ab77fc1
20
lns.lua
20
lns.lua
@ -18,6 +18,22 @@ settings.define("lns_client.lns_server", {
|
||||
allow_dynamic_lns_hosts = settings.get("lns_client.allow_dynamic_lns_hosts")
|
||||
lns_server_id = settings.get("lns_client.lns_server")
|
||||
|
||||
function load_cache()
|
||||
if fs.exists("lns_cache.db") then
|
||||
db = fs.open("lns_cache.db", "r")
|
||||
db_contents = db.readAll()
|
||||
db.close()
|
||||
|
||||
cache = textutils.unserialize(db_contents)
|
||||
end
|
||||
end
|
||||
|
||||
function save_cache()
|
||||
db = fs.open("lns_cache.db", "w")
|
||||
db.write(textutils.serialize(cache))
|
||||
db.close()
|
||||
end
|
||||
|
||||
function lns_lookup(remote_hostname)
|
||||
local data = {
|
||||
["action"] = "lookup",
|
||||
@ -46,6 +62,9 @@ function lns_lookup(remote_hostname)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
load_cache()
|
||||
|
||||
local action = args[1]
|
||||
if action == nil then
|
||||
io.write("Usage: lns <action>\n")
|
||||
@ -68,6 +87,7 @@ if action == "lookup" then
|
||||
if result ~= nil then
|
||||
io.write(result)
|
||||
cache[hostname] = result
|
||||
save_cache()
|
||||
end
|
||||
|
||||
elseif action == "clear" then
|
||||
|
Loading…
Reference in New Issue
Block a user