Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- modem = peripheral.find("modem")
- rednet.open("top")
- local channelID
- local currentLine = 2
- local privateOrPublic
- local inChat = false
- local computerID
- function publicOrPrivate()
- while true do
- term.clear()
- term.setCursorPos(1,1)
- term.write("Please Type 1 For Private and 2 For Public")
- term.setCursorPos(1,2)
- privateOrPublic = tonumber(read())
- if privateOrPublic then
- break
- else
- term.clear()
- term.setCursorPos(1,1)
- term.write("INVALID SELECTION PRESS ANY KEY TO CONTINUE")
- local event, key = os.pullEvent("key")
- end
- end
- end
- function privateMessage()
- while true do
- term.clear()
- term.setCursorPos(1,1)
- term.write("Please Input The ID of The Computer")
- term.setCursorPos(1,2)
- term.write("ID: ")
- computerID = tonumber(read())
- if computerID then
- term.clear()
- term.setCursorPos(1,1)
- inChat = true
- term.write("Press F4 to Exit at Anytime")
- term.setCursorPos(1,2)
- rednet.send(computerID, "User Has Joined The Chat")
- while inChat do
- parallel.waitForAny(listenForMessages, sendMessageToID, endMessaging)
- end
- break
- else
- term.clear()
- term.setCursorPos(1,1)
- term.write("INVALID COMPUTER ID PRESS ANY KEY TO TRY AGAIN")
- local event, key = os.pullEvent("key")
- end
- end
- end
- function listenForMessages()
- while inChat do
- local senderID, message = rednet.receive()
- term.write("ID " .. senderID .. ": " .. message)
- currentLine = currentLine + 1
- term.setCursorPos(1, currentLine)
- end
- end
- function sendMessageToID()
- while inChat do
- local message = read()
- rednet.send(computerID, message)
- currentLine = currentLine + 1
- term.setCursorPos(1, currentLine)
- end
- end
- function endMessaging()
- while inChat do
- local event, key = os.pullEvent("key")
- if key == keys.f4 then
- rednet.send(computerID, "User Has Exited The Chat")
- inChat = false
- end
- end
- end
- function publicMessage()
- while true do
- term.clear()
- term.setCursorPos(1,1)
- term.write("Please Input The ID of The Channel")
- term.setCursorPos(1,2)
- term.write("ID: ")
- channelID = tonumber(read())
- modem.open(channelID)
- if channelID then
- term.clear()
- term.setCursorPos(1,1)
- inChat = true
- term.write("Press F4 to Exit at Anytime")
- term.setCursorPos(1,2)
- modem.transmit(channelID, channelID, "ID ".. os.computerID() .. ":" .. "Has Joined The Chat")
- while inChat do
- parallel.waitForAny(listenForMessagesPublic, sendMessageToChannel, endMessagingPublic)
- end
- break
- else
- term.clear()
- term.setCursorPos(1,1)
- term.write("INVALID COMPUTER ID PRESS ANY KEY TO TRY AGAIN")
- local event, key = os.pullEvent("key")
- end
- end
- end
- function listenForMessages()
- while inChat do
- local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
- term.write(message)
- currentLine = currentLine + 1
- term.setCursorPos(1, currentLine)
- end
- end
- function sendMessageToID()
- while inChat do
- local message = read()
- modem.transmit(channelID, channelID, "ID ".. os.computerID() .. ":" .. message)
- currentLine = currentLine + 1
- term.setCursorPos(1, currentLine)
- end
- end
- function endMessaging()
- while inChat do
- local event, key = os.pullEvent("key")
- if key == keys.f4 then
- modem.transmit(channelID, channelID, "ID ".. os.computerID() .. ":" .. "Has Left The Chat")
- inChat = false
- end
- end
- end
- while true do
- publicOrPrivate()
- if privateOrPublic == 1 then
- privateMessage()
- else
- publicMessage()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement