Advertisement
Guest User

relay.lua

a guest
Apr 9th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.26 KB | None | 0 0
  1. local PacketLog = {}
  2. local MainProtocol = "FireFlyISP"
  3.  
  4. local lstSides = {"left","right","top","bottom","front","back"}
  5. function OpenAll()
  6.     for i, side in pairs(lstSides) do
  7.         if (peripheral.isPresent(side)) then
  8.            if (peripheral.getType(side) == string.lower("modem")) then
  9.                 if not rednet.isOpen(side) then
  10.                     rednet.open(side)
  11.                 else
  12.                 end
  13.            end
  14.         end
  15.     end
  16. end--end function
  17.  
  18. function Listener()
  19.     while true do
  20.         local id, msg, protocol = rednet.receive()
  21.         if protocol == MainProtocol then
  22.             if string.find(msg, "|") then
  23.                 if CheckTable(PacketLog, msg) == false then
  24.                     table.insert(PacketLog, msg)
  25.                     rednet.broadcast(msg, MainProtocol)
  26.                 end
  27.             end
  28.         end
  29.     end
  30. end--end function
  31.  
  32. function CheckTable(Table1, CompareData)
  33.     var1 = false
  34.     if #Table1 > 0 then
  35.         for i=1, #Table1 do
  36.             if Table1[i] ~= nil then
  37.                 if Table1[i].."" == ""..CompareData then
  38.                     return true
  39.                 end
  40.             end
  41.             i=i + 1
  42.         end
  43.     end
  44.     return var1
  45. end
  46.  
  47. OpenAll()
  48. Listener()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement