iteration

This commit is contained in:
2023-10-08 02:44:20 -04:00
parent 22743c248c
commit a58ca7b94c
5 changed files with 35 additions and 35 deletions

View File

@@ -79,28 +79,28 @@ function split (inputstr, sep)
load_data()
while true do
client_id, msg = rednet.receive()
client_id, msg = rednet.receive("lns")
request = msg
if request.action == nil or request.hostname == nil then
rednet.send(client_id, "invalid request")
rednet.send(client_id, "invalid request", "lns")
end
if request.action == "lookup" then
-- check if hostname in data
if request.hostname == nil then
rednet.send(client_id, nil)
rednet.send(client_id, nil, "lns")
log("Sent nil to " .. client_id)
else
rednet.send(client_id, data[request.hostname])
rednet.send(client_id, data[request.hostname], "lns")
log("Sent " .. request.hostname .. " to " .. client_id)
end
end
if request.action == "reload" then
load_data()
rednet.send(client_id, "ok")
rednet.send(client_id, "ok", "lns")
log("Reloaded data")
end
@@ -113,9 +113,9 @@ while true do
rednet.send(authID, {
action = "token",
token = request.token
})
}, "auth")
local auth_response = rednet.receive()
local auth_response = rednet.receive("auth")
log_debug("Auth response: " .. auth_response)
local errorPos, errorEnd = string.find(auth_response, "invalid")
if errorPos then
@@ -134,9 +134,9 @@ while true do
data[request.hostname] = client_id
log("Registered " .. request.hostname .. " as " .. client_id)
save_data()
rednet.send(client_id, "ok")
rednet.send(client_id, "ok", "lns")
else
rednet.send(client_id, "auth required")
rednet.send(client_id, "auth required", "lns")
end
end
end