iteration
This commit is contained in:
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")
|
allow_dynamic_lns_hosts = settings.get("lns_client.allow_dynamic_lns_hosts")
|
||||||
lns_server_id = settings.get("lns_client.lns_server")
|
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)
|
function lns_lookup(remote_hostname)
|
||||||
local data = {
|
local data = {
|
||||||
["action"] = "lookup",
|
["action"] = "lookup",
|
||||||
@ -46,6 +62,9 @@ function lns_lookup(remote_hostname)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
load_cache()
|
||||||
|
|
||||||
local action = args[1]
|
local action = args[1]
|
||||||
if action == nil then
|
if action == nil then
|
||||||
io.write("Usage: lns <action>\n")
|
io.write("Usage: lns <action>\n")
|
||||||
@ -68,6 +87,7 @@ if action == "lookup" then
|
|||||||
if result ~= nil then
|
if result ~= nil then
|
||||||
io.write(result)
|
io.write(result)
|
||||||
cache[hostname] = result
|
cache[hostname] = result
|
||||||
|
save_cache()
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif action == "clear" then
|
elseif action == "clear" then
|
||||||
|
Reference in New Issue
Block a user