iteration

This commit is contained in:
Layla 2023-10-08 03:24:17 -04:00
parent d147fe682c
commit c9e6e5d229
2 changed files with 5 additions and 5 deletions

View File

@ -106,20 +106,17 @@ while true do
if request.action == "token" then if request.action == "token" then
if request.token == nil or request.token == "" or request.token == -1 then if request.token == nil or request.token == "" or request.token == -1 then
rednet.send(client_id, "invalid request", "auth") rednet.send(client_id, "invalid request", "auth")
log("Token request from " .. client_id .. " denied (invalid request)")
else else
local found = false local found = false
for user, userdata in pairs(data.users) do for user, userdata in pairs(data.users) do
if userdata.token == request.token then if userdata.token == request.token then
log("Token request from " .. client_id .. " granted for " .. user)
rednet.send(client_id, user, "auth") rednet.send(client_id, user, "auth")
found = true found = true
end end
end end
if not found then if not found then
log("Token request from " .. client_id .. " denied (invalid token)")
rednet.send(client_id, "invalid token", "auth") rednet.send(client_id, "invalid token", "auth")
end end
end end

View File

@ -117,8 +117,11 @@ while true do
["token"] = request.token ["token"] = request.token
}, "auth") }, "auth")
authID, auth_response = rednet.receive("auth") local responseServerID = nil
log_debug("Auth response: " .. auth_response) while responseServerID ~= authID do
responseServerID, auth_response = rednet.receive("auth")
end
local errorPos, errorEnd = string.find(auth_response, "invalid") local errorPos, errorEnd = string.find(auth_response, "invalid")
if errorPos then if errorPos then
log("Error: " .. auth_response) log("Error: " .. auth_response)