Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("/kernel/kerbase")
- local settings = "/kernel/.set"
- local username1244 = string.sub(kerbase.getLine(settings, 9), string.find(kerbase.getLine(settings, 9), ":")+1)
- local running = false
- shell.run("clear")
- --rednet.open("top")
- rednet.open("back")
- --rednet.open("side")
- u = true
- while u do
- write("Enter a Username: ")
- user = username1244
- shell.run("clear")
- write('Hold CTRL+T for 3 seconds to leave')
- running = true
- if user:find("|") then
- u = true
- print("Name Cannot Have '|'")
- else
- u = false
- end
- end
- rednet.broadcast(user.."| Has Joined The Chat")
- local function writeMes()
- w, h = term.getSize()
- term.setCursorPos(1, h-2)
- term.clearLine()
- term.setCursorPos(1, h-1)
- term.clearLine()
- write("Chat: ")
- mes = read()
- if term.isColor() then
- if mes:find("&") then
- color = mes:match("&([0-9]+)") or 1
- term.setTextColor(tonumber(color))
- message = mes:gsub("&([0-9]+)", "")
- cur = cur + 1
- if cur > h-3 then
- cur = 1
- shell.run("clear")
- end
- term.setCursorPos(1, cur)
- print(user..": "..message)
- message = user.."|"..mes
- rednet.broadcast(message)
- term.setTextColor(1)
- printed = false
- end
- end
- if printed == true then
- cur = cur + 1
- if cur > h-3 then
- cur = 1
- shell.run("clear")
- end
- term.setCursorPos(1, cur)
- print(user..": "..mes)
- mes = user.."|"..mes
- rednet.broadcast(mes)
- term.setTextColor(1)
- end
- printed = true
- end
- cur = 0
- local function readMes()
- id, mes, distance = rednet.receive()
- -- split mes
- a,b = string.find(mes, "|")
- name = mes:sub(1, a-1)
- message = mes:sub(b+1, #mes)
- if message == "^KICKALL" then
- shell.run("clear")
- error("You Have Been Kicked From Chat!")
- end
- -- set message color
- --[[if term.isColor() then
- if message:find("&") then
- color = message:match("&([0-9]+)")
- term.setTextColor(tonumber(color))
- message = message:gsub("&([0-9]+)", "")
- end
- end]]--
- cur = cur + 1
- if cur > h-3 then
- shell.run("clear")
- cur = 1
- end
- term.setCursorPos(1, cur)
- print(name..": "..message)
- term.setTextColor(1)
- end
- while true do
- local event = os.pullEventRaw()
- if event == "terminate" then
- shell.run("startup")
- return
- end
- if running then
- parallel.waitForAny(writeMes, readMes)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement