diff --git a/server.lua b/server.lua index 879a501..76886d6 100644 --- a/server.lua +++ b/server.lua @@ -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 diff --git a/util.lua b/util.lua index 18ae626..cade61b 100644 --- a/util.lua +++ b/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