6677

CCBridge

Dec 24th, 2013
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.86 KB | None | 0 0
  1. local portsPath = "ports.cfg"
  2. local portsFile = fs.open(portsPath, "r")
  3. local portsCount = 0
  4.  
  5. local modem1 = peripheral.wrap("left")
  6. local modem2 = peripheral.wrap("right")
  7.  
  8. local openingPorts = true
  9.  
  10. while openingPorts do
  11.     local port = portsFile.readLine()
  12.     if (port == nil) or (portsCount > 128) then
  13.         openingPorts = false
  14.     elseif tonumber(port) ~= nil then
  15.         print("opening port: "..port)
  16.         modem1.open(tonumber(port))
  17.         modem2.open(tonumber(port))
  18.         portsCount = portsCount + 1
  19.     end
  20. end
  21. portsFile.close()
  22.  
  23. while true do
  24.     local event, side, channel, reply, message, distance = os.pullEvent()
  25.     if event == "modem_message" then
  26.         print(side.." "..channel.." "..reply.." "..message.." "..distance)
  27.         local sendSide
  28.         if side == "left" then
  29.             modem2.transmit(channel, reply, message)
  30.         else
  31.             modem1.transmit(channel, reply, message)
  32.         end
  33.     end
  34. end
Advertisement
Add Comment
Please, Sign In to add comment