Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[Dex chat |client| script writted by Emma B aka anemonemma.
- feel free to edit as much as you want, just give me credit please.
- Thanks for using DexChat]]
- modem="back"
- rednet.open(modem)
- serverid=0 --change to server computer's id / router id if using routers.
- currtext=""
- lastx,lasty = 0
- sx,sy = term.getSize()
- lastlines={}
- linenum=sy-1
- function emptyTable(table)
- for i=1,#table do
- table[i]= nil
- end
- end
- emptyTable(lastlines)
- function clear() shell.run("clear") end
- function setPos(x,y) term.setCursorPos(x,y) end
- function rewrite()
- for i=1,linenum do
- setPos(1,-1+i)
- term.clearLine()
- if lastlines[i]~=nil then
- write(lastlines[i])
- end
- end
- end
- function backspace()
- local tempchars={}
- local finalchars={}
- for i=1,#currtext do
- a=currtext:sub(i, i)
- table.insert(tempchars, a)
- end
- for i=1,#tempchars-1 do
- table.insert(finalchars,tempchars[i])
- end
- currtext=""
- for i=1,#finalchars do
- currtext=currtext..finalchars[i]
- end
- setPos(1,sy)
- term.clearLine()
- write(currtext)
- end
- function lineOut(linetxt)
- for i=1,linenum-1 do
- lastlines[i]=lastlines[i+1]
- end
- lastlines[linenum]=linetxt
- rewrite()
- end
- function tryCommand(com)
- print(com)
- chrs={}
- emptyTable(chrs)
- for i=1,#com do tmpchr=string.sub(com, i, i) table.insert(chrs,tmpchr) end
- if chrs[1] == "/" then
- if com == "/list" then
- rednet.send(serverid,"/list")
- else if com == "/help" then
- lineOut(" ")
- lineOut("/help -Shows commands and their discriptions")
- lineOut("/list -Lists conncted computers")
- lineOut("/clear -Clears the screen")
- lineOut(" ")
- else if com == "/clear" then
- for i=1,linenum do
- lastlines[i]=nil
- end
- rewrite()
- else
- lineOut("Unknown Command. Try /help")
- end
- setPos(1,sy)
- term.clearLine()
- currtext=""
- return true
- end
- end
- end
- return false
- end
- slowRead = function()
- local trashe,par2 = os.pullEvent()
- if trashe == "key" then
- if par2 == 28 then
- if tryCommand(currtext) == false then
- rednet.send(serverid,u..":"..currtext)
- setPos(#currtext,sy)
- currtext=""
- term.clearLine()
- end
- end
- if par2 == 14 then
- backspace()
- end
- if par2 == 211 then
- rednet.send(serverid,os.getComputerID()..":disconnect")
- os.reboot()
- end
- end
- if trashe == "char" then
- currtext=currtext..par2
- setPos(#currtext,sy)
- term.clearLine()
- setPos(1,sy)
- write(currtext)
- end
- end
- receive = function()
- id,message=rednet.receive()
- for i=1,linenum-1 do
- lastlines[i]=lastlines[i+1]
- end
- lastlines[linenum]=message
- rewrite()
- end
- clear()
- lineOut("DexChat V4 Starting up.")
- lineOut("Enter Username: ")
- u=read()
- lastlines[linenum]="Enter Username: "..u
- rednet.send(serverid,u..":Connecting")
- lineOut("Connecting...")
- id,message=rednet.receive()
- repeat
- lineOut("Trying to login...")
- repeat
- if id ~= serverid then
- repeat
- id,message=rednet.receive()
- until id == serverid
- end
- if id == serverid then
- if message == "You are banned from this server" then
- lineOut("You are banned from this server")
- error()
- end
- if message == "Denied" then
- lineOut("You are being denied access to this server")
- error()
- end
- end
- until message==u.." has connected!"
- until id==serverid
- lineOut("You have connected to the server.")
- lineOut(" ")
- sleep(1.5)
- while true do
- a = parallel.waitForAny(receive,slowRead)
- setPos(1,sy-1)
- term.clearLine()
- end
Add Comment
Please, Sign In to add comment