iteration
This commit is contained in:
@ -38,27 +38,30 @@ load_data()
|
|||||||
|
|
||||||
while true do
|
while true do
|
||||||
client_id, msg = rednet.receive()
|
client_id, msg = rednet.receive()
|
||||||
|
request = textutils.unserialize(msg)
|
||||||
|
|
||||||
-- split string msg into action and hostname with ':' as a delimiter using string.unpack
|
if request.action == nil or request.hostname == nil then
|
||||||
local action, hostname = split(msg, ":")
|
rednet.send(client_id, "invalid request")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if action == "lookup" then
|
if request.action == "lookup" then
|
||||||
|
|
||||||
-- check if hostname in data
|
-- check if hostname in data
|
||||||
if data[hostname] == nil then
|
if request.hostname == nil then
|
||||||
rednet.send(client_id, "not found")
|
rednet.send(client_id, "not found")
|
||||||
else
|
else
|
||||||
rednet.send(client_id, data[hostname])
|
rednet.send(client_id, data[request.hostname])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if action == "reload" then
|
if request.action == "reload" then
|
||||||
load_data()
|
load_data()
|
||||||
rednet.send(client_id, "ok")
|
rednet.send(client_id, "ok")
|
||||||
end
|
end
|
||||||
|
|
||||||
if action == "register" then
|
if request.action == "register" then
|
||||||
data[hostname] = client_id
|
data[request.hostname] = client_id
|
||||||
save_data()
|
save_data()
|
||||||
rednet.send(client_id, "ok")
|
rednet.send(client_id, "ok")
|
||||||
end
|
end
|
||||||
|
@ -17,7 +17,14 @@ end
|
|||||||
rednet.open(modem_location)
|
rednet.open(modem_location)
|
||||||
receiverID = rednet.lookup("lns", lns_server)
|
receiverID = rednet.lookup("lns", lns_server)
|
||||||
current_time = os.time()
|
current_time = os.time()
|
||||||
rednet.send(receiverID, "register:" .. hostname)
|
|
||||||
|
|
||||||
|
data = {
|
||||||
|
[action] = "register",
|
||||||
|
[hostname] = hostname
|
||||||
|
}
|
||||||
|
|
||||||
|
rednet.send(receiverID, textutils.serialize(data))
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
id, msg = rednet.receive()
|
id, msg = rednet.receive()
|
||||||
|
Reference in New Issue
Block a user