Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- local function opnmdm()
- for i,v in pairs(rs.getSides()) do
- if peripheral.getType(v) == "modem" then
- if not rednet.isOpen(v) then rednet.open(v) end
- return true end
- end
- return false end
- local dmnlst,rlylst,hstID,sndr,mssg,dstnc,cmnd,prm1 = {},{},os.computerID(),tonumber(tArgs[5])
- local hstfnc = {
- PING = function() rednet.send(sndr,textutils.serialize({xPos,yPos,zPos})) end,
- bcst = function(bmssg) if dmnlst[sndr] then
- if bmssg then rednet.send(nil,bmssg) end
- end end,
- drp = function()
- local rID = rlylst[sndr]
- rlylst[sndr],rlylst[rID] = nil
- local hndl = fs.open("rlylst","w")
- hndl.write(textutils.serialize(rlylst)) hndl.close()
- rednet.send(sndr,"Relay to ID"..rID.." dropped")
- end,
- fwd = function(frwd)
- local rID,fmssg = frwd:match("(%d+)%s*(.*)$")
- rID = tonumber(rID)
- if rID and fmssg then rednet.send(rID,fmssg) end
- end,
- hsts = function() if dmnlst[sndr] then
- local ndx,hstlst = 0,{}
- rednet.broadcast("PING")
- repeat ndx = ndx+1
- hstlst[ndx] = {rednet.receive(0.5)}
- until not hstlst[ndx][1]
- rednet.send(sndr,textutils.serialize(hstlst))
- end end,
- reboot = function() if dmnlst[sndr] then shell.run("reboot") end end,
- rly = function(rlyID)
- local rID = tonumber(rlyID)
- rlylst[sndr],rlylst[rID] = rID,sndr
- local hndl = fs.open("rlylst","w")
- hndl.write(textutils.serialize(rlylst)) hndl.close()
- rednet.send(sndr,"Relaying to ID"..rlylst[sndr])
- end,
- rcvfl = function(flnm) if dmnlst[sndr] then
- local cntnt
- flnm,cntnt = flnm:match("(%S+)%s*(.*)")
- local hndl = fs.open(flnm,"w") hndl.write(cntnt) hndl.close()
- rednet.send(sndr,flnm.." Updated")
- end end,
- srvfl = function(flnm)
- flnm = flnm:match("%S+")
- local hndl = fs.open(flnm,"r")
- rednet.send(sndr,hndl.readAll()) hndl.close()
- end,
- }
- if opnmdm() then
- xPos,yPos,zPos = gps.locate(2,true )
- if tArgs[1] == "host" then
- if not xPos then xPos,yPos,zPos = tArgs[2],tArgs[3],tArgs[4]
- local itr8 = 0
- while not (xPos and yPos and zPos) do
- write("Enter x coordinate: ") xPos = tonumber(read())
- write("Enter y coordinate: ") yPos = tonumber(read())
- write("Enter z coordinate: ") zPos = tonumber(read())
- itr8 = itr8+1
- if itr8 > 3 then print("Invalid input") return false end
- end
- end
- print("GPS/Relay Node position "..xPos..","..yPos..","..zPos)
- local hndl = fs.open("startup","w")
- hndl.writeLine("shell.run(\"rnhst\",\"host\","..xPos..","..yPos..","..zPos..")")
- hndl.close()
- if sndr then hndl,xclst,dmnlst = fs.open("xclst","w"),{[sndr] = true},{[sndr] = true}
- hndl.writeLine(textutils.serialize(xclst)) hndl.close()
- elseif fs.exists("xclst") then hndl = fs.open("xclst","r")
- xclst = textutils.unserialize(hndl.readAll()) hndl.close()
- end
- if fs.exists("rlylst") then hndl = fs.open("rlylst","r")
- rlylst = textutils.unserialize(hndl.readAll()) hndl.close()
- end
- if fs.exists("dmnlst") then hndl = fs.open("dmnlst","r")
- dmnlst = textutils.unserialize(hndl.readAll()) hndl.close()
- else hndl = fs.open("dmnlst","w") hndl.writeLine(textutils.serialize(dmnlst)) hndl.close()end
- repeat sndr,mssg,dstnc = rednet.receive()
- if rlylst[hstID] then rednet.send(rlylst[hstID],sndr..":"..mssg) end
- if xclst and not xclst[sndr] then cmnd = "none" else
- cmnd,prm1 = mssg:match("^(%S+)%s*(.*)")
- if hstfnc[cmnd] then hstfnc[cmnd](prm1) end
- end
- if rlylst[sndr] and not hstfnc[cmnd] then rednet.send(rlylst[sndr],mssg) end
- until false
- return true end
- else print("could not open modem") return false
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement