68 lines
1.3 KiB
Lua
68 lines
1.3 KiB
Lua
args = { ... }
|
|
|
|
cache = {}
|
|
|
|
allow_dynamic_lns_hosts = false
|
|
|
|
function lns_lookup(hostname)
|
|
local data = {
|
|
["action"] = "lookup",
|
|
["hostname"] = hostname
|
|
}
|
|
|
|
local lns_server_id = 7
|
|
if allow_dynamic_lns_hosts then
|
|
lns_server_id = rednet.lookup("lns", lns_server)
|
|
if lns_server_id == nil then
|
|
io.write("LNS Server not found!\n")
|
|
return nil
|
|
end
|
|
end
|
|
|
|
rednet.send(lns_server_id, data)
|
|
|
|
while true do
|
|
id, msg = rednet.receive()
|
|
if id == lns_server_id then
|
|
if msg == nil then
|
|
return nil
|
|
else
|
|
return msg
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
local action = args[1]
|
|
if action == nil then
|
|
io.write("Usage: lns <action>\n")
|
|
return
|
|
end
|
|
|
|
if action == "lookup" then
|
|
local hostname = args[2]
|
|
if hostname == nil then
|
|
io.write("Usage: lns lookup <hostname>\n")
|
|
return
|
|
end
|
|
|
|
if cache[hostname] ~= nil then
|
|
io.write(cache[hostname])
|
|
return
|
|
end
|
|
|
|
local id = lns_lookup(hostname)
|
|
if id ~= nil then
|
|
io.write(id)
|
|
cache[hostname] = id
|
|
end
|
|
|
|
elseif action == "clear" then
|
|
local data = {
|
|
["action"] = "reload"
|
|
}
|
|
|
|
lns_server_id = rednet.lookup("lns", lns_server)
|
|
rednet.send(lns_server_id, data)
|
|
print("Reloaded LNS Server")
|
|
end |