Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.clear()
- term.setCursorPos(1,1)
- function LR()
- local n=1
- while true do
- local x, y=term.getCursorPos()
- term.clearLine()
- if n==1 then write(">LEFT< RIGHT") else write (" LEFT >RIGHT<") end
- term.setCursorPos(x, y)
- a, b=os.pullEventRaw()
- while a~="key" do a, b=os.pullEventRaw() end
- if b==203 and n==2 then n=1 end
- if b==205 and n==1 then n=2 end
- if b==28 then print("") break end
- end
- if n==1 then return true end
- if n==2 then return false end
- return false
- end
- local chatTable = { [1] = "Welcome to DSC Chat! (/help for commands)" }
- local chatLine = 1
- local message = ""
- local user = "???"
- local compID = os.computerID()
- local toID = ""
- local msgMessage = ""
- local msgSent = ""
- function drawLine()
- term.setCursorPos( 1, 17 )
- term.clearLine()
- for n=1,49 do
- io.write("=")
- end
- term.setCursorPos(1,18)
- term.clearLine()
- write(username)
- write(": ")
- write(message)
- end
- function addChat(str)
- if chatLine < 16 then
- table.insert(chatTable, str)
- chatLine = chatLine + 1
- else
- for n=1,15 do
- chatTable[n] = chatTable[n+1]
- end
- chatTable[16] = str
- end
- end
- function quit()
- os.exit()
- end
- function showChat()
- term.setCursorPos( 1, 1 )
- for n=1,chatLine do
- term.clearLine()
- print(chatTable[n])
- end
- end
- print("Is your modem on the Left or the Right?")
- term.setCursorPos(1,18)
- if LR() == true then
- rednet.open("left")
- else
- rednet.open("right")
- end
- term.clear()
- repeat
- term.setCursorPos(1,1)
- print("Enter a username for yourself.")
- term.setCursorPos(1,18)
- user = read()
- if string.len(user) > 9 then
- term.setCursorPos(1,2)
- print("Name too long! 9 character maximum.")
- term.setCursorPos(1,18)
- elseif string.len(user) > 0 then
- write("Your username is ")
- write(user)
- print("")
- print("Entering Chat...")
- username = user
- end
- until string.len(user) ~=0
- sleep(2.0)
- term.clear()
- drawLine()
- rednet.broadcast("")
- rednet.broadcast(username .. " enters the room!")
- repeat
- term.setCursorPos(1,1)
- write(chatTable[chatLine] or "")
- drawLine()
- showChat()
- term.setCursorPos((3 + string.len(username) + string.len(message)),18)
- term.setCursorBlink( true )
- event, param = os.pullEventRaw()
- if event == "key" then
- if param == 28 then
- if string.sub(message,1,1) == "/" then
- if string.sub(message,1,6) == "/name " then
- if string.len(message) > 6 then
- if string.len(message) < 16 then
- user = username
- username = string.sub(message,7,string.len(message))
- message = "User '" .. user .. "' is now called '" .. username .. "'!"
- rednet.broadcast("")
- rednet.broadcast(message)
- addChat(message)
- message = ""
- drawLine()
- else
- addChat("<SYS> Name too long! Maximum 9 characters.")
- message = ""
- end
- end
- elseif string.sub(message,1,4) == "/me " then
- local meMessage = string.sub(message,4,string.len(message))
- message = "*" .. username .. meMessage
- rednet.broadcast("")
- rednet.broadcast(message)
- addChat(message)
- message = ""
- drawLine()
- elseif string.sub(message,1,5) == "/list" then
- rednet.broadcast("")
- rednet.broadcast(message)
- message = ""
- elseif string.sub(message,1,5) == "/exit" then
- addChat("<SYS> Goodbye!")
- rednet.broadcast("")
- rednet.broadcast("User '" .. username .. "' exits the room.")
- sleep(1.0)
- term.clear()
- term.setCursorPos(1,1)
- break
- elseif string.sub(message,1,5) == "/quit" then
- addChat("<SYS> Goodbye!")
- rednet.broadcast("")
- rednet.broadcast("User '" .. username .. "' exits the room.")
- sleep(1.0)
- term.clear()
- term.setCursorPos(1,1)
- break
- elseif string.sub(message,1,5) == "/help" then
- addChat("/help - lists programs")
- addChat("/name <name> - changes username")
- addChat("/list - lists connected users, and console IDs")
- addChat("/me - used as emote")
- addChat("/clear - clears the screen")
- addChat("/msg <ID> <message> - sends a private message")
- addChat("/exit - exits the program")
- message = ""
- elseif string.sub(message,1,5) == "/msg " then
- if string.len(message) > 5 then
- if string.sub(message,7,7) == " " then
- toID = string.sub(message,6,6)
- msgMessage = string.sub(message,8,string.len(message))
- addChat("You whisper to #" .. toID .. ": " .. msgMessage)
- message = username .. " whispers to you: " .. msgMessage
- toID = tonumber(toID)
- rednet.send(toID,"")
- rednet.send(toID,message)
- message = ""
- elseif string.sub(message, 8,8) == " " then
- toID = string.sub(message,6,7)
- msgMessage = string.sub(message,9,string.len(message))
- addChat("You whisper to #" .. toID .. ": " .. msgMessage)
- message = username .. " whispers to you: " .. msgMessage
- toID = tonumber(toID)
- rednet.send(toID,"")
- rednet.send(toID,message)
- message = ""
- elseif string.sub(message, 9,9) == " " then
- toID = string.sub(message,6,8)
- msgMessage = string.sub(message,10,string.len(message))
- addChat("You whisper to #" .. toID .. ": " .. msgMessage)
- message = username .. " whispers to you: " .. msgMessage
- toID = tonumber(toID)
- rednet.send(toID,"")
- rednet.send(toID,message)
- message = ""
- elseif string.sub(message,10,10) == " " then
- toID = string.sub(message,6,9)
- msgMessage = string.sub(message,11,string.len(message))
- addChat("You whisper to #" .. toID .. ": " .. msgMessage)
- message = username .. " whispers to you: " .. msgMessage
- toID = tonumber(toID)
- rednet.send(toID,"")
- rednet.send(toID,message)
- message = ""
- end
- end
- elseif string.sub(message,1,3) == "/m " then
- if string.len(message) > 3 then
- if string.sub(message,5,5) == " " then
- toID = string.sub(message,4,4)
- msgMessage = string.sub(message,6,string.len(message))
- addChat("You whisper to #" .. toID .. ": " .. msgMessage)
- message = username .. " whispers to you: " .. msgMessage
- toID = tonumber(toID)
- rednet.send(toID,"")
- rednet.send(toID,message)
- message = ""
- elseif string.sub(message, 6,6) == " " then
- toID = string.sub(message,4,5)
- msgMessage = string.sub(message,7,string.len(message))
- addChat("You whisper to #" .. toID .. ": " .. msgMessage)
- message = username .. " whispers to you: " .. msgMessage
- toID = tonumber(toID)
- rednet.send(toID,"")
- rednet.send(toID,message)
- message = ""
- elseif string.sub(message, 7,7) == " " then
- toID = string.sub(message,4,6)
- msgMessage = string.sub(message,8,string.len(message))
- addChat("You whisper to #" .. toID .. ": " .. msgMessage)
- message = username .. " whispers to you: " .. msgMessage
- toID = tonumber(toID)
- rednet.send(toID,"")
- rednet.send(toID,message)
- message = ""
- elseif string.sub(message,8,8) == " " then
- toID = string.sub(message,4,7)
- msgMessage = string.sub(message,9,string.len(message))
- addChat("You whisper to #" .. toID .. ": " .. msgMessage)
- message = username .. " whispers to you: " .. msgMessage
- toID = tonumber(toID)
- rednet.send(toID,"")
- rednet.send(toID,message)
- message = ""
- end
- end
- elseif string.sub(message,1,6) == "/clear" then
- term.clear()
- for n=1,16 do
- addChat(" ")
- end
- chatTable = {}
- chatLine = 1
- message = ""
- else
- message = ""
- end
- else
- if string.len(message) > 0 then
- username = tostring(username)
- message = tostring(message)
- message = "<" .. username .. "> " .. message
- rednet.broadcast("")
- rednet.broadcast(message)
- addChat(message)
- message = ""
- drawLine()
- end
- end
- elseif param == 14 then
- message = string.sub(message,1,string.len(message)-1)
- drawLine()
- end
- end
- if event == "char" then
- if string.len(message) < 40 then
- message = message .. param
- end
- drawLine()
- end
- if event == "rednet_message" then
- id, incoming = rednet.receive(0.5)
- if incoming == "/list" then
- rednet.send(id,"")
- rednet.send(id,"User '" .. username .. "' is connected at terminal #" .. compID)
- else
- addChat(incoming)
- end
- end
- until message == "override"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement