Advertisement
Lyqyd

redrelay

Dec 29th, 2012
109
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. args = {...}
  2. if #args < 2 or tonumber(args[1]) == nil or tonumber(args[2]) == nil then
  3.     print("Usage:")
  4.     print("redrelay <id> <id>")
  5.     return
  6. else
  7.     local modemFound = false
  8.     for _,side in ipairs(rs.getSides()) do
  9.         if peripheral.getType(side) == "modem" then
  10.             rednet.open(side)
  11.             modemFound = true
  12.             break
  13.         end
  14.     end
  15.     if not modemFound then
  16.         print("No modem found!")
  17.         return
  18.     end
  19. end
  20.  
  21. local logTable = {}
  22. local id1, id2 = tonumber(args[1]), tonumber(args[2])
  23.  
  24. while true do
  25.     event = {os.pullEvent()}
  26.     if event[1] == "rednet_message" then
  27.         if event[2] == id1 or event[2] == id2 then
  28.             print(event[2]..": "..event[3])
  29.             table.insert(logTable, event[2]..": "..event[3])
  30.             rednet.send(event[2] == id1 and id2 or id1, event[3])
  31.         end
  32.     elseif event[1] == "char" and event[2] == "q" then
  33.         handle = io.open("/rednet_log", "w")
  34.         if handle then
  35.             for i=1, #logTable do
  36.                 handle:write(logTable[i].."\n")
  37.             end
  38.             handle:close()
  39.         end
  40.         return
  41.     end
  42. end
Advertisement
RAW Paste Data Copied
Advertisement