iteration

This commit is contained in:
2023-10-08 02:18:41 -04:00
parent eb55a5d783
commit c918c2da39
3 changed files with 74 additions and 9 deletions

View File

@@ -1,8 +1,31 @@
modem_location = "right"
settings.define("lns_server.modem_location", {
description = "Modem location",
type = "string",
default = "right"
})
modem_location = settings.get("lns_server.modem_location")
settings.define("lns_server.rednet_hostname", {
description = "Rednet hostname",
type = "string",
default = "test"
})
rednet.host("lns", "default")
settings.define("lns_server.require_auth", {
description = "Require authentication",
type = "boolean",
default = false
})
require_auth = settings.get("lns_server.require_auth")
settings.define("lns_server.auth_server", {
description = "Authentication server",
type = "string",
default = "auth.box"
})
rednet.host("lns", settings.get("lns_server.rednet_hostname"))
rednet.open(modem_location)
local data = {}
@@ -68,9 +91,37 @@ while true do
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")
local auth_passed = false
if require_auth then
local authID = data[auth_server]
if authID ~= nil then
rednet.send(authID, {
action = "token",
token = request.token
})
local auth_response = rednet.receive()
local errorPos, errorEnd = string.find(auth_response, "invalid")
if errorPos then
log("Error: " .. auth_response)
else
auth_passed = true
end
else
log("Error: Auth server not found to " .. client_id)
end
else
auth_passed = true
end
if auth_passed then
data[request.hostname] = client_id
log("Registered " .. request.hostname .. " as " .. client_id)
save_data()
rednet.send(client_id, "ok")
else
rednet.send(client_id, "auth required")
end
end
end