Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("top")
- term.clear()
- term.setCursorPos(1,1)
- local command = {"-quit", "-msg", "-users"}
- local input = ""
- local quit = false
- CID = {0,1,2,3,4,5,6,7,8,9}
- UID = {}
- oldUID = {}
- UID[os.computerID()+1] = CurrentUsername
- function EraseLine()
- oldx, oldy = term.getCursorPos()
- term.clearLine()
- term.setCursorPos(1,oldy)
- end
- function GetUsers()
- for n=1,#UID do
- if n-1 ~= os.computerID() then
- rednet.send(n-1, "PING")
- idn, UID[n], distance = rednet.receive(0.5)
- end
- end
- end
- function Receive()
- while not quit do
- GetUsers()
- local id, msg = rednet.receive()
- if msg == "PING" then
- rednet.send(id, CurrentUsername)
- elseif msg == "LOGIN" then
- GetUsers()
- elseif msg == "QUIT" then
- EraseLine()
- UID[id+1] = nil
- else
- EraseLine()
- print(msg)
- end
- end
- end
- function Send()
- while true do
- write(CurrentUsername.." > ")
- local iscommand = false
- local input = read()
- for i=1,#command do
- if input == command[i] then
- if i == 1 then
- iscommand = true
- rednet.broadcast("QUIT")
- rednet.broadcast("* * "..CurrentUsername.." has left RedNet.")
- term.clear()
- term.setCursorPos(1,1)
- rednet.close("top")
- quit = true
- elseif i == 2 then
- iscommand = true
- write("Send message to: ")
- local whisper = read()
- write("Message: ")
- local msg = read()
- rednet.send(tonumber(whisper), CurrentUsername.." whispers: "..msg, true)
- elseif i == 3 then
- iscommand = true
- for n=1, #UID do
- write(UID[n].." ")
- end
- write("\n")
- end
- end
- end
- if iscommand == false then
- rednet.broadcast("<"..CurrentUsername.."> "..input)
- end
- end
- end
- print("-------------------------")
- print("Welcome to RedNet, "..CurrentUsername.."!")
- shell.run("realtime")
- print("Current Realtime is "..Time)
- print("Current Minecraft time is "..os.time())
- GetUsers()
- print("Current users online: ")
- for key,value in pairs(UID) do
- write(value.." ")
- end
- write("\n")
- print("-------------------------")
- rednet.broadcast("LOGIN")
- rednet.broadcast("* * "..CurrentUsername.." has joined RedNet.")
- parallel.waitForAny(Receive, Send)
Advertisement
Add Comment
Please, Sign In to add comment