From b576c57f18155cf8900935933219987a0e74a96c Mon Sep 17 00:00:00 2001 From: Layla Manley Date: Sun, 8 Oct 2023 01:39:10 -0400 Subject: [PATCH] iteration --- lns_server.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lns_server.lua b/lns_server.lua index 91b4b9e..8d37edd 100644 --- a/lns_server.lua +++ b/lns_server.lua @@ -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