Add in UID support, prepare for better errors
This commit is contained in:
parent
d294f9256c
commit
ab3bc38d4c
@ -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
|
||||
|
21
util.lua
21
util.lua
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user