Advertisement
LDDestroier

FakeChat (client)

Aug 1st, 2016
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- ...use responsibly.
  2. --
  3. -- Get with
  4. -- pastebin get ruyCGxps fakechat
  5. -- std ld fakechat
  6.  
  7. local prefix = "" --global prefix
  8. local suffix = "" --global suffix
  9.  
  10. local tArg = {...}
  11.  
  12. local channel = 1251
  13. local modem = peripheral.find("modem")
  14. if not modem then
  15.   error("Requires a modem.")
  16. end
  17. modem.open(channel)
  18.  
  19. term.setBackgroundColor(colors.black)
  20. term.clear()
  21.  
  22. if prevnames == nil then
  23.   prevnames = {}
  24. end
  25.  
  26. term.setCursorPos(1,1)
  27. local name
  28. if tArg[1] then
  29.     name = tArg[1]
  30.     if name:gsub(" ","") ~= "" and prevnames[#prevnames] ~= name then
  31.       table.insert(prevnames,name)
  32.     end
  33. else
  34.     print("Enter your name:")
  35.     write(">")
  36.     name = read(nil,prevnames)
  37.     if name:gsub(" ","") ~= "" and prevnames[#prevnames] ~= name then
  38.       table.insert(prevnames,name)
  39.     end
  40. end
  41.  
  42. local names = { --Add names to quickly switch between using UP and DOWN
  43.     {
  44.         name = name,
  45.         prefix = "<",
  46.         suffix = "> ",
  47.         realname = name
  48.     },
  49.     {
  50.         name = "&o&6Jesus",
  51.         prefix = "<",
  52.         suffix = "> ",
  53.     },
  54.     {
  55.         name = "&dServer",
  56.         prefix = "&d[",
  57.         suffix = "&d] ",
  58.         msgprefix = "&d",
  59.         realname = "But nobody"
  60.     },
  61.     {
  62.         name = "dan200",
  63.         prefix = "<",
  64.         suffix = "> ",
  65.     },
  66. }
  67.  
  68. local colors_names = { --for use with colors api, you see
  69.     ["0"] = colors.black,
  70.     ["1"] = colors.blue,
  71.     ["2"] = colors.green,
  72.     ["3"] = colors.cyan,
  73.     ["4"] = colors.red,
  74.     ["5"] = colors.purple,
  75.     ["6"] = colors.orange,
  76.     ["7"] = colors.lightGray,
  77.     ["8"] = colors.gray,
  78.     ["9"] = colors.blue, --they don't translate perfectly, okay??
  79.     ["a"] = colors.lime,
  80.     ["b"] = colors.lightBlue,
  81.     ["c"] = colors.red,
  82.     ["d"] = colors.magenta,
  83.     ["e"] = colors.yellow,
  84.     ["f"] = colors.white,
  85. }
  86. local codeNames = { --just for checking
  87.     ["k"] = "obfuscate",   
  88.     ["o"] = "italic",
  89.     ["l"] = "bold",
  90.     ["m"] = "strikethrough",
  91.     ["n"] = "underline",
  92.     ["r"] = "reset",
  93. }
  94.  
  95. filterColors = function(str,doprint)
  96.     local p = 1
  97.     local output = ""
  98.     local code = "&"
  99.     local col = "f"
  100.     while p <= #str do
  101.         if str:sub(p,p) == code then
  102.             if colors_names[str:sub(p+1,p+1)] then
  103.                 col = str:sub(p+1,p+1)
  104.                 p = p + 1
  105.             elseif codeNames[str:sub(p+1,p+1)] then
  106.                 if str:sub(p+1,p+1) == "r" then
  107.                     col = "f"
  108.                 end
  109.                 p = p + 1
  110.             else
  111.                 if doprint then
  112.                     term.setTextColor(colors_names[col])
  113.                     write(str:sub(p,p))
  114.                 end
  115.             end
  116.             p = p + 1
  117.         else
  118.             output = output..str:sub(p,p)
  119.             if doprint then
  120.                 term.setTextColor(colors_names[col])
  121.                 write(str:sub(p,p))
  122.             end
  123.             p = p + 1
  124.         end
  125.     end
  126.     return output
  127. end
  128.  
  129. local pos = 1
  130. local scr_x, scr_y = term.getSize()
  131.  
  132. local send = function(n,m,p,s,mp,rn) --name, message, prefix, suffix
  133.     local data = {
  134.         name = n,
  135.         realname = rn or n,
  136.         msg = mp..m,
  137.         prefix = p or "<",
  138.         suffix = s or "> ",
  139.     }
  140.     modem.transmit(channel,channel,data)
  141. end
  142.  
  143. local renderMenu = function()
  144.   local x,y = term.getCursorPos()
  145.   local bg = term.getBackgroundColor()
  146.   local txt = term.getTextColor()
  147.   term.setBackgroundColor(colors.black)
  148.   for a = 1, #names do
  149.     term.setCursorPos(1,a)
  150.     term.setTextColor(colors.white)
  151.     if pos == a then
  152.       write("*")
  153.     else
  154.       write(" ")
  155.     end
  156.     filterColors(prefix.."&r"..names[a].prefix.."&r"..names[a].name.."&r"..names[a].suffix.."&r"..suffix,true)
  157.   end
  158.   term.setCursorPos(x,y)
  159.   term.setBackgroundColor(bg)
  160.   term.setTextColor(txt)
  161. end
  162.  
  163. local msgHistory = {}
  164.  
  165. local function doRead()
  166.   while true do
  167.     term.setBackgroundColor(colors.black)
  168.     term.clear()
  169.     renderMenu()
  170.     term.setCursorPos(1,1)
  171.     term.setCursorPos(1,scr_y-1)
  172.     term.setBackgroundColor(colors.gray)
  173.     term.clearLine()
  174.     term.setTextColor(colors.white)
  175.     write(">")
  176.     local msg = read(nil,msgHistory)
  177.     if (msg:gsub(" ","") ~= "") and (msg ~= msgHistory[#msgHistory]) then
  178.         msgHistory[#msgHistory+1] = msg
  179.     end
  180.     if msg:gsub(" ","") == "/exit" then
  181.       return
  182.     end
  183.     if msg:gsub(" ","") ~= "" then
  184.       local sdata = {
  185.         names[pos].name,
  186.         msg,
  187.         prefix..names[pos].prefix or "<",
  188.         suffix..names[pos].suffix or "> ",
  189.         names[pos].msgprefix or "",
  190.       }
  191.       if type(names[pos].realname) == "string" then
  192.         table.insert(sdata,names[pos].realname)
  193.       end
  194.       send(unpack(sdata))
  195.     end
  196.   end
  197. end
  198.  
  199. local function changename()
  200.   while true do
  201.     local evt, key = os.pullEvent("key")
  202.     if key == keys.pageUp then
  203.       pos = pos - 1
  204.     end
  205.     if key == keys.pageDown then
  206.       pos = pos + 1
  207.     end
  208.     if pos <= 0 then
  209.       pos = #names
  210.     elseif pos > #names then
  211.       pos = 1
  212.     end
  213.     renderMenu()
  214.   end
  215. end
  216. parallel.waitForAny(changename,doRead)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement