incinirate

client

Jun 23rd, 2013 (edited)
641
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.58 KB | None | 0 0
  1. --[[Dex chat |client| script writted by Emma B aka anemonemma.
  2. feel free to edit as much as you want, just give me credit please.
  3. Thanks for using DexChat]]
  4.  
  5. modem="back"
  6. rednet.open(modem)
  7. serverid=0 --change to server computer's id / router id if using routers.
  8. currtext=""
  9. lastx,lasty = 0
  10. sx,sy = term.getSize()
  11. lastlines={}
  12. linenum=sy-1
  13.  
  14. function emptyTable(table)
  15.   for i=1,#table do
  16.     table[i]= nil
  17.   end
  18. end
  19.  
  20. emptyTable(lastlines)
  21.  
  22. function clear() shell.run("clear") end
  23.  
  24. function setPos(x,y) term.setCursorPos(x,y) end
  25.  
  26. function rewrite()
  27.   for i=1,linenum do
  28.     setPos(1,-1+i)
  29.     term.clearLine()
  30.     if lastlines[i]~=nil then
  31.       write(lastlines[i])
  32.     end
  33.   end
  34. end
  35.  
  36. function backspace()
  37.   local tempchars={}
  38.   local finalchars={}
  39.   for i=1,#currtext do
  40.     a=currtext:sub(i, i)
  41.     table.insert(tempchars, a)
  42.   end
  43.   for i=1,#tempchars-1 do
  44.     table.insert(finalchars,tempchars[i])
  45.   end
  46.   currtext=""
  47.   for i=1,#finalchars do
  48.     currtext=currtext..finalchars[i]
  49.   end
  50.   setPos(1,sy)
  51.   term.clearLine()
  52.   write(currtext)
  53. end
  54.  
  55. function lineOut(linetxt)
  56.   for i=1,linenum-1 do
  57.     lastlines[i]=lastlines[i+1]
  58.   end
  59.   lastlines[linenum]=linetxt
  60.   rewrite()
  61. end
  62.  
  63. function tryCommand(com)
  64.   print(com)
  65.   chrs={}
  66.   emptyTable(chrs)
  67.   for i=1,#com do tmpchr=string.sub(com, i, i) table.insert(chrs,tmpchr) end
  68.   if chrs[1] == "/" then
  69.     if com == "/list" then
  70.       rednet.send(serverid,"/list")
  71.     else if com == "/help" then
  72.       lineOut(" ")
  73.       lineOut("/help -Shows commands and their discriptions")
  74.       lineOut("/list -Lists conncted computers")
  75.       lineOut("/clear -Clears the screen")
  76.       lineOut(" ")
  77.     else if com == "/clear" then
  78.       for i=1,linenum do
  79.         lastlines[i]=nil
  80.       end
  81.       rewrite()
  82.     else
  83.       lineOut("Unknown Command. Try /help")
  84.     end
  85.     setPos(1,sy)
  86.     term.clearLine()
  87.     currtext=""
  88.     return true
  89.   end
  90.   end
  91.   end
  92.   return false
  93. end
  94.  
  95. slowRead = function()
  96.   local trashe,par2 = os.pullEvent()
  97.   if trashe == "key" then
  98.     if par2 == 28 then
  99.     if tryCommand(currtext) == false then
  100.       rednet.send(serverid,u..":"..currtext)
  101.       setPos(#currtext,sy)
  102.       currtext=""
  103.       term.clearLine()
  104.     end
  105.   end
  106.   if par2 == 14 then
  107.     backspace()
  108.   end
  109.   if par2 == 211 then
  110.     rednet.send(serverid,os.getComputerID()..":disconnect")
  111.     os.reboot()
  112.   end
  113.   end
  114.   if trashe == "char" then
  115.   currtext=currtext..par2
  116.   setPos(#currtext,sy)
  117.   term.clearLine()
  118.   setPos(1,sy)
  119.   write(currtext)
  120.   end
  121. end
  122.  
  123. receive = function()
  124.   id,message=rednet.receive()
  125.   for i=1,linenum-1 do
  126.     lastlines[i]=lastlines[i+1]
  127.   end
  128.   lastlines[linenum]=message
  129.   rewrite()
  130. end
  131.  
  132.  
  133.  
  134. clear()
  135. lineOut("DexChat V4 Starting up.")
  136. lineOut("Enter Username: ")
  137. u=read()
  138. lastlines[linenum]="Enter Username: "..u
  139. rednet.send(serverid,u..":Connecting")
  140. lineOut("Connecting...")
  141. id,message=rednet.receive()
  142. repeat
  143.   lineOut("Trying to login...")
  144.   repeat
  145.     if id ~= serverid then
  146.       repeat
  147.       id,message=rednet.receive()
  148.       until id == serverid
  149.     end
  150.     if id == serverid then
  151.       if message == "You are banned from this server" then
  152.         lineOut("You are banned from this server")
  153.         error()
  154.       end
  155.       if message == "Denied" then
  156.         lineOut("You are being denied access to this server")
  157.         error()
  158.       end
  159.     end
  160.   until message==u.." has connected!"
  161. until id==serverid
  162. lineOut("You have connected to the server.")
  163. lineOut(" ")
  164. sleep(1.5)
  165. while true do
  166.   a = parallel.waitForAny(receive,slowRead)
  167.   setPos(1,sy-1)
  168.   term.clearLine()
  169. end
Add Comment
Please, Sign In to add comment