Add in UID support, prepare for better errors

This commit is contained in:
osmarks 2018-05-06 08:12:05 +01:00
parent d294f9256c
commit ab3bc38d4c
2 changed files with 23 additions and 3 deletions

View File

@ -134,10 +134,11 @@ end
function processRequests()
while true do
local id, msg = rednet.receive "dragon"
if msg and msg.cmd then
if msg and msg.cmd and msg.uid then
local ok, r = pcall(processRequest, msg)
if not ok then r = "ERROR" end
if not ok then r = "ERROR" end
r.uid = msg.uid
rednet.send(id, r, "dragon")
end

View File

@ -2,13 +2,32 @@ local f = fs.open("conf", "r")
local conf = textutils.unserialise(f.readAll())
f.close()
local errors = {
matches = function(error, etyp)
return error and error[1] == etyp
end,
error = function(etyp, ...)
local ret = {etyp}
for _, arg in pairs({...}) do
table.insert(ret, arg)
end
return ret
end,
missingItems = "EITEMS",
noSpace = "ESPACE",
noPattern = "EPATTERN",
}
-- Queries Dragon servers. In a loop.
local function query(m)
local uid = math.random(0, 1000000000)
m.uid = uid
local msg
repeat
rednet.broadcast(m, "dragon")
_, msg = rednet.receive("dragon", 1)
until msg
until msg and msg.uid == uid
return msg
end