Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.clear()
- term.setCursorPos(1,1)
- print("Running Relay Program.")
- print("See Server-Monitor for my events")
- print("I am computer 'A1' seen at the top of the Server-Monitor at Y = 1")
- message = nil
- id = nil
- cpIds = {}
- nextRelayLeftCPID = nil
- nextEmailRelayLeft = 14329
- nextRelayRightCPID = nil
- nextEmailRelayRight = 9871
- emerCP = 1
- passwordCP = 6789
- passwordSever = 9875
- message = nil
- serverMon = peripheral.wrap("monitor_0")
- modemR = peripheral.wrap("right")
- modemL = peripheral.wrap("left")
- statMon = peripheral.wrap("top")
- modemR.open(43561)
- modemL.open(32654)
- modemR.transmit(34561, 0, "CP-List")
- event, side, freq, rfreq, message, disT = os.pullEvent("modem_message")
- if not (message == nil) then
- for i,p in string.gmatch(message, "(%d+)=(%S+)") do
- cpIds[i] = p
- end
- serverMon.setCursorPos(1,1)
- serverMon.clearLine()
- serverMon.setTextColor(colors.green)
- serverMon.write("Relay CP 'A1' loaded CPIDs")
- statMon.setBackgroundColor(colors.green)
- else
- serverMon.setCursorPos(1,1)
- serverMon.clearLine()
- serverMon.setTextColor(colors.red)
- serverMon.write("Relay CP 'A1' did not find IDCP or message was wrong")
- statMon.setBackgroundColor(colors.red)
- end
- while (true) do
- event, side, freq, rfreq, message, disT = os.pullEvent("modem_message")
- typeM, m = string.gmatch(message, "(%S+)=(.+)")
- if (typeM == nil or m == nil) then
- statMon.setBackgroundColor(colors.red)
- serverMon.setCursorPos(1,1)
- serverMon.clearLine()
- serverMon.setTextColor(colors.red)
- serverMon.write("Invaild message sent on freq " .. freq .. " from " .. disT .. " away from 'A1' relay CP")
- elseif (side == "right") then
- if (typeM == "email") then
- modemL.transmit(nextEmailRelayLeft, m)
- elseif (typeM == "access") then
- modemL.transmit(passwordCP, m)
- elseif (typeM == "emer") then
- modemL.transmit(emerCP, m)
- end
- elseif (side == "left") then
- if (typeM == "email") then
- modemL.transmit(nextEmailRelayRight, m)
- elseif (typeM == "access") then
- modemL.transmit(passwordSever, m)
- end
- else
- statMon.setBackgroundColor(colors.red)
- serverMon.setCursorPos(1,1)
- serverMon.clearLine()
- serverMon.setTextColor(colors.red)
- serverMon.write("Invaild side input: side = " .. side)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment