Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- pastebin get JtgbWdV5 enchat
- std pb JtgbWdV5 enchat
- std ld enchat enchat
- 'Encmail' version 0.1 by EldidiStroyrr (CC Forums: LDDestroier)
- Encrypted, decentralized, colorized EMAIL program for ComputerCraft 1.6 or later.
- Encrypts messages/usernames with a password and os.time()
- Color your text with &[color code] and ~[color code].
- Disable text formatting with &{, and re-enable it with &}.
- Use &k to obfuscate, and ~k to stop obfuscation. Hehe.
- This program is based on Enchat, and is incomplete.
- Forum link for Enchat:
- http://www.computercraft.info/forums2/index.php?/topic/25290-enchat-encrypted-decentralized-chat/
- This is a beta release. You fool!
- Working on:
- +making an interface like a standard email program
- +making an address book
- +getting a solid folder hierarchy
- +removing all unneccesary fucking garbage text goddamn it
- --]]
- local log,_log,chatlog
- local em_path = ".encmail"
- local logpath = fs.combine(em_path,"logs")
- local configpath = fs.combine(em_path,"config")
- local displayMode = "mainmenu"
- local timedivisor = 2 --Must be same as other enchat clients. Can be used to limit scrambling due to using os.time
- local tArg = {...}
- local encKey, yourName = tArg[1], tArg[2]
- log = {} --Log formatted for view
- _log = {} --Log with all information
- chatlog = {} --Log with all pre-formatted information
- local commandTable --Contains all commands
- local scr_x, scr_y = term.getSize()
- local channel = 0 --Do not modify, it's changed anyway
- local checksum, modems, scroll, doScroll
- local endMode = 0 --0 is exit, 1 is restart
- local cfile --Current file. Defined later.
- local hasKrazy = false
- local enchatSettings = {
- fancyMsg = true, --Whether or not to colorize as you type
- doColorize = true, --Whether or not to use color formatting at all
- reverseScroll = false, --Reverses scrolling direction. But why would you want to do that?
- }
- local palate = {
- bg = colors.gray, --Default chat background color
- txt = colors.white, --Default chat text color
- chatbg = colors.white, --Chat prompt background color
- chattxt = colors.black, --Chat prompt text color
- }
- local colors_names = { --this has been modified to use the Paint colors rather than minecraft formatting
- ["0"] = colors.white,
- ["1"] = colors.orange,
- ["2"] = colors.magenta,
- ["3"] = colors.lightBlue,
- ["4"] = colors.yellow,
- ["5"] = colors.lime,
- ["6"] = colors.pink,
- ["7"] = colors.gray,
- ["8"] = colors.lightGray,
- ["9"] = colors.cyan,
- ["a"] = colors.purple,
- ["b"] = colors.blue,
- ["c"] = colors.brown,
- ["d"] = colors.green,
- ["e"] = colors.red,
- ["f"] = colors.black,
- }
- --going to add compatibility for ComputerCaft 1.63
- local _currentcolors = {
- txt = colors.white,
- bg = colors.black,
- }
- local termsetTextColor,termsetBackgroundColor = term.setTextColor,term.setBackgroundColor
- local termsetCursorPos,termclear,termclearLine,termwrite,termgetSize,termsetCursorBlink,termisColor = term.setCursorPos,term.clear,term.clearLine,term.write,term.getSize,term.setCursorBlink,term.isColor
- local tableinsert,tableconcat,tableunpack = table.insert,table.concat,table.unpack
- local termblit,termgetTextColor,termgetBackgroundColor,termgetCursorPos
- local parallelwaitForAny = parallel.waitForAny
- local termsetVisible
- if term.current then
- termcurrent = term.current
- end
- local oldsettext = term.setTextColor
- local oldsetbg = term.setBackgroundColor
- if not term.blit then
- termsetTextColor = function(col)
- oldsettext(col)
- _currentcolors.txt = col
- end
- termsetBackgroundColor = function(col)
- oldsetbg(col)
- _currentcolors.bg = col
- end
- termgetTextColor = function()
- return _currentcolors.txt
- end
- termgetBackgroundColor = function()
- return _currentcolors.bg
- end
- termblit = function(txt,tx,bg)
- local pt,pb = _currentcolors.bg,_currentcolors.txt
- if type(txt) ~= "string" or type(tx) ~= "string" or type(bg) ~= "string" then
- error("expected 3 strings, got "..tableconcat({type(txt),type(tx),type(bg)},", "))
- end
- if not ((#txt == #tx) and #tx == #bg) then
- error("all three arguments must be of same length")
- end
- for p = 1, #txt do
- oldsettext(colors_names[tx:sub(p,p)])
- oldsetbg(colors_names[bg:sub(p,p)])
- termwrite(txt:sub(p,p))
- end
- oldsettext(pt)
- oldsettext(pb)
- end
- else
- termblit = term.blit
- termgetTextColor = term.getTextColor
- termgetBackgroundColor = term.getBackgroundColor
- termgetCursorPos = term.getCursorPos
- end
- local tableConcat = function(tbl,between)
- local output = ""
- for k,v in pairs(tbl) do
- output = output..k..between
- end
- return output:sub(1,-2)
- end
- --Loading AES encryption functions. AES API ported to CC by SquidDev. Thanks heaps!
- local apipath
- if shell then apipath = fs.combine(shell.dir(),"aes") else apipath = "" end
- if (not aes) and (not fs.exists(apipath)) then
- print("AES API not found! Downloading...")
- local prog = http.get("http://pastebin.com/raw/9E5UHiqv")
- if not prog then error("FAIL!") end
- local file = fs.open(apipath,"w")
- file.write(prog.readAll())
- file.close()
- end
- if not aes then
- local res = os.loadAPI(apipath)
- if not res then error("Didn't load AES API!") end
- end
- --In case I use an API that uses a different syntax than (msg, key)
- local encrite = function(msg, key)
- return aes.encrypt(key, msg)
- end
- local decrite = function(msg, key)
- return aes.decrypt(key, msg)
- end
- local encode = function(txt) --converts string into a table of each character's byte code
- if type(txt) ~= "string" then return false, "requires string" end
- return {txt:byte(1,-1)}
- end
- local decode = function(tbl) --converts an encoded string into something useful.
- if type(tbl) ~= "table" then return false, "requires table" end
- return string.char(tableunpack(tbl))
- end
- local strcapsule = function(txt)
- return "\""..tostring(txt).."\""
- end
- local cwrite = function(txt,setY,doClearLine)
- local scr_x, scr_y = termgetSize()
- local x,y = termgetCursorPos()
- termsetCursorPos((scr_x/2)-(#txt/2),setY or y)
- if doClearLine then termclearLine() end
- write(txt)
- end
- local waitForModem = function()
- local mod
- while true do
- sleep(0.2)
- mod = peripheral.find("modem")
- if mod then
- return mod
- end
- end
- end
- if not peripheral.find("modem") then
- termsetBackgroundColor(colors.gray)
- termsetTextColor(colors.white)
- termclear()
- cwrite("Enchat requires a modem.",3)
- cwrite("Add one, or press a key.",4)
- sleep(0.1)
- local outcome = parallelwaitForAny(function() os.pullEvent("key") end, waitForModem)
- modems = {peripheral.find("modem")}
- if #modems == 0 then
- termsetBackgroundColor(colors.black)
- termsetCursorPos(1,scr_y)
- termclearLine()
- sleep(0)
- return false
- end
- end
- local modemOpen = function(chan)
- for a = 1, #modems do
- modems[a].open(chan)
- end
- end
- local modemClose = function(chan)
- for a = 1, #modems do
- modems[a].close(chan)
- end
- end
- local modemTransmit = function(chan,repchan,msg)
- for a = 1, #modems do
- modems[a].transmit(chan,repchan,msg)
- end
- end
- local tsv = function(visible)
- if termcurrent then
- if termcurrent().setVisible then
- termcurrent().setVisible(visible)
- return true
- else
- return false
- end
- else
- return false
- end
- end
- local logadd = function(name,msg,newline,stopFormatting)
- chatlog[#chatlog+1] = {name,msg,newline,stopFormatting or false}
- end
- local deepCopy = function(tbl)
- local output = {}
- for k,v in pairs(tbl) do
- output[k] = v
- end
- return output
- end
- local explode = function(div,str)
- if (div=='') then return false end
- local pos,arr = 0,{}
- for st,sp in function() return string.find(str,div,pos,false) end do
- tableinsert(arr,string.sub(str,pos,st-1))
- pos = sp + 1
- end
- tableinsert(arr,string.sub(str,pos))
- return arr
- end
- local colors_strnames = { --primarily for use when coloring palate
- ["white"] = colors.white,
- ["orange"] = colors.orange,
- ["magenta"] = colors.magenta,
- ["lightpurple"] = colors.magenta,
- ["light purple"] = colors.magenta,
- ["lightblue"] = colors.lightBlue,
- ["light blue"] = colors.lightBlue,
- ["yellow"] = colors.yellow,
- ["piss"] = colors.yellow,
- ["lemon"] = colors.yellow,
- ["lime"] = colors.lime,
- ["lightgreen"] = colors.lime,
- ["light green"] = colors.lime,
- ["pink"] = colors.pink,
- ["lightish red"] = colors.pink,
- ["gray"] = colors.gray,
- ["grey"] = colors.gray,
- ["lightgray"] = colors.lightGray,
- ["lightgrey"] = colors.lightGray,
- ["light gray"] = colors.lightGray,
- ["light grey"] = colors.lightGray,
- ["cyan"] = colors.cyan,
- ["seawater"] = colors.cyan,
- ["purple"] = colors.purple,
- ["purble"] = colors.purple,
- ["blue"] = colors.blue,
- ["blu"] = colors.blue,
- ["brown"] = colors.brown,
- ["shit"] = colors.brown,
- ["green"] = colors.green,
- ["grass"] = colors.green,
- ["red"] = colors.red,
- ["blood"] = colors.red,
- ["black"] = colors.black,
- }
- for k,v in pairs(colors_names) do
- colors_strnames[k] = v
- end
- local function alterXY()
- local cx,cy = termgetCursorPos()
- if cx == scr_x then
- termsetCursorPos(1,cy+1)
- end
- end
- local blit_names = {}
- for k,v in pairs(colors_names) do
- blit_names[v] = k
- end
- local safeColor = function(col) --I could've done much better, but whatever
- if type(col) ~= "number" then
- return false
- else
- if col > 2^15 then
- return false
- else
- if not termisColor() then
- if (col ~= colors.white) and (col ~= colors.lightGray) and (col ~= colors.gray) and (col ~= colors.black) then
- return false
- end
- end
- end
- end
- return true
- end
- local blitWrap = function(text,txt,bg,noWrite)
- local wordNo = 1
- local words = explode(" ",text)
- local lines = 0
- local scr_x, scr_y = termgetSize()
- local cx,cy
- local startX,startY = termgetCursorPos()
- for a = 1, #text do
- cx,cy = termgetCursorPos()
- if text:sub(a,a) == " " and text:sub(a-1,a-1) ~= " " and a > 1 then
- wordNo = wordNo + 1
- if cx + #words[wordNo] > scr_x then
- termsetCursorPos(1,cy+1)
- lines = lines + 1
- end
- end
- cx,cy = termgetCursorPos()
- if text:sub(a,a) == "\n" then
- termsetCursorPos(1,cy+1)
- lines = lines + 1
- elseif not (cx == 1 and text:sub(a,a) == " ") then
- if noWrite == true then
- termsetCursorPos(cx+1,cy)
- else
- if safeColor(colors_names[txt:sub(a,a)]) then
- termblit(text:sub(a,a),txt:sub(a,a),bg:sub(a,a))
- else
- termwrite(text:sub(a,a))
- end
- end
- end
- if cx == scr_x then
- termsetCursorPos(1,cy+1)
- lines = lines + 1
- end
- end
- if noWrite == true then
- termsetCursorPos(startX,startY)
- end
- return lines
- end
- local tablefind = function(tbl,str)
- for a = 1, #tbl do
- if tbl[a] == str then
- return a
- end
- end
- end
- local codeNames = {
- ["r"] = "reset", -- Sets either the text (&) or background (~) colors to their original color.
- ["{"] = "stopFormatting", --Toggles formatting text off
- ["}"] = "startFormatting", --Toggles formatting text on
- ["k"] = "krazy" --Makes the font krazy!
- }
- local kraziez = {
- ["l"] = {
- "!",
- "l",
- "1",
- "|",
- "i",
- "I",
- ":",
- ";",
- },
- ["m"] = {
- "M",
- "W",
- "w",
- "m",
- "X",
- "N",
- "_",
- "%",
- "@",
- },
- ["all"] = {}
- }
- for a = 1, #kraziez["l"] do
- kraziez[kraziez["l"][a]] = kraziez["l"]
- end
- for k,v in pairs(kraziez) do
- for a = 1, #v do
- kraziez[kraziez[k][a]] = v
- end
- end
- if _VERSION then
- for a = 1, 255 do
- if (a ~= 32) and (a ~= 13) and (a ~= 10) then
- kraziez["all"][#kraziez["all"]+1] = string.char(a)
- end
- end
- else
- for a = 33, 126 do
- kraziez["all"][#kraziez["all"]+1] = string.char(a)
- end
- end
- local textToBlit = function(str) --returns output for term.blit, or blitWrap, with formatting codes for color selection. Modified for use specifically with Enchat.
- local p = 1
- local output = ""
- local txcolorout = ""
- local bgcolorout = ""
- local txcode = "&"
- local bgcode = "~"
- local isKrazy = false
- local doFormatting = true
- local usedformats = {}
- local txcol,bgcol = blit_names[termgetTextColor()], blit_names[termgetBackgroundColor()]
- local origTX,origBG = blit_names[termgetTextColor()], blit_names[termgetBackgroundColor()]
- local cx,cy
- local moveOn = function(tx,bg)
- if isKrazy and (str:sub(p,p) ~= " ") and doFormatting then
- if kraziez[str:sub(p,p)] then
- output = output..kraziez[str:sub(p,p)][math.random(1,#kraziez[str:sub(p,p)])]
- else
- output = output..kraziez.all[math.random(1,#kraziez.all)]
- end
- else
- output = output..str:sub(p,p)
- end
- txcolorout = txcolorout..(doFormatting and tx or origTX)
- bgcolorout = bgcolorout..(doFormatting and bg or origBG)
- end
- while p <= #str do
- if str:sub(p,p) == txcode then
- if colors_names[str:sub(p+1,p+1)] and doFormatting then
- txcol = str:sub(p+1,p+1)
- usedformats.txcol = true
- p = p + 1
- elseif codeNames[str:sub(p+1,p+1)] then
- if str:sub(p+1,p+1) == "r" and doFormatting then
- txcol = blit_names[termgetTextColor()]
- isKrazy = false
- p = p + 1
- elseif str:sub(p+1,p+1) == "{" and doFormatting then
- doFormatting = false
- p = p + 1
- elseif str:sub(p+1,p+1) == "}" and (not doFormatting) then
- doFormatting = true
- p = p + 1
- elseif str:sub(p+1,p+1) == "k" and doFormatting then
- isKrazy = true
- usedformats.krazy = true
- p = p + 1
- else
- moveOn(txcol,bgcol)
- end
- else
- moveOn(txcol,bgcol)
- end
- p = p + 1
- elseif str:sub(p,p) == bgcode then
- if colors_names[str:sub(p+1,p+1)] and doFormatting then
- bgcol = str:sub(p+1,p+1)
- usedformats.bgcol = true
- p = p + 1
- elseif codeNames[str:sub(p+1,p+1)] and (str:sub(p+1,p+1) == "r") and doFormatting then
- bgcol = blit_names[termgetBackgroundColor()]
- p = p + 1
- elseif str:sub(p+1,p+1) == "k" and doFormatting then
- isKrazy = false
- p = p + 1
- else
- moveOn(txcol,bgcol)
- end
- p = p + 1
- else
- moveOn(txcol,bgcol)
- p = p + 1
- end
- end
- return output, txcolorout, bgcolorout, usedformats
- end
- local funcread = function(repchar,rHistory,doFunc,noNewLine,writeFunc,cursorAdjFunc,doFuncEvent)
- local scr_x,scr_y = termgetSize()
- local sx,sy = termgetCursorPos()
- local cursor = 1
- local rCursor = #rHistory+1
- local output = ""
- termsetCursorBlink(true)
- local rite = writeFunc or termwrite
- while true do
- local evt,key = os.pullEvent()
- if evt == doFuncEvent then
- pleaseDoFunc = true
- elseif evt == "key" then
- if key == keys.enter then
- if not noNewLine then
- write("\n")
- end
- termsetCursorBlink(false)
- return output
- elseif key == keys.left then
- if cursor-1 >= 1 then
- cursor = cursor - 1
- end
- elseif key == keys.right then
- if cursor <= #output then
- cursor = cursor + 1
- end
- elseif key == keys.up then
- if rCursor > 1 then
- rCursor = rCursor - 1
- termsetCursorPos(sx,sy)
- rite((" "):rep(#output))
- output = rHistory[rCursor] or ""
- cursor = #output+1
- pleaseDoFunc = true
- end
- elseif key == keys.down then
- termsetCursorPos(sx,sy)
- rite((" "):rep(#output))
- if rCursor < #rHistory then
- rCursor = rCursor + 1
- output = rHistory[rCursor] or ""
- cursor = #output+1
- pleaseDoFunc = true
- else
- rCursor = #rHistory+1
- output = ""
- cursor = 1
- end
- elseif key == keys.backspace then
- if cursor > 1 and #output > 0 then
- output = output:sub(1,cursor-2)..output:sub(cursor)
- cursor = cursor - 1
- pleaseDoFunc = true
- end
- elseif key == keys.delete then
- if #output:sub(cursor,cursor) == 1 then
- output = output:sub(1,cursor-1)..output:sub(cursor+1)
- pleaseDoFunc = true
- end
- end
- elseif evt == "char" or evt == "paste" then
- output = output:sub(1,cursor-1)..key..output:sub(cursor+(#key-1))
- cursor = cursor + #key
- pleaseDoFunc = true
- end
- local pOut = (output or ""):sub(math.max( 1,(#textToBlit(output)+sx)-scr_x) )
- if pleaseDoFunc then
- pleaseDoFunc = false
- if type(doFunc) == "function" then
- doFunc(output)
- end
- termsetCursorPos(sx,sy)
- if repchar then
- rite(repchar:sub(1,1):rep(#pOut))
- else
- rite(pOut)
- end
- termwrite(" ")
- end
- termsetCursorPos(sx+cursorAdjFunc(pOut)+cursor-math.max( 1,(#textToBlit(output)+sx)-scr_x),sy)
- end
- end
- local generateEncy = function()
- modems = {peripheral.find("modem")}
- modemClose(channel)
- channel = 0
- for a = 1, #encKey do
- channel = channel + string.byte(string.sub(encKey,a,a))
- end
- if channel >= 65535 then
- error("Bad key! Use a smaller one.")
- end
- modemOpen(channel)
- checksum = "ENCMAIL" --Used to eliminate gibberish messages securely, based on the key.
- for a = 1, #encKey do
- checksum = checksum..string.byte(string.sub(encKey,a,a))
- end
- checksum = encrite(checksum,encKey)
- end
- if yourName then
- if textToBlit(yourName) == "con" or textToBlit(yourName) == "*" then return printError("Not that name!") end
- end
- local cf = function(txt) --contextual filter
- if enchatSettings.doColorize then
- return txt
- else
- return textToBlit(txt)
- end
- end
- local writef = function(txt,noWrite)
- if enchatSettings.doColorize then
- local text, textCol, bgCol, usedformats = textToBlit(txt)
- local out = blitWrap(text,textCol,bgCol,noWrite)
- return out, #text, usedformats
- else
- return write(txt), #txt, {}
- end
- end
- local _ftlen = function(text)
- return #textToBlit(text)-#text
- end
- local clearLines = function(top, bottom)
- for a = top, bottom do
- termsetCursorPos(1,a)
- termclearLine()
- end
- end
- scroll = 1
- doScroll = true
- local urkrazy,_ = false
- local redrawScreen = function() --renders the chat and other things that change when scrolling.
- tsv(false)
- local prevX, prevY = termgetCursorPos()
- local _logold = _log
- _log,log = {},{}
- for a = 1, #chatlog do
- if not chatlog[a][3] then
- _log[#_log+1] = {"",false}
- end
- if chatlog[a][4] == true then
- _log[#_log+1] = {"<"..chatlog[a][1].."> "..chatlog[a][2],false}
- else
- _log[#_log+1] = {cf("<"..chatlog[a][1].."&r~r> "..chatlog[a][2]),true}
- end
- end
- if not doScroll then
- scroll = scroll + (#_log - #_logold)
- end
- for a = 1, #_log-(scroll-1) do
- log[#log+1] = _log[a]
- end
- termsetCursorPos(1,1)
- termsetBackgroundColor(palate.bg)
- termsetTextColor(palate.txt)
- termwrite(string.rep(" ",scr_x*(scr_y-2)))
- local midPoint = {
- scr_x / 2,
- scr_y / 2,
- }
- local yoffset = 0
- clearLines(1,scr_y-2)
- termsetCursorPos(1,scr_y)
- termclearLine()
- local indent = 1 --in case any line is greater than the length of the screen
- local indentIn = 0 --in the same case, mid writing
- for a = 1, #log do
- if log[a][2] then
- indent = indent + writef(log[a][1],true)
- else
- indent = indent + math.floor(#log[a][1]/scr_x)
- end
- end
- hasKrazy = false
- for a = 1, #log do
- termsetCursorPos(1,((((scr_y-1)+a-#log))-indent)+indentIn)
- if log[a][2] then
- indentIn = indentIn + writef(log[a][1],true)
- _,_,urkrazy = writef(log[a][1],false)
- hasKrazy = hasKrazy or (urkrazy.krazy or false)
- else
- indentIn = indentIn + math.floor((#log[a][1])/scr_x)
- termwrite(log[a][1])
- end
- end
- termsetCursorPos(scr_x,scr_y)
- if doScroll then writef("&8.") else termwrite(" ") end
- termsetCursorPos(prevX,prevY)
- tsv(true)
- end
- local _getTears = function() --to be ran with the /cry command. You freakin' mimsy.
- if (#modems > 0) then modemTransmit(channel, channel, {cry = true, cs = encode(checksum)}) end --ping!
- while true do
- local evt = {os.pullEvent("modem_message")}
- if type(evt[5]) == "table" then
- if type(evt[5].tears) == "table" then evt[5].tears = decode(evt[5].tears) end
- if type(evt[5].tears) == "string" and decrite(decode(evt[5].cs),encKey) == decrite(checksum,encKey) then
- local tear = decrite(evt[5].tears,encKey)
- playerList[tear] = true
- end
- end
- end
- end
- local handleCommand = function(commie)
- commie = commie or {}
- local command = commie[1] or ""
- local argument = commie
- if #commie > 0 then
- table.remove(argument,1)
- argument = tableconcat(argument," ") or ""
- else
- argument = ""
- end
- local commandTable
- commandTable = {
- ["exit"] = function() --why would you want to leave??
- endMode = 0
- return "exit"
- end,
- ["key"] = function()
- if #argument > 0 then
- if argument == encKey then return end
- os.queueEvent("enchat_send", "con", yourName.."&r~r has left.",encKey)
- sleep(0)
- encKey = argument
- generateEncy()
- os.queueEvent("enchat_send", "con", yourName.."&r~r moseyed on over.",encKey)
- logadd("*","Key changed. (channel: "..channel.."&r)",true)
- else
- generateEncy() --in case you break and reattach a modem, this should fix it right up
- logadd("*","Modem Channel: "..channel,false,true)
- logadd("*","Key: "..strcapsule(encKey),true,true)
- end
- redrawScreen()
- end,
- ["heil"] = function() --please don't tell me that you're offended, or I'll get offended
- local heilTable = {
- "Cobra",
- "this",
- "LDD",
- "unto me",
- "dan200",
- "myself",
- "!",
- "oeed",
- "Exerro",
- "Kepler",
- "Danny",
- "Bagel",
- "Roger",
- "King Porky",
- }
- local hailer
- if argument ~= "" then hailer = argument else hailer = heilTable[math.random(1,#heilTable)] end
- local mess = "Heil "..hailer.."!"
- os.queueEvent("enchat_send", yourName, mess)
- logadd("con","You heiled "..hailer.."!",false)
- redrawScreen()
- end,
- ["help"] = function() --I would call it "man", but there's only so much you can write about a two-argument function
- local a = false
- for k,v in pairs(commandTable) do
- strtime = tostring(math.floor(os.time()/timedivisor))
- logadd("*","&0/&4"..k,a)
- a = true
- end
- redrawScreen()
- end,
- ["clear"] = function() --*accidentally clears inventory* FUCK
- _log = {}
- log = {}
- chatlog = {}
- redrawScreen()
- end,
- ["cry"] = function() --your annoying tears streaming from your stupid fat face attracts a list of other people
- playerList = {}
- logadd("con","You cried loudly!",true)
- redrawScreen()
- parallelwaitForAny(_getTears, function() sleep(0.5) return end)
- _list = {}
- for k,v in pairs(playerList) do
- tableinsert(_list,k)
- end
- if #_list > 0 then
- logadd("con",tableconcat(_list,"&r~r, ").."&r~r responded!",true)
- else
- logadd("con","&eBut nobody came.",true)
- end
- redrawScreen()
- end,
- ["me"] = function() -- * EldidiStroyrr is dashingly handsome
- os.queueEvent("enchat_send", "*", "~r"..yourName.."~r&2 "..argument)
- logadd("*","~r"..yourName.."~r&2 "..argument,false)
- redrawScreen()
- end,
- ["colors"] = function()
- logadd("*","~0&f0~1&01~22~33~44~55~66~77~88~99~aa~bb~cc~dd~ee~ff",false)
- logadd("*","'&' for text, '~' for background.",false)
- redrawScreen()
- end,
- ["ping"] = function() --what do you mean this command is useless
- logadd("*",(argument ~= "") and argument or "Pong!",false)
- redrawScreen()
- end,
- ["update"] = function()
- local url
- if argument:gsub("%s","") == "beta" then
- url = "https://pastebin.com/raw/4a6NZaMZ"
- else
- url = "https://pastebin.com/raw/JtgbWdV5"
- end
- if shell then
- cfile = shell.getRunningProgram()
- else
- --termsetBackgroundColor(palate.bg)
- --termsetTextColor((palate.txt ~= colors.yellow) and colors.yellow or colors.black)
- --cwrite("Download where?",scr_y,true)
- logadd("con","&4Download where?",true)
- scroll = 1
- redrawScreen()
- termsetCursorPos(1,scr_y-1)
- termsetBackgroundColor(colors.lightGray)
- termsetTextColor(palate.chattxt)
- termclearLine()
- write(":")
- termsetBackgroundColor(palate.chatbg)
- cfile = read()
- end
- if fs.isReadOnly(cfile) then
- logadd("*","Unable to update to &4read-only directory.&r",true)
- redrawScreen()
- return
- end
- if not http then
- logadd("*","&4HTTP is disabled.&r Ask an admin to enable it.",true)
- redrawScreen()
- return
- else
- if not http.checkURL(url) then
- logadd("*","&4It appears the download URL is whitelisted.&r &cPlease slap your admin in their stupid face.",true)
- redrawScreen()
- return
- end
- end
- --termsetBackgroundColor(palate.bg)
- --termsetTextColor((palate.txt ~= colors.yellow) and colors.yellow or colors.black)
- --cwrite("Downloading...",scr_y,true)
- logadd("con","&4Downloading...",true)
- scroll = 1
- redrawScreen()
- local data = http.get(url)
- if not data then
- logadd("*","&4Couldn't connect to Pastebin.&r Sorry.",true)
- redrawScreen()
- return
- else
- local file = fs.open(cfile,"w")
- file.write(data.readAll())
- file.close()
- --cwrite("Yay! Relaunching.",scr_y,true)
- logadd("con","&4Yay! Relaunching.",true)
- scroll = 1
- redrawScreen()
- sleep(1)
- os.queueEvent("enchat_send", "con", yourName.."&r~r redownloaded the program.")
- sleep(0)
- endMode = 1
- return "restart"
- end
- end,
- ["whoami"] = function()
- if argument:lower() == "now" then
- logadd("*","You are still \""..yourName.."&r~r\"!",true)
- else
- logadd("*","You are \""..yourName.."&r~r\"!",true)
- end
- redrawScreen()
- end,
- ["nick"] = function()
- if argument ~= "" then
- if argument ~= yourName then
- if #argument:gsub("%s","") > 0 then
- if #textToBlit(argument) < 20 then
- if textToBlit(argument) ~= "con" and textToBlit(argument) ~= "*" then
- os.queueEvent("enchat_send", "con", tostring(yourName.."&r~r is now known as "..strcapsule(argument.."&r~r")))
- logadd("*",yourName.."&r~r is now known as "..strcapsule(argument.."&r~r"),false)
- yourName = tostring(argument)
- else
- logadd("*","&4Not so fast!!",false)
- end
- else
- logadd("*","&4Maximum 20 non-formatting characters!",false)
- end
- else
- logadd("*","&4Choose a more substantial name.",false)
- end
- else
- logadd("*","&4That's already your name.",false)
- end
- else
- logadd("*","&4/nick <newname>",true)
- end
- redrawScreen()
- end,
- ["palate"] = function()
- if argument:gsub("%s","") == "" then
- logadd("*","&4/palate "..tableConcat(palate,"/").." <color code>",false)
- else
- argument = explode(" ",argument)
- if #argument == 1 then
- if argument[1]:gsub("%s",""):lower() == "reset" then
- palate = {
- bg = colors.gray,
- txt = colors.white,
- chatbg = colors.white,
- chattxt = colors.black,
- }
- logadd("*","&4You cleansed your palate.",false)
- else
- logadd("*","&4Give me a color code next time.",false)
- end
- else
- if #argument > 2 then
- argument = {argument[1], tableconcat(argument," ",2)}
- end
- argument[1] = argument[1]:lower()
- local newcol = argument[2]:lower()
- if not palate[argument[1]] then
- logadd("*","&4That's not a valid palate choice.")
- else
- if not colors_strnames[newcol] then
- logadd("*","&4That isn't a valid color code. (0-f)")
- else
- palate[argument[1]] = colors_strnames[newcol]
- logadd("*","You have such a sense of style.",false)
- end
- end
- end
- end
- redrawScreen()
- end,
- }
- if commandTable[command] then
- return commandTable[command]()
- else
- return false
- end
- end
- local doAndBack = function(func)
- local backColor = termgetBackgroundColor()
- local textColor = termgetTextColor()
- local curX, curY = termgetCursorPos()
- local results = {func()}
- termsetBackgroundColor(backColor)
- termsetTextColor(textColor)
- termsetCursorPos(curX,curY)
- return tableunpack(results)
- end
- local mainMenu = function()
- local options = {"Send","Inbox","Contacts","Back to terminal","Quit"}
- local cursor = 1
- local _rendermenu = function(c)
- for a = 1, #options do
- term.setCursorPos(2,(scr_y-#options)-1+a)
- if a == c then
- writef("&0> "..options[a])
- else
- writef("&7 "..options[a])
- end
- end
- end
- while true do
- _rendermenu(cursor)
- end
- end
- local renderAll = function()
- while true do
- local result = mainMenu()
- end
- end
- local receiveMessages = function()
- local encMessage
- local event, side, frequency, replyFrequency, message, distance
- while true do
- event, side, frequency, replyFrequency, message, distance = os.pullEvent()
- if event == "modem_message" then
- if distance ~= 0 then
- if type(message) == "table" then
- if message.cry and message.cs then --basically a ping thing
- message.cs = decrite(decode(message.cs),encKey)
- if type(message.cry) == "boolean" and message.cs == decrite(checksum,encKey) then
- modemTransmit(channel, channel, {tears = encode(encrite(yourName,encKey)), cs = encode(checksum)})
- end
- else
- if message.name and message.msg and message.cs then
- encMessage = deepCopy(message)
- message.cs = decrite(decode(message.cs),encKey)
- message.msg = decode(message.msg)
- message.name = decode(message.name)
- if type(message.name) == "string" and type(message.msg) == "string" and message.cs == decrite(checksum,encKey) then
- local strtime = tostring(math.floor(os.time()/timedivisor))
- local plainname, plainmsg = decrite(decrite(message.name,strtime),encKey), decrite(decrite(message.msg,strtime),encKey)
- logadd(plainname,plainmsg,false)
- os.queueEvent("enchat_receive",message.name,encMessage)
- doAndBack(redrawScreen)
- end
- end
- end
- end
- end
- --elseif event == "didScroll" then
- -- doAndBack(redrawScreen)
- elseif event == "peripheral" or event == "peripheral_detach" then --yaay
- if peripheral.getType(side) == "modem" then
- generateEncy()
- end
- end
- end
- end
- local sendMessages = function()
- while true do
- local event, name, message = os.pullEvent("enchat_send",key)
- local eName = encrite(encrite(tostring(name),key or encKey),tostring(math.floor(os.time()/timedivisor)))
- local eMessage = encrite(encrite(tostring(message),key or encKey),tostring(math.floor(os.time()/timedivisor)))
- local sendmsg = {
- name = encode(eName),
- msg = encode(eMessage),
- cs = encode(checksum),
- }
- modemTransmit(channel, channel, sendmsg)
- end
- end
- if termisColor() then
- colormode = true
- grayAllowed = true
- else
- colormode = false
- if _VERSION then
- grayAllowed = true
- else
- grayAllowed = false
- end
- end
- termsetBackgroundColor(colors.gray)
- termclear()
- termsetCursorPos(1,1)
- if not encKey or encKey == "" then
- local posX, posY = termgetCursorPos()
- repeat
- termsetBackgroundColor(colors.gray)
- termsetTextColor(colors.white)
- termsetCursorPos(posX,posY)
- termclearLine()
- cwrite("Enter encryption key:\n")
- termsetBackgroundColor(colors.lightGray)
- termsetTextColor(colors.black)
- termclearLine()
- write(">")
- encKey = read("*")
- until encKey ~= ""
- end
- if not yourName then
- write("\n")
- local posX, posY = termgetCursorPos()
- local prevX,prevY = 1,1
- local namePrompt = function()
- termsetCursorPos(prevX,prevY)
- termsetBackgroundColor(colors.lightGray)
- termsetTextColor(colors.black)
- termclearLine()
- write(">")
- end
- repeat
- termsetBackgroundColor(colors.gray)
- termsetTextColor(colors.white)
- termsetCursorPos(posX,posY)
- termclearLine()
- cwrite("Enter your name:\n",posY)
- prevX,prevY = termgetCursorPos()
- if enchatSettings.doColorize then
- termsetTextColor(colors.lightGray)
- cwrite("Color codes:",scr_y-3)
- cwrite("(&text,~backg.)",scr_y-2)
- termsetCursorPos((scr_x/2)-8,scr_y-1)
- termsetBackgroundColor(colors.gray)
- termclearLine()
- blitWrap(textToBlit("~0&f0~1&01~22~33~44~55~66~77~88~99~aa~bb~cc~dd~ee~ff"))
- termsetCursorPos(prevX,prevY)
- end
- termsetBackgroundColor(colors.lightGray)
- termsetTextColor(colors.black)
- termclearLine()
- write(">")
- yourName = enchatSettings.fancyMsg and funcread(nil,{},namePrompt,false,writef,_ftlen) or read()
- if textToBlit(yourName) == "con" or textToBlit(yourName) == "*" then
- termsetBackgroundColor(colors.gray)
- termsetTextColor(colors.white)
- print("\nBut not that name!")
- end
- until (#yourName >= 1) and (yourName ~= "con") and (yourName ~= "*")
- end
- termsetBackgroundColor(colors.gray)
- termsetTextColor(colors.white)
- generateEncy()
- local getScrolling = function()
- local oldScroll
- scroll = 1
- doScroll = true
- while true do
- local _,dir,x,y = os.pullEvent("mouse_scroll")
- oldScroll = scroll
- if dir == (enchatSettings.reverseScroll and 1 or -1) then
- if scroll < #_log-1 then
- scroll = scroll + 1
- doScroll = false
- end
- elseif dir == (enchatSettings.reverseScroll and -1 or 1) then
- if scroll > 1 then
- scroll = scroll - 1
- if scroll == 1 then
- doScroll = true
- end
- end
- end
- if oldScroll ~= scroll then
- os.queueEvent("didScroll",scroll)
- end
- end
- end
- local redrawForKrazy = function()
- while true do
- if hasKrazy then
- redrawScreen()
- os.queueEvent("redrawprompt")
- else
- sleep(0.2)
- end
- sleep(0.2)
- end
- end
- os.queueEvent("enchat_send", "con", yourName.."&r~r moseyed on over.")
- local funcList = {
- receiveMessages,
- sendMessages,
- renderAll,
- getScrolling,
- redrawForKrazy,
- }
- parallelwaitForAny(tableunpack(funcList))
- if endMode == 1 then
- if shell then
- shell.run(strcapsule(cfile),strcapsule(encKey),strcapsule(yourName))
- else
- loadfile(cfile)(encKey,yourName)
- end
- else
- if modem then modemClose(channel) end
- termsetCursorPos(1,scr_y)
- termsetBackgroundColor(colors.black)
- termclearLine()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement