ZNZNCOOP

Repeater

Apr 16th, 2014
64
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local function printUsage()
  2.   print( "Usages: repeater <ID1> <ID2>" )
  3. end
  4.  
  5. local tArgs = { ... }
  6. if #tArgs < 2 then
  7.   printUsage()
  8.   return
  9. end
  10.  
  11. local ID1,ID2 = tonumber(tArgs[1]), tonumber(tArgs[2])
  12. if ID1 == nil or ID2 == nil or ID1==ID2 then
  13.   printUsage()
  14.   return
  15. end
  16.  
  17. if ip.open() then
  18.   print( "Connection ID "..ID1.." and "..ID2 )
  19.   local nServed1,nServed2 = 0, 0
  20.   while true do
  21.     sender,message,distance = rednet.receive()
  22.     if sender==ID1 then
  23.       rednet.send(ID2, message)
  24.       nServed1 = nServed1 + 1
  25.     end
  26.     if sender==ID2 then
  27.       rednet.send(ID1, message)
  28.       nServed2 = nServed2 + 1
  29.     end
  30.     write( nServed1.." received from "..ID1.." and "..nServed2.." received from "..ID2 )
  31.     local x,y = term.getCursorPos()
  32.     term.setCursorPos(1,y)
  33.   end
  34. end
RAW Paste Data