iteration
This commit is contained in:
@ -7,6 +7,11 @@ rednet.open(modem_location)
|
|||||||
|
|
||||||
local data = {}
|
local data = {}
|
||||||
|
|
||||||
|
|
||||||
|
function log(str)
|
||||||
|
io.write("[" .. os.time() .. "] " .. str .. "\n")
|
||||||
|
end
|
||||||
|
|
||||||
function save_data()
|
function save_data()
|
||||||
db = fs.open("lns.db", "w")
|
db = fs.open("lns.db", "w")
|
||||||
db.write(textutils.serialize(data))
|
db.write(textutils.serialize(data))
|
||||||
@ -49,18 +54,22 @@ while true do
|
|||||||
-- check if hostname in data
|
-- check if hostname in data
|
||||||
if request.hostname == nil then
|
if request.hostname == nil then
|
||||||
rednet.send(client_id, nil)
|
rednet.send(client_id, nil)
|
||||||
|
log("Sent nil to " .. client_id)
|
||||||
else
|
else
|
||||||
rednet.send(client_id, data[request.hostname])
|
rednet.send(client_id, data[request.hostname])
|
||||||
|
log("Sent " .. request.hostname .. " to " .. client_id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if request.action == "reload" then
|
if request.action == "reload" then
|
||||||
load_data()
|
load_data()
|
||||||
rednet.send(client_id, "ok")
|
rednet.send(client_id, "ok")
|
||||||
|
log("Reloaded data")
|
||||||
end
|
end
|
||||||
|
|
||||||
if request.action == "register" then
|
if request.action == "register" then
|
||||||
data[request.hostname] = client_id
|
data[request.hostname] = client_id
|
||||||
|
log("Registered " .. request.hostname .. " as " .. client_id)
|
||||||
save_data()
|
save_data()
|
||||||
rednet.send(client_id, "ok")
|
rednet.send(client_id, "ok")
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user