Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- if args[1] == "update" or not fs.exists("apis/encryption.lua") then
- fs.delete("apis/encryption.lua")
- shell.run("pastebin get 0eYmhPMt apis/encryption.lua")
- end
- if args[1] == "update" or not fs.exists("apis/screen.lua") then
- fs.delete("apis/screen.lua")
- shell.run("pastebin get qudBZVpH apis/screen.lua")
- end
- if args[1] == "update" or not fs.exists("apis/docs.lua") then
- fs.delete("apis/docs.lua")
- shell.run("pastebin get 97XNLNEw apis/docs.lua")
- end
- if args[1] == "update" then
- shell.run(".SMSinstaller.lua")
- end
- if not fs.exists(".SMSinstaller.lua") then shell.run("pastebin get Y58ddpyY .SMSinstaller.lua") end
- if not encryption then os.loadAPI("apis/encryption.lua") end
- if not screen then os.loadAPI("apis/screen.lua") end
- --SMS PROTOCOLS
- --Unsecure SMS
- --#A: Initial message, Encrypted and scrambled by first computer and sent from first computer to second computer
- --#B: Return message, Encrypted by both computers and sent from second computer back to the first computer
- --#C: Double Return message, Encrypted by the both computers, then decrypted and unscrambled by first computer and sent from first computer to second computer
- --Errors
- --#E: Error message, retry to send message
- --#e: Error message, don't retry to send message
- --Secure SMS
- --#a: A, but the original message is "<original message><mutual key>"
- --#b: B, but the original message is "<original message><mutual key>"
- --#c: C, but the original message is "<original message><mutual key>"
- --Mutual Key
- --#K: First contact procedure, sends an encrypted mutual key (essentially A but the payload is mutual keys)
- --#L: Second step of first contact procedure, sends the double encrypted mutual key back (essentially B)
- --#M: Third step of first contact procedure (essentially C)
- --#N: Mutual Key Confirmation
- term.clear()
- --TODO: remove?
- local completion = require("cc.completion")
- --Startup screen
- local base_term = term.current()
- local maxX,maxY = term.getSize()
- local startup_screen = screen.Screen(1,1,term.getSize())
- local startup_msg,isFirstLogin = "Welcome back! Please login",false
- if not fs.exists("SMS/settings.encryptedtxt") then
- fs.delete("SMS")
- startup_msg,isFirstLogin = "Create your password. This cannot be changed later.",true
- end
- term.redirect(startup_screen.wndw)
- startup_screen.textBoxes = {
- screen.TextBox(1,1,"Schem Messaging System SMS",maxX,1,colors.white,colors.green),
- screen.TextBox(1,2,startup_msg,maxX,2,colors.white,colors.gray),
- screen.TextBox(1,6,string.rep(" ",maxX),maxX,1,colors.white,colors.gray),
- screen.TextBox(1,9,string.rep(" ",maxX),maxX,1,colors.white,colors.gray)
- }
- startup_screen.buttons = {
- pass = screen.FormField(2,4,"Enter Password:",maxX-2,2,colors.white,colors.lightGray,true,maxX-2),
- confirmpass = screen.FormField(2,7,"Confirm Password:",maxX-2,2,colors.white,colors.lightGray,true,maxX-2),
- enter = screen.Button(2,10,"Enter",5,1,colors.white,colors.red,nil,"Enter")
- }
- local password,confirmpass = "",""
- local btype,a,b,c
- while btype ~= "Enter" or #password <= 0 or password ~= confirmpass do
- local b = startup_screen:waitForClick()
- btype,a,b,c = b:click()
- if btype == "form" and b then
- if a == "Enter Password:" then password = b
- else
- confirmpass = b
- end
- end
- end
- term.clear()
- term.redirect(base_term)
- --Constants
- local receive_queue,send_queue,message_queue,mutual_queue,err_log,retry_queue,onlineComputers = {},{},{},{},{},{},{}
- local next_msgID = 1
- local current_screen
- --Random alphanumeric string of length len (or 1)
- local function randString(len)
- len = math.floor(tonumber(len) or 1)
- local res = ""
- math.randomseed(os.epoch())
- while #res < len do
- res = res .. (string.match(string.char(math.random(256)-1),"%a") or "")
- end
- return res
- end
- local session_id = randString(16)
- local settings = {}
- local function writeSettings(newSettings,dir)
- if type(newSettings) ~= "table" then return false end
- dir = dir or "/SMS/settings.encryptedtxt"
- local file = fs.open(dir,"w+")
- file.write(textutils.serialiseJSON(newSettings))
- file.close()
- encryption.encryptFile(dir,password)
- end
- local function readSettings(dir)
- dir = dir or "/SMS/settings.encryptedtxt"
- if fs.exists(dir) then
- local data,wasEncrypted = encryption.decryptFile(dir,password)
- local settings = textutils.unserialiseJSON(data)
- if type(settings) ~= "table" or not wasEncrypted then
- term.clear()
- error("Settings are not encrypted or password was invalid")
- --return false
- end
- return settings
- elseif dir == "/SMS/settings.encryptedtxt" then
- local defaultSettings = {
- allowUnsecureMsgs = false,
- allowSecureMsgs = true,
- establishMutuals = true,
- hashSize = 256^2
- }
- writeSettings(defaultSettings,dir)
- return defaultSettings
- else
- return {}
- end
- end
- settings = readSettings()
- mutual_keys = readSettings("/SMS/mutualkeys.encryptedtxt")
- local hostName
- if type(settings.hostName) ~= "string" then hostName = randString(16) end
- --Opening rednet
- local modem = peripheral.find("modem",function(name,modem) return modem.isWireless() end)
- if not modem then error("No modem attached") end
- rednet.open(peripheral.getName(modem))
- --Opening rednet host
- if settings.allowUnsecureMsgs then
- rednet.host("Unsecure-SMS",hostName)
- end
- if settings.allowSecureMsgs then
- rednet.host("Secure-SMS",hostName)
- end
- --Rednet lookup
- local function getComputerNames()
- if type(onlineComputer) ~= "table" or not onlineComputers.epoch or onlineComputers.epoch + 5000 > os.epoch() then
- local secure_computers = {rednet.lookup("Secure-SMS")}
- local unsecure_computers = {rednet.lookup("Unsecure-SMS")}
- onlineComputers = {epoch=os.epoch()}
- for k,v in pairs(secure_computers) do
- onlineComputers[v] = k
- end
- for k,v in pairs(unsecure_computers) do
- onlineComputers[v] = k
- end
- onlineComputers[os.getComputerID()] = nil
- end
- return onlineComputers
- end
- local log = fs.open("SMS/latest.log","w+")
- --Receive loop protocol
- local function receive()
- while true do
- local id,msg,prtcl = rednet.receive() --fck rednet
- if type(prtcl) ~= "string" then prtcl = "" end
- local msgID = tonumber(string.match(prtcl,"%d+")) or 0
- if type(send_queue[id]) ~= "table" then send_queue[id] = {} end
- if type(receive_queue[id]) ~= "table" then receive_queue[id] = {} end
- if type(msg) ~= "string" then msg = "" end
- log.writeLine(id .. " " .. msg .. " " .. prtcl)
- log.flush()
- --Unsecure protocols
- if settings.allowUnsecureMsgs and string.match(prtcl,"SMS#[ABC]") then
- if string.match(prtcl,"SMS#B") then
- if type(send_queue[id][msgID]) == "table" and #send_queue[id][msgID].payload == #msg then
- rednet.send(id,encryption.decryptString(msg,password .. session_id,settings.hashSize,true,true,send_queue[id][msgID].epoch),"SMS#C" .. msgID)
- send_queue[id][msgID] = nil
- else
- rednet.send(id,"418 I'm a teapot","SMS#e" .. msgID) --Message length not consistent or original message wasnt sent, another computer trying to get decryption?
- end
- elseif string.match(prtcl,"SMS#A") then --secure and unsecure A protocol are functionally the same
- local epoch = os.epoch()
- if type(receive_queue[id][msgID]) == "table" then --ID already used
- rednet.send(id,"409 ID already used in session","SMS#E"..msgID)
- else
- receive_queue[id][msgID] = {epoch=epoch,payload=msg}
- rednet.send(id,encryption.encryptString(msg,password .. session_id,settings.hashSize,true,false,epoch),"SMS#B"..msgID)
- end
- elseif string.match(prtcl,"SMS#C") then
- if type(receive_queue[id][msgID]) == "table" and #receive_queue[id][msgID].payload == #msg then
- local msg = encryption.decryptString(msg,password .. session_id,settings.hashSize,true,false,receive_queue[id][msgID].epoch)
- table.insert(message_queue,{msg=msg,id=id,msgID=msgID,prtcl=prtcl,conversation=id})
- next_msgID = next_msgID + 1
- else
- end
- end
- elseif string.match(prtcl,"SMS#[ABC]") then
- rednet.sent(id,"401 Unsecure messages not supported","SMS#E" .. msgID)
- --Secure a protocol
- elseif string.match(prtcl,"SMS#a") then --secure and unsecure A protocol are functionally the same
- local epoch = os.epoch()
- if type(receive_queue[id][msgID]) == "table" then --ID already used
- rednet.send(id,"409 ID already used in session","SMS#E"..msgID)
- else
- receive_queue[id][msgID] = {epoch=epoch,payload=msg}
- rednet.send(id,encryption.encryptString(msg,password .. session_id,settings.hashSize,true,false,epoch),"SMS#b"..msgID)
- end
- --Secure c protocol
- elseif string.match(prtcl,"SMS#c") then
- if type(receive_queue[id][msgID]) == "table" then
- local msg = encryption.decryptString(msg,password .. session_id,settings.hashSize,true,false,receive_queue[id][msgID].epoch)
- msg = encryption.decryptString(msg,mutual_keys["MutualKey"..id],256,true,true) --Unencrypt with mutual key
- table.insert(message_queue,{msg=msg,id=id,msgID=msgID,prtcl=prtcl,conversation=id})
- next_msgID = next_msgID + 1
- end
- --Secure b protocol
- elseif string.match(prtcl,"SMS#b") then --Same protocol
- if type(send_queue[id]) == "table" then
- if type(send_queue[id][msgID]) == "table" and #send_queue[id][msgID].payload == #msg then
- rednet.send(id,encryption.decryptString(msg,password .. session_id,settings.hashSize,true,true,send_queue[id][msgID].epoch),"SMS#C" .. msgID)
- send_queue[id][msgID] = nil
- else
- rednet.send(id,"418 I'm a teapot","SMS#e" .. msgID) --Message length not consistent or original message wasnt sent, another computer trying to get decryption?
- end
- end
- --Error Handling
- elseif string.match(prtcl,"SMS#[Ee]") then
- table.insert(err_log,{id=id,msgID=msgID,err=msg,prtcl=prtcl})
- local originalMessage = receive_queue[id][msgID]
- if not originalMessage then originalMessage = send_queue[id][msgID] end
- if not originalMessage then originalMessage = mutual_queue[id] end
- if originalMessage and string.match(prtcl,"SMS#E") then
- --table.insert(retry_queue,originalMessage) --NYI
- end
- receive_queue[id][msgID] = nil
- send_queue[id][msgID] = nil
- mutual_queue[id] = nil
- --Mutual Key protocols
- elseif settings.establishMutuals and string.match(prtcl,"SMS#[KLMN]") then
- if string.match(prtcl,"SMS#K") then
- local epoch = os.epoch()
- if mutual_queue[id] or settings["MutualKey"..id] then --Mutual queue already waiting for response
- rednet.send(id,"400 Mutual key already established, or is being verified","SMS#E"..msgID)
- else
- rednet.send(id,encryption.encryptString(msg,password .. session_id,settings.hashSize,true,true,epoch),"SMS#L" .. msgID)
- mutual_queue[id] = {epoch=epoch,payload=msg}
- end
- elseif string.match(prtcl,"SMS#L") then
- if not mutual_queue[id] then
- rednet.send(id,"418 I'm a teapot","SMS#e"..msgID)
- else
- rednet.send(id,encryption.decryptString(msg,password .. session_id,settings.hashSize,true,true,mutual_queue[id].epoch),"SMS#M"..msgID)
- end
- elseif string.match(prtcl,"SMS#M") then
- if not mutual_queue[id] or #mutual_queue[id].payload ~= #msg or mutual_keys["MutualKey"..id] then
- rednet.send(id,"418 I'm a teapot","SMS#e"..msgID)
- else
- mutual_keys["MutualKey"..id] = encryption.decryptString(msg,password .. session_id,settings.hashSize,true,true,mutual_queue[id].epoch)
- writeSettings(mutual_keys,"SMS/mutualkeys.encryptedtxt")
- mutual_queue[id] = nil
- rednet.send(id,encryption.encryptString("200 Key Established",mutual_keys["MutualKey"..id],256^2,true,false),"SMS#N"..msgID)
- os.queueEvent("mutual_key",id,mutual_keys["MutualKey"..id])
- end
- elseif string.match(prtcl,"SMS#N") then
- if encryption.decryptString(msg,mutual_queue[id].payload,256^2,true,false) == "200 Key Established" then
- mutual_keys["MutualKey"..id] = mutual_queue[id].payload
- writeSettings(mutual_keys,"SMS/mutualkeys.encryptedtxt")
- mutual_queue[id] = nil
- os.queueEvent("mutual_key",id,mutual_keys["MutualKey"..id])
- else
- table.insert(err_log,{id=id,msgID=msgID,err="001 No mutual key return for mutual:"..mutual_queue[id].payload,prtcl=prtcl})
- mutual_queue[id] = nil
- end
- end
- elseif prtcl ~= "dns" then
- rednet.send(id,"405 Protocol invalid, or attempting to establish unsecure practices with a secure computer","SMS#E"..msgID)
- end
- end
- end
- local function readMessageHistory(id)
- local dir = "SMS/PrivateMessages/"..id .. ".encryptedtxt"
- local oldData
- if fs.exists(dir) then
- local data = encryption.decryptFile(dir,password)
- oldData = textutils.unserialiseJSON(data)
- end
- if type(oldData) ~= "table" then oldData = {msgs={}} end
- oldData.name = "" .. (oldData.name or id)
- oldData.name = oldData.name:sub(1,8)
- return oldData,dir
- end
- local function addMessageHistory(message,id,conversation)
- local oldData,dir = readMessageHistory(conversation)
- oldData.epoch = os.epoch()
- table.insert(oldData.msgs,{id,message})
- if current_screen.recipient == conversation then
- current_screen.subscreen.messageHistory = oldData
- os.queueEvent("refreshMessages",conversation)
- end
- local file = fs.open(dir,"w+")
- file.write(textutils.serialiseJSON(oldData))
- file.close()
- encryption.encryptFile(dir,password)
- end
- --TODO: implement group messaging protocols so this is actually relevant
- local function addGroupMessageHistory(message,id,groupChat)
- local dir = "SMS/GroupMessages/"..groupChat..".encryptedtxt"
- local oldData
- if fs.exists(dir) then
- local data = encryption.decryptFile(dir,password)
- oldData = textutils.unserialiseJSON(data)
- end
- if type(oldData) ~= "table" then oldData = {msgs={}} end
- table.insert(oldData.msgs,{id,message})
- oldData.epoch = os.epoch()
- oldData.name = groupChat
- local file = fs.open(dir,"w+")
- file.write(textutils.serialiseJSON(oldData))
- file.close()
- encryption.encryptFile(dir,password)
- end
- --Returns isUnsecure,isSecure,isSecureAndKey
- local function canReceive(id)
- local secure_computers = {rednet.lookup("Secure-SMS")}
- local unsecure_computers = {rednet.lookup("Unsecure-SMS")}
- local isUnsecure,isSecure,isSecureAndKey = false,false,false
- if settings.allowSecureMsgs then
- for k,v in pairs(secure_computers) do
- if v == id then
- isSecure = true
- if settings["MutualKey"..id] then isSecureAndKey = true end
- break
- end
- end
- end
- if settings.allowUnsecureMsgs then
- for k,v in pairs(unsecure_computers) do
- if v == id then
- isUnsecure = true
- break
- end
- end
- end
- return isUnsecure,isSecure,isSecureAndKey
- end
- --Sends message to recipient with id
- local function send(recipient,msg)
- local a,b,c = canReceive(recipient)
- if type(send_queue[recipient]) ~= "table" then send_queue[recipient] = {} end
- if type(receive_queue[recipient]) ~= "table" then receive_queue[recipient] = {} end
- if c then
- local epoch = os.epoch()
- local str = encryption.encryptString(msg,password .. session_id,settings.hashSize,true,true,epoch)
- str = encryption.encryptString(str,settings["MutualKey"..recipient],256^2,true,true)
- rednet.send(recipient,str,"SMS#a"..next_msgID)
- send_queue[recipeint][next_msgID] = {epoch=epoch,payload=msg}
- next_msgID = next_msgID + 1
- table.insert(message_queue,{id=os.getComputerID(),msg=msg,conversation=recipient})
- return 1
- elseif b then
- local epoch = os.epoch()
- if not mutual_queue[recipient] then
- local key = randString(32)
- rednet.send(recipient,encryption.encryptString(key,password .. session_id,settings.hashSize,true,true,epoch),"SMS#K"..next_msgID)
- mutual_queue[recipient] = {epoch=epoch,payload=key}
- table.insert(retry_queue,{id=recipient,payload=msg})
- next_msgID = next_msgID + 1
- return 0
- end
- end
- if a and not secure_success then
- local epoch = os.epoch()
- rednet.send(recipient,encryption.encryptString(msg,password .. session_id, settings.hashSize, true, true, epoch), "SMS#A" .. next_msgID)
- send_queue[recipient][next_msgID] = {epoch=epoch,payload=msg}
- next_msgID = next_msgID + 1
- table.insert(message_queue,{id=os.getComputerID(),msg=msg,conversation=recipient})
- return 1
- end
- table.insert(retry_queue,{id=recipient,payload=msg})
- return 0
- end
- --UI bullsh t (PASTEBIN IS CENSORING ME THIS IS LITERALLY 1984 GEORGE ORWELL ANIMAL FARM BIG BROTHER IS WATCHING YOU FREEDOM IS SLAVERY IGNORANCE IS STRENGTH WAR IS PEACE ALL OF US ARE EQUAL BUT SOME OF US ARE MORE EQUAL THAN OTHERS DOUBLETHINK WRONGTHINK NEWSPEAK)
- local function ConversationScreen(id)
- term.redirect(base_term)
- term.clear()
- local scn = screen.Screen(1,1,term.getSize())
- term.redirect(scn.wndw)
- scn.type = "conversation_screen"
- scn.isSecure = mutual_keys[id]
- scn.recipient = id
- local temp = "Private Message THP" --TES = triple handshake protocol
- if scn.isSecure then
- temp = "Private Message MKP" -- mutual key protocol
- end
- local messageHistory = readMessageHistory(id)
- scn.textBoxes = {
- header = screen.TextBox(1,1,"Schem Messaging System SMS",maxX,1,colors.white,colors.green),
- chatType = screen.TextBox(1,2,temp,maxX,1,colors.white,colors.gray),
- menubar = screen.TextBox(1,3,messageHistory.name,maxX,1,colors.white,colors.gray)
- }
- scn.buttons = {
- exit = screen.Button(maxX - 3,3,"Exit",4,1,colors.white,colors.red,nil,"Exit"),
- messageEntry = screen.FormField(1,maxY - 3,"",maxX,4,colors.white,colors.lightGray,false,maxX*4)
- }
- scn.buttons.messageEntry.click = function(self) return self.type,self.header,self.pass,self.name end --Fixing form field
- term.redirect(base_term)
- scn.subscreen = screen.Screen(1,4,maxX,maxY - 7)
- scn.subscreen.messageHistory = messageHistory
- term.redirect(base_term)
- return scn
- end
- local function refreshMessages(subscreen)
- --TODO: Add scrolling
- local yPos,index = subscreen.h,#subscreen.messageHistory.msgs
- subscreen.textBoxes = {}
- term.redirect(subscreen.wndw)
- term.clear()
- while yPos > 0 and index > 0 do
- local id,msg = subscreen.messageHistory.msgs[index][1],subscreen.messageHistory.msgs[index][2]
- local txt = "[".. id .. "]: " .. msg
- local buttonHeight = math.ceil(#txt/(subscreen.w - 1))
- local color,xPos = colors.blue,1
- if tonumber(id) == os.getComputerID() then
- color = colors.orange
- xPos = 2
- end
- yPos = yPos - buttonHeight
- index = index - 1
- table.insert(subscreen.textBoxes,screen.TextBox(xPos,yPos+1,txt,subscreen.w - 1, buttonHeight,colors.white,color))
- end
- end
- local settings_screen = screen.SettingsScreen(settings)
- settings_screen.type = "settings"
- term.redirect(base_term)
- term.clear()
- local ui_screen = screen.Screen(1,1,term.getSize())
- term.redirect(ui_screen.wndw)
- ui_screen.textBoxes = {
- header = screen.TextBox(1,1,"Schem Messaging System SMS",maxX,1,colors.white,colors.green),
- menubar = screen.TextBox(1,2,string.rep(" ",maxX),maxX,1,colors.white,colors.gray), --Just a menu bar
- preview_screen = screen.TextBox(2,5,"",maxX - 2, maxY - 5,colors.white,colors.brown) --Conversation preview screen backdrop
- }
- ui_screen.buttons = {
- settings = screen.Button(1,2,"Settings",8,1,colors.white,colors.orange,nil,"Settings"),
- dm = screen.FormField(10,2,"DM:",7,1,colors.white,colors.blue,false,4,function(char) return string.match(char,"%d") or "" end), --digit only form field
- errors = screen.Button(18,2,"Errors",6,1,colors.white,colors.red,nil,"Errors"),
- new_conv = screen.Button(2,4,"New Conversation",maxX - 2,1,colors.white,colors.blue,nil,"New Conv"),
- up = screen.Button(maxX,5,"^",1,1,colors.white,colors.gray,nil,"Up"),
- down = screen.Button(maxX,maxY - 1, "v",1,1,colors.white,colors.gray,nil,"Down")
- }
- ui_screen.scroll = 0
- local conversation_screen = screen.Screen(2,5,maxX - 2, maxY - 5)
- ui_screen.type = "ui_screen"
- term.redirect(base_term)
- current_screen = ui_screen
- local function drawConversationScreen(page)
- if not fs.isDir("SMS/PrivateMessages") then fs.makeDir("SMS/PrivateMessages") end
- local conversations = fs.list("SMS/PrivateMessages")
- conversation_screen.buttons = {}
- local t = {}
- for k,v in pairs(conversations) do
- local id = tonumber(v)
- if id then
- table.insert(t,{readMessageHistory(id),id})
- end
- end
- table.sort(t,function(a,b) return (a[1].epoch or 0) < (b[1].epoch or 0) end)
- if #t <= 0 then
- conversation_screen:render()
- return 0
- end
- local conversationsPerPage = math.floor(conversation_screen.h/2)
- page = math.max(math.min(page,math.floor(#t/conversationsPerPage)),0)
- term.redirect(conversation_screen.wndw)
- for i=1,conversationsPerPage do
- local conversation = t[page*conversationsPerPage + i][1]
- local bgColor = colors.gray
- if i%2 == 1 then bcGolor = colors.lightGray end
- if conversation then
- local msg = conversation.msgs[#conversation.msgs]
- local text = conversation.name .. ":[" .. msg[1] .. "]" .. msg[2]
- table.insert(conversation_screen.buttons,screen.Button(1,2*i - 1,text,conversation_screen.w,2,colors.white,bgColor,function() return "pm",id end,"pm"))
- end
- end
- return page
- end
- local function trollScreen()
- local errors = {
- {"You have been reported.", "I am not a bot. I am a Volunteer Reddit Moderator. I do not have mod powers but my reports are taken seriously and those who get on my bad side tend to get banned in under 24 hours. I have numerous rules, which you may read in my post history, but 1 is the most important rule of all:", "I am an officer in training, and I expect to be treated the same way I would be with my uniform and badge.", "Watch your back and get used to this face kiddo, you'll be seeing a lot of it."},
- {"Sure, you are a vile piece of sh".."i".."t that does nothing but cause issues, and to be frank at the time I wanted nothing more than to throttle your likely-chubby neck. However I also realize that your awful state of being probably has something to do with your circumstances, that likely being a basement-dwelling reddit-addicted fatso, and that killing you would be a mercy. So, as with all people I despise, I would rather gravely injure you than put an end to your misery."},
- {"Dear @Moderator, I am reaching out to request the opportunity to unrestrict my account in exchange for a promise to showcase a spectacular airship build within the Minecraft valkyrien skies with other of it's addons. I assure you that this project will not only demonstrate my dedication to the mod & it's add-ons but also serve as a testament to the creativity and innovation that can flourish within the community. I am confident that this endeavor will not only benefit my account but also inspire and engage fellow players. Your consideration of this request is greatly appreciated. Sincerely, [SscreamMOrSmg6]"},
- {"Cool mute reason. You know that literally nothing i said related to anything conspiracy-related in any way, and you're just proving how much of a butthurt neckbeard with some desire for power and control you are?"},
- {"I'm want to be a clock","Why I should be on the CIockwork team"," ","I have a good understanding of java.","I know how to write minecraft mods","I have some great features I want to add.","Development has been extremely slow","I have a lot of time to work on the mod","I know kotlin","Those are my reasons of why I should be on the cIockwork Development team."}
- }
- local scn = screen.Screen(1,1,term.getSize())
- scn.type = "troll"
- term.redirect(scn.wndw)
- local yPos = 1,1
- for k,v in ipairs(errors[math.random(#errors)]) do
- table.insert(scn.textBoxes,screen.TextBox(1,yPos,v,maxX,math.ceil(#v/maxX),colors.red,colors.black))
- yPos = yPos + math.ceil(#v/maxX)
- end
- return scn
- end
- local function ui()
- while true do
- sleep(0)
- term.redirect(current_screen.wndw)
- term.clear()
- current_screen:render()
- if current_screen.type == "ui_screen" then
- current_screen.scroll = drawConversationScreen(current_screen.scroll)
- term.redirect(current_screen.wndw)
- local b,x,y
- while not b or not b.click do
- b,x,y = current_screen:getClick()
- if not b then b = conversation_screen:getClick(x,y) end
- sleep(0)
- end
- local btype,a,b,c = b:click()
- sleep(0)
- if btype == "Settings" then
- term.clear()
- current_screen = settings_screen
- elseif btype == "Up" then
- current_screen.scroll = current_screen.scroll - 1
- elseif btype == "Down" then
- current_screen.scroll = current_screen.scroll + 1
- elseif btype == "form" then
- if tonumber(b) then
- term.clear()
- current_screen = ConversationScreen(tonumber(b))
- end
- elseif btype == "Errors" then
- --TODO
- current_screen = trollScreen()
- elseif btype == "New Conv" then
- --TODO
- current_screen = trollScreen()
- elseif btype == "pm" then
- term.clear()
- current_screen = ConversationScreen(tonumber(a))
- end
- elseif current_screen.type == "settings" then
- settings = current_screen:updateSettings()
- writeSettings(settings)
- term.clear()
- current_screen = ui_screen
- elseif current_screen.type == "conversation_screen" then
- refreshMessages(current_screen.subscreen)
- term.redirect(current_screen.wndw)
- local flag = 0
- local msgEntry = current_screen.buttons.messageEntry
- term.setCursorBlink(true)
- while flag <= 0 do
- term.setCursorPos(msgEntry.x + #msgEntry.text%msgEntry.w,msgEntry.y + math.floor(#msgEntry.text/msgEntry.w))
- local e,a,b,c,d = os.pullEvent()
- if e == "refreshMessages" and tonumber(a) == tonumber(current_screen.recipient) then
- refreshMessages(current_screen.subscreen)
- term.redirect(current_screen.wndw)
- elseif e == "key" then
- if a <= 256 and #msgEntry.pass <= msgEntry.maxLength then
- local _,char = os.pullEvent("char") --Safe because char event always comes right after key event?
- msgEntry.pass = msgEntry.pass .. char
- msgEntry:updateText()
- elseif a == keys.delete or a == keys.backspace then
- msgEntry.pass = string.sub(msgEntry.pass,1,-2)
- msgEntry:updateText()
- elseif a == keys.enter then
- flag = 1
- end
- elseif e == "mouse_click" then
- local button = current_screen:waitForClick(a,b)
- if button then
- local buttonType,f,g,h = button:click()
- if buttonType == "Exit" then
- current_screen = ui_screen
- flag = 2
- end
- end
- end
- end
- term.setCursorBlink(false)
- if flag == 1 then
- send(tonumber(current_screen.recipient),msgEntry.pass)
- msgEntry.pass = ""
- msgEntry:updateText()
- end
- else
- os.pullEvent("mouse_click")
- current_screen = ui_screen
- end
- end
- end
- --Queue handling protocol
- local function handleQueues()
- while true do
- if #message_queue > 0 then
- local msg = table.remove(message_queue)
- addMessageHistory(msg.msg,msg.id,msg.conversation)
- end
- sleep(0)
- if #retry_queue > 0 then
- local msg = table.remove(retry_queue)
- local res = send(msg.id,msg.payload)
- if res < 0 then table.insert(retry_queue,msg) end
- end
- sleep(0)
- end
- end
- parallel.waitForAny(handleQueues,receive,ui) --Wait for any in case I add a logout protocol
- term.redirect(base_term)
- term.clear()
Advertisement
Add Comment
Please, Sign In to add comment