Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- write("Initializing messenger...")
- -- https://stackoverflow.com/a/7615129/13347795
- function split(input, maxSplits, sep)
- if sep == nil then
- sep = ";"
- end
- splits = {}
- splitCount = 0
- for str in string.gmatch(input, "[^"..sep.."]+") do
- if maxSplits ~= nil and splitCount > maxSplits then
- splits[splitCount] = splits[splitCount]..sep..str
- else
- table.insert(splits, str)
- splitCount = splitCount + 1
- end
- end
- return splits
- end
- function readLoop()
- while true do
- message = read()
- rednet.broadcast(message, "broadcast-messenger-message")
- end
- end
- function rednetLoop()
- while true do
- id, message = rednet.receive("broadcast-messenger-message")
- print(id..": "..message)
- end
- end
- print(" Done!")
- print("Loading messages...")
- peripheral.find("modem", rednet.open)
- rednet.broadcast(nil, "request-messenger-backlog")
- _, response = rednet.receive("response-messenger-backlog")
- term.clear()
- term.setCursorPos(1, 1)
- for _, row in ipairs(split(response, nil, "\n")) do
- date, time, id, message = table.unpack(split(row, 3))
- if message ~= nil then
- if id == tostring(os.getComputerID()) then
- print(message)
- else
- print(id..": "..message)
- end
- end
- end
- parallel.waitForAll(readLoop, rednetLoop)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement