Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --========================================================--
- -- ROBCO INDUSTRIES (TM) UNIFIED OPERATING SYSTEM
- -- COPYRIGHT 2075-2077 ROBCO INDUSTRIES
- --========================================================--
- -------------------------
- -- CONFIG
- -------------------------
- local ENCRYPTION_KEY = "ROBCO-SECURE-KEY"
- local USER_DB = "/robco_users"
- -------------------------
- -- BASIC UI HELPERS
- -------------------------
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.green)
- local w, h = term.getSize()
- local function clearScreen()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.green)
- term.clear()
- term.setCursorPos(1,1)
- end
- local function centerText(y, text)
- local x = math.floor((w - #text) / 2) + 1
- term.setCursorPos(x, y)
- term.write(text)
- end
- -------------------------
- -- LOGIN SYSTEM
- -------------------------
- local function initUserDB()
- if not fs.exists(USER_DB) then
- local h = fs.open(USER_DB, "w")
- h.writeLine("admin:password") -- CHANGE THIS TO SET YOUR OWN LOGIN
- h.close()
- end
- end
- local function loadUsers()
- local users = {}
- if not fs.exists(USER_DB) then return users end
- local h = fs.open(USER_DB, "r")
- while true do
- local line = h.readLine()
- if not line then break end
- local user, pass = line:match("([^:]+):(.+)")
- if user and pass then users[user] = pass end
- end
- h.close()
- return users
- end
- -- FIXED PASSWORD INPUT FOR MINECRAFT
- local function readHidden(promptText)
- term.write(promptText)
- local password = ""
- while true do
- local event, p1 = os.pullEvent()
- if event == "char" then
- password = password .. p1
- term.write("*")
- elseif event == "key" then
- if p1 == keys.enter then
- print()
- return password
- elseif p1 == keys.backspace then
- if #password > 0 then
- password = password:sub(1, -2)
- local x, y = term.getCursorPos()
- term.setCursorPos(x-1, y)
- term.write(" ")
- term.setCursorPos(x-1, y)
- end
- end
- end
- end
- end
- local function loginScreen()
- initUserDB()
- local users = loadUsers()
- local attempts = 0
- while attempts < 3 do
- clearScreen()
- centerText(5, "ROBCO INDUSTRIES (TM)")
- centerText(6, "UNIFIED OPERATING SYSTEM")
- centerText(8, "USER LOGIN REQUIRED")
- term.setCursorPos(5, 10)
- term.write("USERNAME: ")
- local username = read()
- term.setCursorPos(5, 12)
- local password = readHidden("PASSWORD: ")
- if users[username] and users[username] == password then
- centerText(14, "ACCESS GRANTED")
- sleep(1)
- return true
- else
- centerText(14, "ACCESS DENIED")
- attempts = attempts + 1
- sleep(1.2)
- end
- end
- clearScreen()
- centerText(math.floor(h/2), "TERMINAL LOCKED")
- sleep(3)
- os.shutdown()
- end
- -- RUN LOGIN FIRST
- loginScreen()
- -------------------------
- -- BOOT ANIMATION
- -------------------------
- local function typeWrite(text, delay)
- delay = delay or 0.03
- for i = 1, #text do
- write(text:sub(i,i))
- sleep(delay)
- end
- print()
- end
- local function bootSequence()
- clearScreen()
- centerText(math.floor(h/2)-2, "ROBCO INDUSTRIES (TM)")
- centerText(math.floor(h/2), "UNIFIED OPERATING SYSTEM")
- sleep(1.5)
- clearScreen()
- typeWrite("BOOTING ROBCO INDUSTRIES (TM) UOS v2.3...", 0.04)
- sleep(0.4)
- typeWrite("INITIALIZING KERNEL MODULES.............OK", 0.02)
- typeWrite("CHECKING MEMORY BANKS...................OK", 0.02)
- typeWrite("SCANNING PERIPHERALS....................OK", 0.02)
- typeWrite("LOADING TERMINAL INTERFACE..............OK", 0.02)
- typeWrite("ESTABLISHING SECURE REDNET LAYER.......OK", 0.02)
- sleep(0.6)
- typeWrite("SYSTEM READY.", 0.05)
- sleep(0.8)
- end
- -- RUN BOOT AFTER LOGIN
- bootSequence()
- -------------------------
- -- FULL ROBCO UI
- -------------------------
- local function drawFrame()
- clearScreen()
- term.setCursorPos(1,1)
- term.write(string.rep("-", w))
- term.setCursorPos(1,h)
- term.write(string.rep("-", w))
- for y = 2, h-1 do
- term.setCursorPos(1,y)
- term.write("|")
- term.setCursorPos(w,y)
- term.write("|")
- end
- end
- local function drawHeader()
- drawFrame()
- centerText(2, "ROBCO INDUSTRIES (TM)")
- centerText(3, "UNIFIED OPERATING SYSTEM")
- centerText(4, "COPYRIGHT 2075-2077 ROBCO INDUSTRIES")
- term.setCursorPos(3,6)
- term.write("TERMINAL READY")
- end
- local function statusLine(text)
- term.setCursorPos(3, h-1)
- term.clearLine()
- term.setCursorPos(3, h-1)
- term.write(text)
- end
- local function prompt()
- term.setCursorPos(3, h-2)
- term.clearLine()
- term.setCursorPos(3, h-2)
- term.write("> ")
- end
- -------------------------
- -- ENCRYPTION
- -------------------------
- local function xorByte(a, b)
- local r = 0
- for i = 0, 7 do
- local x = a % 2
- local y = b % 2
- if x ~= y then r = r + 2^i end
- a = math.floor(a / 2)
- b = math.floor(b / 2)
- end
- return r
- end
- local function encrypt(text, key)
- if not key or key == "" then return text end
- local out = {}
- for i = 1, #text do
- local c = text:byte(i)
- local k = key:byte(((i-1) % #key) + 1)
- table.insert(out, string.char(xorByte(c, k)))
- end
- return table.concat(out)
- end
- local function decrypt(text, key)
- return encrypt(text, key)
- end
- -------------------------
- -- FILE SYSTEM
- -------------------------
- local function listFiles()
- statusLine("LISTING FILES...")
- local files = fs.list("")
- for i, f in ipairs(files) do
- term.setCursorPos(3, 9 + i)
- print(f)
- end
- end
- local function newFile(name)
- if not name then statusLine("USAGE: new <filename>") return end
- if fs.exists(name) then statusLine("FILE EXISTS") return end
- statusLine("CREATING FILE: "..name)
- term.setCursorPos(3,9)
- print("ENTER TEXT. END WITH '.'")
- local lines = {}
- while true do
- term.setCursorPos(3,10 + #lines)
- local line = read()
- if line == "." then break end
- table.insert(lines, line)
- end
- local h = fs.open(name, "w")
- for _, l in ipairs(lines) do h.writeLine(l) end
- h.close()
- statusLine("FILE SAVED")
- end
- local function editFile(name)
- if not name then statusLine("USAGE: edit <filename>") return end
- if not fs.exists(name) then statusLine("FILE NOT FOUND") return end
- statusLine("EDITING FILE: "..name)
- term.setCursorPos(3,9)
- print("CURRENT CONTENTS:")
- local h = fs.open(name, "r")
- local contents = h.readAll()
- h.close()
- term.setCursorPos(3,10)
- print(contents or "")
- term.setCursorPos(3,12)
- print("ENTER NEW CONTENT. END WITH '.'")
- local lines = {}
- while true do
- term.setCursorPos(3,13 + #lines)
- local line = read()
- if line == "." then break end
- table.insert(lines, line)
- end
- local h2 = fs.open(name, "w")
- for _, l in ipairs(lines) do h2.writeLine(l) end
- h2.close()
- statusLine("FILE UPDATED")
- end
- local function deleteFile(name)
- if not name then statusLine("USAGE: delete <filename>") return end
- if fs.exists(name) then
- fs.delete(name)
- statusLine("FILE DELETED")
- else
- statusLine("FILE NOT FOUND")
- end
- end
- -------------------------
- -- DISK FUNCTIONS
- -------------------------
- local function getDiskSide()
- for _, side in ipairs({"left","right","top","bottom","front","back"}) do
- if disk.isPresent(side) then return side end
- end
- return nil
- end
- local function saveToDisk(name)
- if not name then statusLine("USAGE: disk save <file>") return end
- if not fs.exists(name) then statusLine("FILE NOT FOUND") return end
- local side = getDiskSide()
- if not side then statusLine("NO DISK") return end
- local mount = disk.getMountPath(side)
- fs.copy(name, mount.."/"..name)
- statusLine("FILE SAVED TO DISK")
- end
- local function loadFromDisk(name)
- if not name then statusLine("USAGE: disk load <file>") return end
- local side = getDiskSide()
- if not side then statusLine("NO DISK") return end
- local mount = disk.getMountPath(side)
- if not fs.exists(mount.."/"..name) then
- statusLine("NOT ON DISK")
- return
- end
- fs.copy(mount.."/"..name, name)
- statusLine("FILE LOADED")
- end
- -------------------------
- -- NETWORKING
- -------------------------
- local modem = peripheral.find("modem")
- if modem then rednet.open(peripheral.getName(modem)) end
- local function connect(id)
- if not modem then statusLine("NO MODEM") return end
- if not id then statusLine("USAGE: connect <id>") return end
- statusLine("PINGING "..id.."...")
- rednet.send(id, encrypt("ROBCO_CONNECT", ENCRYPTION_KEY), "robco")
- local sender, msg = rednet.receive("robco", 2)
- if sender == id and decrypt(msg, ENCRYPTION_KEY) == "ROBCO_ACK" then
- statusLine("CONNECTED")
- else
- statusLine("NO RESPONSE")
- end
- end
- local function sendMsg(id, msg)
- if not modem then statusLine("NO MODEM") return end
- if not id or msg == "" then statusLine("USAGE: send <id> <msg>") return end
- rednet.send(id, encrypt(msg, ENCRYPTION_KEY), "robco")
- statusLine("ENCRYPTED MESSAGE SENT")
- end
- local function listen()
- if not modem then statusLine("NO MODEM") return end
- statusLine("LISTENING...")
- local sender, msg = rednet.receive("robco")
- local dec = decrypt(msg, ENCRYPTION_KEY)
- term.setCursorPos(3,9)
- print("MESSAGE FROM "..sender..":")
- term.setCursorPos(3,10)
- print(dec)
- statusLine("MESSAGE RECEIVED")
- end
- -- Background auto‑ACK
- local function backgroundListener()
- if not modem then return end
- while true do
- local sender, msg = rednet.receive("robco")
- if decrypt(msg, ENCRYPTION_KEY) == "ROBCO_CONNECT" then
- rednet.send(sender, encrypt("ROBCO_ACK", ENCRYPTION_KEY), "robco")
- end
- end
- end
- -------------------------
- -- HELP
- -------------------------
- local function help()
- term.setCursorPos(3,9)
- print("COMMANDS:")
- print(" list")
- print(" new <file>")
- print(" edit <file>")
- print(" delete <file>")
- print(" disk save <file>")
- print(" disk load <file>")
- print(" connect <id>")
- print(" send <id> <msg>")
- print(" listen")
- statusLine("HELP SHOWN")
- end
- -------------------------
- -- MAIN LOOP
- -------------------------
- drawHeader()
- term.setCursorPos(3,8)
- print("TYPE 'help' FOR COMMANDS")
- local function mainLoop()
- while true do
- prompt()
- local input = read()
- local args = {}
- for word in input:gmatch("%S+") do table.insert(args, word) end
- local cmd = args[1]
- drawHeader()
- if cmd == "list" then listFiles()
- elseif cmd == "new" then newFile(args[2])
- elseif cmd == "edit" then editFile(args[2])
- elseif cmd == "delete" then deleteFile(args[2])
- elseif cmd == "disk" and args[2] == "save" then saveToDisk(args[3])
- elseif cmd == "disk" and args[2] == "load" then loadFromDisk(args[3])
- elseif cmd == "connect" then connect(tonumber(args[2]))
- elseif cmd == "send" then sendMsg(tonumber(args[2]), table.concat(args, " ", 3))
- elseif cmd == "listen" then listen()
- elseif cmd == "help" then help()
- elseif cmd == "clear" then drawHeader()
- else statusLine("UNKNOWN COMMAND")
- end
- end
- end
- if modem then
- parallel.waitForAny(mainLoop, backgroundListener)
- else
- mainLoop()
- end
Advertisement
Add Comment
Please, Sign In to add comment