iteration

This commit is contained in:
Layla 2023-10-08 01:39:10 -04:00
parent 00cb10d9f5
commit b576c57f18

View File

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