computercraft/packages/set_lns.lua

38 lines
870 B
Lua
Raw Normal View History

2023-10-08 04:57:23 +02:00
io.write("Enter the hostname: ")
hostname = io.read()
io.write("Enter the modem location: ")
modem_location = io.read()
rednet.open(modem_location)
receiverID = rednet.lookup("lns", lns_server)
current_time = os.time()
2023-10-08 05:36:37 +02:00
data = {
2023-10-08 05:38:28 +02:00
["action"] = "register",
2023-10-08 08:18:41 +02:00
["hostname"] = hostname,
["token"] = settings.get("auth.token", nil)
2023-10-08 05:36:37 +02:00
}
2023-10-08 08:44:20 +02:00
rednet.send(receiverID, data, "lns")
2023-10-08 04:57:23 +02:00
while true do
2023-10-08 08:44:20 +02:00
id, msg = rednet.receive("lns")
2023-10-08 05:45:04 +02:00
if id == receiverID then
if msg == "ok" then
print("Registered with LNS Server Successfully!")
break
else
print("Failed to register with LNS Server! Error: " .. msg)
break
end
-- timeout after 5 seconds
if os.time() - current_time > 5 then
print("Failed to register with LNS Server! Timeout!")
break
end
2023-10-08 04:57:23 +02:00
end
end