BeastmodeJD

Rednet-Relay

Dec 28th, 2019
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.22 KB | None | 0 0
  1. term.clear()
  2. term.setCursorPos(1,1)
  3. print("Running Relay Program.")
  4. print("See Server-Monitor for my events")
  5. print("I am computer 'A1' seen at the top of the Server-Monitor at Y = 1")
  6. message = nil
  7. id = nil
  8. cpIds = {}
  9. nextRelayLeftCPID = nil
  10. nextEmailRelayLeft = 14329
  11. nextRelayRightCPID = nil
  12. nextEmailRelayRight = 9871
  13. emerCP = 1
  14. passwordCP = 6789
  15. passwordSever = 9875
  16. message = nil
  17. serverMon = peripheral.wrap("monitor_0")
  18. modemR = peripheral.wrap("right")
  19. modemL = peripheral.wrap("left")
  20. statMon = peripheral.wrap("top")
  21. modemR.open(43561)
  22. modemL.open(32654)
  23.  
  24. modemR.transmit(34561, 0, "CP-List")
  25.  
  26.  
  27. event, side, freq, rfreq, message, disT = os.pullEvent("modem_message")
  28. if  not (message == nil) then  
  29.     for i,p in string.gmatch(message, "(%d+)=(%S+)") do
  30.         cpIds[i] = p
  31.     end
  32.     serverMon.setCursorPos(1,1)
  33.     serverMon.clearLine()
  34.     serverMon.setTextColor(colors.green)
  35.     serverMon.write("Relay CP 'A1' loaded CPIDs")
  36.     statMon.setBackgroundColor(colors.green)
  37. else
  38.     serverMon.setCursorPos(1,1)
  39.     serverMon.clearLine()
  40.     serverMon.setTextColor(colors.red)
  41.     serverMon.write("Relay CP 'A1' did not find IDCP or message was wrong")
  42.     statMon.setBackgroundColor(colors.red)
  43. end
  44.  
  45. while (true) do
  46.     event, side, freq, rfreq, message, disT = os.pullEvent("modem_message")
  47.     typeM, m = string.gmatch(message, "(%S+)=(.+)")
  48.     if (typeM == nil or m == nil) then
  49.     statMon.setBackgroundColor(colors.red)
  50.     serverMon.setCursorPos(1,1)
  51.     serverMon.clearLine()
  52.     serverMon.setTextColor(colors.red)
  53.     serverMon.write("Invaild message sent on freq " .. freq .. " from " .. disT .. " away from 'A1' relay CP")
  54.     elseif (side == "right") then
  55.         if (typeM == "email") then
  56.             modemL.transmit(nextEmailRelayLeft, m)
  57.         elseif (typeM == "access") then
  58.             modemL.transmit(passwordCP, m)
  59.         elseif (typeM == "emer") then
  60.             modemL.transmit(emerCP, m)
  61.         end
  62.     elseif (side == "left") then
  63.         if (typeM == "email") then
  64.             modemL.transmit(nextEmailRelayRight, m)
  65.         elseif (typeM == "access") then
  66.             modemL.transmit(passwordSever, m)
  67.         end
  68.     else
  69.         statMon.setBackgroundColor(colors.red)
  70.         serverMon.setCursorPos(1,1)
  71.         serverMon.clearLine()
  72.         serverMon.setTextColor(colors.red)
  73.         serverMon.write("Invaild side input: side = " .. side)
  74.     end
  75. end
Advertisement
Add Comment
Please, Sign In to add comment