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