DraRex368

TEST (fixed)

Feb 7th, 2026
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.99 KB | None | 0 0
  1. --========================================================--
  2. --   ROBCO INDUSTRIES (TM) UNIFIED OPERATING SYSTEM
  3. --   COPYRIGHT 2075-2077 ROBCO INDUSTRIES
  4. --========================================================--
  5.  
  6. -------------------------
  7. -- CONFIG
  8. -------------------------
  9. local ENCRYPTION_KEY = "ROBCO-SECURE-KEY"
  10. local USER_DB = "/robco_users"
  11.  
  12. -------------------------
  13. -- BASIC UI HELPERS
  14. -------------------------
  15. term.setBackgroundColor(colors.black)
  16. term.setTextColor(colors.green)
  17.  
  18. local w, h = term.getSize()
  19.  
  20. local function clearScreen()
  21.     term.setBackgroundColor(colors.black)
  22.     term.setTextColor(colors.green)
  23.     term.clear()
  24.     term.setCursorPos(1,1)
  25. end
  26.  
  27. local function centerText(y, text)
  28.     local x = math.floor((w - #text) / 2) + 1
  29.     term.setCursorPos(x, y)
  30.     term.write(text)
  31. end
  32.  
  33. -------------------------
  34. -- LOGIN SYSTEM
  35. -------------------------
  36.  
  37. local function initUserDB()
  38.     if not fs.exists(USER_DB) then
  39.         local h = fs.open(USER_DB, "w")
  40.         h.writeLine("admin:password")  -- CHANGE THIS TO SET YOUR OWN LOGIN
  41.         h.close()
  42.     end
  43. end
  44.  
  45. local function loadUsers()
  46.     local users = {}
  47.     if not fs.exists(USER_DB) then return users end
  48.     local h = fs.open(USER_DB, "r")
  49.     while true do
  50.         local line = h.readLine()
  51.         if not line then break end
  52.         local user, pass = line:match("([^:]+):(.+)")
  53.         if user and pass then users[user] = pass end
  54.     end
  55.     h.close()
  56.     return users
  57. end
  58.  
  59. -- FIXED PASSWORD INPUT FOR MINECRAFT
  60. local function readHidden(promptText)
  61.     term.write(promptText)
  62.     local password = ""
  63.  
  64.     while true do
  65.         local event, p1 = os.pullEvent()
  66.  
  67.         if event == "char" then
  68.             password = password .. p1
  69.             term.write("*")
  70.  
  71.         elseif event == "key" then
  72.             if p1 == keys.enter then
  73.                 print()
  74.                 return password
  75.  
  76.             elseif p1 == keys.backspace then
  77.                 if #password > 0 then
  78.                     password = password:sub(1, -2)
  79.                     local x, y = term.getCursorPos()
  80.                     term.setCursorPos(x-1, y)
  81.                     term.write(" ")
  82.                     term.setCursorPos(x-1, y)
  83.                 end
  84.             end
  85.         end
  86.     end
  87. end
  88.  
  89. local function loginScreen()
  90.     initUserDB()
  91.     local users = loadUsers()
  92.  
  93.     local attempts = 0
  94.     while attempts < 3 do
  95.         clearScreen()
  96.         centerText(5, "ROBCO INDUSTRIES (TM)")
  97.         centerText(6, "UNIFIED OPERATING SYSTEM")
  98.         centerText(8, "USER LOGIN REQUIRED")
  99.  
  100.         term.setCursorPos(5, 10)
  101.         term.write("USERNAME: ")
  102.         local username = read()
  103.  
  104.         term.setCursorPos(5, 12)
  105.         local password = readHidden("PASSWORD: ")
  106.  
  107.         if users[username] and users[username] == password then
  108.             centerText(14, "ACCESS GRANTED")
  109.             sleep(1)
  110.             return true
  111.         else
  112.             centerText(14, "ACCESS DENIED")
  113.             attempts = attempts + 1
  114.             sleep(1.2)
  115.         end
  116.     end
  117.  
  118.     clearScreen()
  119.     centerText(math.floor(h/2), "TERMINAL LOCKED")
  120.     sleep(3)
  121.     os.shutdown()
  122. end
  123.  
  124. -- RUN LOGIN FIRST
  125. loginScreen()
  126.  
  127. -------------------------
  128. -- BOOT ANIMATION
  129. -------------------------
  130. local function typeWrite(text, delay)
  131.     delay = delay or 0.03
  132.     for i = 1, #text do
  133.         write(text:sub(i,i))
  134.         sleep(delay)
  135.     end
  136.     print()
  137. end
  138.  
  139. local function bootSequence()
  140.     clearScreen()
  141.     centerText(math.floor(h/2)-2, "ROBCO INDUSTRIES (TM)")
  142.     centerText(math.floor(h/2), "UNIFIED OPERATING SYSTEM")
  143.     sleep(1.5)
  144.  
  145.     clearScreen()
  146.     typeWrite("BOOTING ROBCO INDUSTRIES (TM) UOS v2.3...", 0.04)
  147.     sleep(0.4)
  148.     typeWrite("INITIALIZING KERNEL MODULES.............OK", 0.02)
  149.     typeWrite("CHECKING MEMORY BANKS...................OK", 0.02)
  150.     typeWrite("SCANNING PERIPHERALS....................OK", 0.02)
  151.     typeWrite("LOADING TERMINAL INTERFACE..............OK", 0.02)
  152.     typeWrite("ESTABLISHING SECURE REDNET LAYER.......OK", 0.02)
  153.     sleep(0.6)
  154.     typeWrite("SYSTEM READY.", 0.05)
  155.     sleep(0.8)
  156. end
  157.  
  158. -- RUN BOOT AFTER LOGIN
  159. bootSequence()
  160.  
  161. -------------------------
  162. -- FULL ROBCO UI
  163. -------------------------
  164. local function drawFrame()
  165.     clearScreen()
  166.     term.setCursorPos(1,1)
  167.     term.write(string.rep("-", w))
  168.     term.setCursorPos(1,h)
  169.     term.write(string.rep("-", w))
  170.     for y = 2, h-1 do
  171.         term.setCursorPos(1,y)
  172.         term.write("|")
  173.         term.setCursorPos(w,y)
  174.         term.write("|")
  175.     end
  176. end
  177.  
  178. local function drawHeader()
  179.     drawFrame()
  180.     centerText(2, "ROBCO INDUSTRIES (TM)")
  181.     centerText(3, "UNIFIED OPERATING SYSTEM")
  182.     centerText(4, "COPYRIGHT 2075-2077 ROBCO INDUSTRIES")
  183.     term.setCursorPos(3,6)
  184.     term.write("TERMINAL READY")
  185. end
  186.  
  187. local function statusLine(text)
  188.     term.setCursorPos(3, h-1)
  189.     term.clearLine()
  190.     term.setCursorPos(3, h-1)
  191.     term.write(text)
  192. end
  193.  
  194. local function prompt()
  195.     term.setCursorPos(3, h-2)
  196.     term.clearLine()
  197.     term.setCursorPos(3, h-2)
  198.     term.write("> ")
  199. end
  200.  
  201. -------------------------
  202. -- ENCRYPTION
  203. -------------------------
  204. local function xorByte(a, b)
  205.     local r = 0
  206.     for i = 0, 7 do
  207.         local x = a % 2
  208.         local y = b % 2
  209.         if x ~= y then r = r + 2^i end
  210.         a = math.floor(a / 2)
  211.         b = math.floor(b / 2)
  212.     end
  213.     return r
  214. end
  215.  
  216. local function encrypt(text, key)
  217.     if not key or key == "" then return text end
  218.     local out = {}
  219.     for i = 1, #text do
  220.         local c = text:byte(i)
  221.         local k = key:byte(((i-1) % #key) + 1)
  222.         table.insert(out, string.char(xorByte(c, k)))
  223.     end
  224.     return table.concat(out)
  225. end
  226.  
  227. local function decrypt(text, key)
  228.     return encrypt(text, key)
  229. end
  230.  
  231. -------------------------
  232. -- FILE SYSTEM
  233. -------------------------
  234. local function listFiles()
  235.     statusLine("LISTING FILES...")
  236.     local files = fs.list("")
  237.     for i, f in ipairs(files) do
  238.         term.setCursorPos(3, 9 + i)
  239.         print(f)
  240.     end
  241. end
  242.  
  243. local function newFile(name)
  244.     if not name then statusLine("USAGE: new <filename>") return end
  245.     if fs.exists(name) then statusLine("FILE EXISTS") return end
  246.  
  247.     statusLine("CREATING FILE: "..name)
  248.     term.setCursorPos(3,9)
  249.     print("ENTER TEXT. END WITH '.'")
  250.  
  251.     local lines = {}
  252.     while true do
  253.         term.setCursorPos(3,10 + #lines)
  254.         local line = read()
  255.         if line == "." then break end
  256.         table.insert(lines, line)
  257.     end
  258.  
  259.     local h = fs.open(name, "w")
  260.     for _, l in ipairs(lines) do h.writeLine(l) end
  261.     h.close()
  262.     statusLine("FILE SAVED")
  263. end
  264.  
  265. local function editFile(name)
  266.     if not name then statusLine("USAGE: edit <filename>") return end
  267.     if not fs.exists(name) then statusLine("FILE NOT FOUND") return end
  268.  
  269.     statusLine("EDITING FILE: "..name)
  270.     term.setCursorPos(3,9)
  271.     print("CURRENT CONTENTS:")
  272.  
  273.     local h = fs.open(name, "r")
  274.     local contents = h.readAll()
  275.     h.close()
  276.  
  277.     term.setCursorPos(3,10)
  278.     print(contents or "")
  279.     term.setCursorPos(3,12)
  280.     print("ENTER NEW CONTENT. END WITH '.'")
  281.  
  282.     local lines = {}
  283.     while true do
  284.         term.setCursorPos(3,13 + #lines)
  285.         local line = read()
  286.         if line == "." then break end
  287.         table.insert(lines, line)
  288.     end
  289.  
  290.     local h2 = fs.open(name, "w")
  291.     for _, l in ipairs(lines) do h2.writeLine(l) end
  292.     h2.close()
  293.     statusLine("FILE UPDATED")
  294. end
  295.  
  296. local function deleteFile(name)
  297.     if not name then statusLine("USAGE: delete <filename>") return end
  298.     if fs.exists(name) then
  299.         fs.delete(name)
  300.         statusLine("FILE DELETED")
  301.     else
  302.         statusLine("FILE NOT FOUND")
  303.     end
  304. end
  305.  
  306. -------------------------
  307. -- DISK FUNCTIONS
  308. -------------------------
  309. local function getDiskSide()
  310.     for _, side in ipairs({"left","right","top","bottom","front","back"}) do
  311.         if disk.isPresent(side) then return side end
  312.     end
  313.     return nil
  314. end
  315.  
  316. local function saveToDisk(name)
  317.     if not name then statusLine("USAGE: disk save <file>") return end
  318.     if not fs.exists(name) then statusLine("FILE NOT FOUND") return end
  319.  
  320.     local side = getDiskSide()
  321.     if not side then statusLine("NO DISK") return end
  322.  
  323.     local mount = disk.getMountPath(side)
  324.     fs.copy(name, mount.."/"..name)
  325.     statusLine("FILE SAVED TO DISK")
  326. end
  327.  
  328. local function loadFromDisk(name)
  329.     if not name then statusLine("USAGE: disk load <file>") return end
  330.  
  331.     local side = getDiskSide()
  332.     if not side then statusLine("NO DISK") return end
  333.  
  334.     local mount = disk.getMountPath(side)
  335.     if not fs.exists(mount.."/"..name) then
  336.         statusLine("NOT ON DISK")
  337.         return
  338.     end
  339.  
  340.     fs.copy(mount.."/"..name, name)
  341.     statusLine("FILE LOADED")
  342. end
  343.  
  344. -------------------------
  345. -- NETWORKING
  346. -------------------------
  347. local modem = peripheral.find("modem")
  348. if modem then rednet.open(peripheral.getName(modem)) end
  349.  
  350. local function connect(id)
  351.     if not modem then statusLine("NO MODEM") return end
  352.     if not id then statusLine("USAGE: connect <id>") return end
  353.  
  354.     statusLine("PINGING "..id.."...")
  355.     rednet.send(id, encrypt("ROBCO_CONNECT", ENCRYPTION_KEY), "robco")
  356.  
  357.     local sender, msg = rednet.receive("robco", 2)
  358.     if sender == id and decrypt(msg, ENCRYPTION_KEY) == "ROBCO_ACK" then
  359.         statusLine("CONNECTED")
  360.     else
  361.         statusLine("NO RESPONSE")
  362.     end
  363. end
  364.  
  365. local function sendMsg(id, msg)
  366.     if not modem then statusLine("NO MODEM") return end
  367.     if not id or msg == "" then statusLine("USAGE: send <id> <msg>") return end
  368.  
  369.     rednet.send(id, encrypt(msg, ENCRYPTION_KEY), "robco")
  370.     statusLine("ENCRYPTED MESSAGE SENT")
  371. end
  372.  
  373. local function listen()
  374.     if not modem then statusLine("NO MODEM") return end
  375.  
  376.     statusLine("LISTENING...")
  377.     local sender, msg = rednet.receive("robco")
  378.     local dec = decrypt(msg, ENCRYPTION_KEY)
  379.  
  380.     term.setCursorPos(3,9)
  381.     print("MESSAGE FROM "..sender..":")
  382.     term.setCursorPos(3,10)
  383.     print(dec)
  384.     statusLine("MESSAGE RECEIVED")
  385. end
  386.  
  387. -- Background auto‑ACK
  388. local function backgroundListener()
  389.     if not modem then return end
  390.     while true do
  391.         local sender, msg = rednet.receive("robco")
  392.         if decrypt(msg, ENCRYPTION_KEY) == "ROBCO_CONNECT" then
  393.             rednet.send(sender, encrypt("ROBCO_ACK", ENCRYPTION_KEY), "robco")
  394.         end
  395.     end
  396. end
  397.  
  398. -------------------------
  399. -- HELP
  400. -------------------------
  401. local function help()
  402.     term.setCursorPos(3,9)
  403.     print("COMMANDS:")
  404.     print(" list")
  405.     print(" new <file>")
  406.     print(" edit <file>")
  407.     print(" delete <file>")
  408.     print(" disk save <file>")
  409.     print(" disk load <file>")
  410.     print(" connect <id>")
  411.     print(" send <id> <msg>")
  412.     print(" listen")
  413.     statusLine("HELP SHOWN")
  414. end
  415.  
  416. -------------------------
  417. -- MAIN LOOP
  418. -------------------------
  419. drawHeader()
  420. term.setCursorPos(3,8)
  421. print("TYPE 'help' FOR COMMANDS")
  422.  
  423. local function mainLoop()
  424.     while true do
  425.         prompt()
  426.         local input = read()
  427.         local args = {}
  428.         for word in input:gmatch("%S+") do table.insert(args, word) end
  429.  
  430.         local cmd = args[1]
  431.         drawHeader()
  432.  
  433.         if cmd == "list" then listFiles()
  434.         elseif cmd == "new" then newFile(args[2])
  435.         elseif cmd == "edit" then editFile(args[2])
  436.         elseif cmd == "delete" then deleteFile(args[2])
  437.         elseif cmd == "disk" and args[2] == "save" then saveToDisk(args[3])
  438.         elseif cmd == "disk" and args[2] == "load" then loadFromDisk(args[3])
  439.         elseif cmd == "connect" then connect(tonumber(args[2]))
  440.         elseif cmd == "send" then sendMsg(tonumber(args[2]), table.concat(args, " ", 3))
  441.         elseif cmd == "listen" then listen()
  442.         elseif cmd == "help" then help()
  443.         elseif cmd == "clear" then drawHeader()
  444.         else statusLine("UNKNOWN COMMAND")
  445.         end
  446.     end
  447. end
  448.  
  449. if modem then
  450.     parallel.waitForAny(mainLoop, backgroundListener)
  451. else
  452.     mainLoop()
  453. end
  454.  
Advertisement
Add Comment
Please, Sign In to add comment