Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- YamaCorpDisplayController, 2022, Yamazouki
- REDNET_SIDE =
- TIMEOUT_DELAY = 30
- rednet.open(REDNET_SIDE)
- function generateErrorMessage (str)
- return {"Error :", 0xFF0000, str, 0xFF0000}
- end
- ids = {}
- msg = {}
- while true do
- rnID, rnMsg, rnProto = rednet.receive("YamaCorp", TIMEOUT_DELAY)
- msg = {}
- msg.protocol = "display"
- msg.body = {}
- if rnID == nil then
- print("No signals since " .. TIMEOUT_DELAY .. "s")
- table.insert(msg.body, generateErrorMessage("no signal from main controller"))
- else
- if (rnProto == "YamaCorp") then
- rnMsg = textutils.unserializeJSON(rnMsg)
- if (rnMsg == nil) then
- print("error serializing JSON")
- table.insert(msg.body, generateErrorMessage("JSON error"))
- else
- proto = rnMsg.protocol
- body = rnMsg.body
- if (proto == 'global') then
- if (body == 'restart') then
- os.reboot()
- end
- elseif (proto == 'connect') then
- table.insert(ids, rnID)
- elseif (proto == 'display') then
- msg.body = body
- end
- end
- end
- end
- for i, id in ipairs(ids) do
- rednet.send(id, textutils.serializeJSON(msg), YamaCorp)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment