DraRex368

ROBCO OS

Feb 7th, 2026 (edited)
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.68 KB | None | 0 0
  1. --[[
  2. ROBCO INDUSTRIES UNIFIED OPERATING SYSTEM
  3. Single-file terminal system for ComputerCraft / CC:Tweaked
  4.  
  5. Features:
  6. - Boot animation (FO4-inspired)
  7. - Login system with users + passwords
  8. - Secondary auth for secure systems
  9. - Simple UI framework (screens + menus)
  10. - Network system (rednet)
  11. - File editor (create/edit/delete/save)
  12. - File viewer (read files with pagination)
  13. - Speaker usage (if attached)
  14. ]]
  15.  
  16. -------------------------
  17. -- CONFIG & STATE
  18. -------------------------
  19.  
  20. local VERSION = "v1.0"
  21. local SYSTEM_NAME = "ROBCO TERMINAL"
  22. local SECURE_SYSTEM_NAME = "SECURE SUBSYSTEM"
  23.  
  24. -- Users database
  25. local USERS = {
  26.     admin = { password = "admin123", clearance = 3 },
  27.     overseer = { password = "vaulttec", clearance = 2 },
  28.     guest = { password = "guest", clearance = 1 },
  29. }
  30.  
  31. -- Secondary auth users
  32. local SECURE_USERS = {
  33.     secadmin = { password = "secpass" },
  34. }
  35.  
  36. -- Runtime state
  37. local state = {
  38.     currentUser = nil,
  39.     currentClearance = 0,
  40.     running = true,
  41.     modemSide = nil,
  42.     speaker = nil,
  43. }
  44.  
  45. -------------------------
  46. -- UTILITIES
  47. -------------------------
  48.  
  49. local function centerText(y, text)
  50.     local w = term.getSize()
  51.     term.setCursorPos(math.floor((w - #text) / 2) + 1, y)
  52.     term.write(text)
  53. end
  54.  
  55. local function clearScreen()
  56.     term.setBackgroundColor(colors.black)
  57.     term.setTextColor(colors.green)
  58.     term.clear()
  59.     term.setCursorPos(1,1)
  60. end
  61.  
  62. local function beep(freq, dur)
  63.     if state.speaker then
  64.         state.speaker.playNote("harp", 1, math.floor(freq / 100))
  65.         sleep(dur or 0.1)
  66.     end
  67. end
  68.  
  69. local function promptInput(label, hidden)
  70.     term.setTextColor(colors.green)
  71.     write(label .. ": ")
  72.     if hidden then
  73.         local s = ""
  74.         while true do
  75.             local e, p = os.pullEvent()
  76.             if e == "char" then
  77.                 s = s .. p
  78.                 write("*")
  79.             elseif e == "key" then
  80.                 if p == keys.enter then
  81.                     print()
  82.                     break
  83.                 elseif p == keys.backspace and #s > 0 then
  84.                     s = s:sub(1, -2)
  85.                     local x, y = term.getCursorPos()
  86.                     term.setCursorPos(x-1, y)
  87.                     write(" ")
  88.                     term.setCursorPos(x-1, y)
  89.                 end
  90.             end
  91.         end
  92.         return s
  93.     else
  94.         return read()
  95.     end
  96. end
  97.  
  98. local function waitKey(msg)
  99.     if msg then print(msg) end
  100.     print("Press any key to continue...")
  101.     os.pullEvent("key")
  102. end
  103.  
  104. -------------------------
  105. -- BOOT ANIMATION
  106. -------------------------
  107.  
  108. local function bootAnimation()
  109.     clearScreen()
  110.     centerText(3, "ROBCO INDUSTRIES UNIFIED OPERATING SYSTEM")
  111.     centerText(4, "COPYRIGHT 2075-2077 ROBCO INDUSTRIES")
  112.     centerText(5, "LOADED FROM: " .. SYSTEM_NAME)
  113.     sleep(1.5)
  114.  
  115.     term.setCursorPos(1,7)
  116.     print("Initializing system...")
  117.     sleep(0.5)
  118.     print("Performing memory check.................. OK")
  119.     sleep(0.4)
  120.     print("Checking peripherals.....................")
  121.  
  122.     for _, side in ipairs(rs.getSides()) do
  123.         if peripheral.getType(side) == "modem" then
  124.             state.modemSide = side
  125.         elseif peripheral.getType(side) == "speaker" then
  126.             state.speaker = peripheral.wrap(side)
  127.         end
  128.     end
  129.  
  130.     if state.modemSide then
  131.         print(" - Network modem: " .. state.modemSide .. "........ OK")
  132.     else
  133.         print(" - Network modem: NOT FOUND")
  134.     end
  135.  
  136.     if state.speaker then
  137.         print(" - Audio device: SPEAKER................. OK")
  138.         beep(400, 0.1)
  139.         beep(600, 0.1)
  140.     else
  141.         print(" - Audio device: NOT FOUND")
  142.     end
  143.  
  144.     sleep(0.6)
  145.     print("Loading kernel modules................... OK")
  146.     sleep(0.6)
  147.     print("Mounting file system..................... OK")
  148.     sleep(0.6)
  149.  
  150.     local w = term.getSize()
  151.     local barWidth = math.floor(w * 0.6)
  152.     local startX = math.floor((w - barWidth) / 2) + 1
  153.     local y = 14
  154.  
  155.     term.setCursorPos(startX, y)
  156.     term.write("[")
  157.     term.setCursorPos(startX + barWidth - 1, y)
  158.     term.write("]")
  159.  
  160.     for i = 1, barWidth - 2 do
  161.         term.setCursorPos(startX + i, y)
  162.         term.write("=")
  163.         beep(800 + i * 5, 0.02)
  164.         sleep(0.03)
  165.     end
  166.  
  167.     sleep(0.5)
  168.     centerText(16, "BOOT COMPLETE")
  169.     sleep(1.2)
  170. end
  171.  
  172. -------------------------
  173. -- LOGIN SYSTEM
  174. -------------------------
  175.  
  176. local function loginScreen()
  177.     while true do
  178.         clearScreen()
  179.         centerText(3, SYSTEM_NAME)
  180.         centerText(4, VERSION)
  181.         centerText(6, "USER LOGIN REQUIRED")
  182.         term.setCursorPos(1,8)
  183.  
  184.         local user = promptInput("USERNAME", false)
  185.         local pass = promptInput("PASSWORD", true)
  186.  
  187.         local record = USERS[user]
  188.         if record and record.password == pass then
  189.             state.currentUser = user
  190.             state.currentClearance = record.clearance
  191.             beep(1000, 0.1)
  192.             clearScreen()
  193.             centerText(5, "ACCESS GRANTED")
  194.             centerText(7, "WELCOME, " .. string.upper(user))
  195.             sleep(1.5)
  196.             return
  197.         else
  198.             beep(200, 0.2)
  199.             clearScreen()
  200.             centerText(5, "ACCESS DENIED")
  201.             sleep(1.5)
  202.         end
  203.     end
  204. end
  205.  
  206. -------------------------
  207. -- SECONDARY AUTH
  208. -------------------------
  209.  
  210. local function secondaryAuth()
  211.     clearScreen()
  212.     centerText(3, SECURE_SYSTEM_NAME)
  213.     centerText(5, "SECONDARY AUTHENTICATION REQUIRED")
  214.     term.setCursorPos(1,7)
  215.  
  216.     local user = promptInput("SECURE USER", false)
  217.     local pass = promptInput("SECURE PASS", true)
  218.  
  219.     local record = SECURE_USERS[user]
  220.     if record and record.password == pass then
  221.         beep(1200, 0.1)
  222.         clearScreen()
  223.         centerText(6, "SECONDARY ACCESS GRANTED")
  224.         sleep(1.2)
  225.         return true
  226.     else
  227.         beep(200, 0.2)
  228.         clearScreen()
  229.         centerText(6, "SECONDARY ACCESS DENIED")
  230.         sleep(1.2)
  231.         return false
  232.     end
  233. end
  234.  
  235. -------------------------
  236. -- NETWORK SYSTEM
  237. -------------------------
  238.  
  239. local function networkInit()
  240.     if state.modemSide then
  241.         rednet.open(state.modemSide)
  242.     end
  243. end
  244.  
  245. local function networkShutdown()
  246.     if state.modemSide then
  247.         rednet.close(state.modemSide)
  248.     end
  249. end
  250.  
  251. local function networkSend()
  252.     clearScreen()
  253.     centerText(3, "NETWORK SEND")
  254.     term.setCursorPos(1,5)
  255.  
  256.     local idStr = promptInput("TARGET ID", false)
  257.     local msg = promptInput("MESSAGE", false)
  258.  
  259.     local id = tonumber(idStr)
  260.     if id then
  261.         rednet.send(id, { from = state.currentUser, msg = msg }, "robco_net")
  262.         beep(900, 0.1)
  263.         print("Message sent.")
  264.     else
  265.         print("Invalid ID.")
  266.     end
  267.     waitKey()
  268. end
  269.  
  270. local function networkListen()
  271.     clearScreen()
  272.     centerText(3, "NETWORK LISTEN (CTRL+T TO EXIT)")
  273.     term.setCursorPos(1,5)
  274.  
  275.     while true do
  276.         local e = { os.pullEvent() }
  277.         if e[1] == "rednet_message" then
  278.             local sender, msg, proto = e[2], e[3], e[4]
  279.             if proto == "robco_net" then
  280.                 print("[" .. sender .. "] " .. msg.from .. ": " .. msg.msg)
  281.                 beep(700, 0.05)
  282.             end
  283.         elseif e[1] == "terminate" then
  284.             break
  285.         end
  286.     end
  287. end
  288.  
  289. local function networkMenu()
  290.     while true do
  291.         clearScreen()
  292.         centerText(3, "NETWORK SYSTEM")
  293.         term.setCursorPos(1,5)
  294.         print("1) Send Message")
  295.         print("2) Listen")
  296.         print("3) Back")
  297.         term.write("> ")
  298.         local choice = read()
  299.  
  300.         if choice == "1" then networkSend()
  301.         elseif choice == "2" then networkListen()
  302.         elseif choice == "3" then return end
  303.     end
  304. end
  305.  
  306. -------------------------
  307. -- FILE VIEWER (READ FILES)
  308. -------------------------
  309.  
  310. local function fileRead(path)
  311.     clearScreen()
  312.     centerText(2, "FILE VIEWER")
  313.     term.setCursorPos(1,4)
  314.  
  315.     if not fs.exists(path) then
  316.         print("File not found.")
  317.         waitKey()
  318.         return
  319.     end
  320.  
  321.     local h = fs.open(path, "r")
  322.     local content = h.readAll()
  323.     h.close()
  324.  
  325.     local w, hgt = term.getSize()
  326.     local lines = {}
  327.     for line in string.gmatch(content, "([^\n]*)\n?") do
  328.         table.insert(lines, line)
  329.     end
  330.  
  331.     local index = 1
  332.     while index <= #lines do
  333.         clearScreen()
  334.         centerText(2, "FILE VIEWER: " .. path)
  335.         term.setCursorPos(1,4)
  336.  
  337.         for i = 0, hgt - 7 do
  338.             local line = lines[index + i]
  339.             if not line then break end
  340.             print(line)
  341.         end
  342.  
  343.         print("")
  344.         print("Press ENTER for next page, or Q to quit.")
  345.         local e, key = os.pullEvent("key")
  346.  
  347.         if key == keys.q then break
  348.         elseif key == keys.enter then index = index + (hgt - 7)
  349.         end
  350.     end
  351. end
  352.  
  353. -------------------------
  354. -- FILE EDITOR
  355. -------------------------
  356.  
  357. local function fileEditor(path)
  358.     clearScreen()
  359.     centerText(2, "FILE EDITOR")
  360.     term.setCursorPos(1,4)
  361.     print("Editing: " .. path)
  362.     print("CTRL+T to exit editor")
  363.     print("Enter lines. Empty line to finish.")
  364.     print("")
  365.  
  366.     local lines = {}
  367.     if fs.exists(path) then
  368.         local h = fs.open(path, "r")
  369.         for line in h.readAll():gmatch("([^\n]*)\n?") do
  370.             table.insert(lines, line)
  371.         end
  372.         h.close()
  373.         print("--- Existing content loaded. ---")
  374.     end
  375.  
  376.     while true do
  377.         local line = read()
  378.         if line == "" then break end
  379.         table.insert(lines, line)
  380.     end
  381.  
  382.     local h = fs.open(path, "w")
  383.     for i, l in ipairs(lines) do
  384.         h.write(l)
  385.         if i < #lines then h.write("\n") end
  386.     end
  387.     h.close()
  388.  
  389.     beep(800, 0.1)
  390.     print("File saved.")
  391.     waitKey()
  392. end
  393.  
  394. local function fileDelete(path)
  395.     if fs.exists(path) then
  396.         fs.delete(path)
  397.         beep(500, 0.1)
  398.         print("File deleted.")
  399.     else
  400.         print("File not found.")
  401.     end
  402.     waitKey()
  403. end
  404.  
  405. local function filesMenu()
  406.     while true do
  407.         clearScreen()
  408.         centerText(2, "FILE SYSTEM")
  409.         term.setCursorPos(1,4)
  410.  
  411.         print("Files in root:")
  412.         for _, f in ipairs(fs.list("")) do
  413.             print(" - " .. f)
  414.         end
  415.  
  416.         print("")
  417.         print("1) Create/Edit File")
  418.         print("2) Read File")
  419.         print("3) Delete File")
  420.         print("4) Back")
  421.         term.write("> ")
  422.         local choice = read()
  423.  
  424.         if choice == "1" then
  425.             term.write("Enter filename: ")
  426.             local name = read()
  427.             if name ~= "" then fileEditor(name) end
  428.  
  429.         elseif choice == "2" then
  430.             term.write("Enter filename to read: ")
  431.             local name = read()
  432.             if name ~= "" then fileRead(name) end
  433.  
  434.         elseif choice == "3" then
  435.             term.write("Enter filename to delete: ")
  436.             local name = read()
  437.             if name ~= "" then fileDelete(name) end
  438.  
  439.         elseif choice == "4" then
  440.             return
  441.         end
  442.     end
  443. end
  444.  
  445. -------------------------
  446. -- SECURE SYSTEM
  447. -------------------------
  448.  
  449. local function secureSystem()
  450.     if not secondaryAuth() then return end
  451.  
  452.     while true do
  453.         clearScreen()
  454.         centerText(3, SECURE_SYSTEM_NAME)
  455.         term.setCursorPos(1,5)
  456.         print("1) Secure Logs")
  457.         print("2) Secure Network Ping")
  458.         print("3) Back")
  459.         term.write("> ")
  460.         local choice = read()
  461.  
  462.         if choice == "1" then
  463.             clearScreen()
  464.             centerText(3, "SECURE LOGS")
  465.             term.setCursorPos(1,5)
  466.             print("User: " .. state.currentUser)
  467.             print("Time: " .. textutils.formatTime(os.time(), true))
  468.             waitKey()
  469.  
  470.         elseif choice == "2" then
  471.             clearScreen()
  472.             centerText(3, "SECURE NETWORK PING")
  473.             term.setCursorPos(1,5)
  474.             if state.modemSide then
  475.                 rednet.broadcast({ type = "secure_ping", from = state.currentUser }, "robco_secure")
  476.                 beep(1000, 0.1)
  477.                 print("Ping sent.")
  478.             else
  479.                 print("No modem detected.")
  480.             end
  481.             waitKey()
  482.  
  483.         elseif choice == "3" then
  484.             return
  485.         end
  486.     end
  487. end
  488.  
  489. -------------------------
  490. -- MAIN MENU
  491. -------------------------
  492.  
  493. local function mainMenu()
  494.     while state.running do
  495.         clearScreen()
  496.         centerText(2, SYSTEM_NAME)
  497.         centerText(3, VERSION)
  498.         term.setCursorPos(1,5)
  499.         print("USER: " .. state.currentUser .. "  CLR: " .. state.currentClearance)
  500.         print("")
  501.         print("1) Files")
  502.         print("2) Network")
  503.         print("3) Secure Systems")
  504.         print("4) Logout")
  505.         print("5) Shutdown")
  506.         term.write("> ")
  507.         local choice = read()
  508.  
  509.         if choice == "1" then filesMenu()
  510.         elseif choice == "2" then networkMenu()
  511.         elseif choice == "3" then
  512.             if state.currentClearance >= 2 then secureSystem()
  513.             else
  514.                 clearScreen()
  515.                 centerText(6, "INSUFFICIENT CLEARANCE")
  516.                 beep(200, 0.2)
  517.                 sleep(1.5)
  518.             end
  519.         elseif choice == "4" then
  520.             state.currentUser = nil
  521.             state.currentClearance = 0
  522.             loginScreen()
  523.         elseif choice == "5" then
  524.             state.running = false
  525.         end
  526.     end
  527. end
  528.  
  529. -------------------------
  530. -- ENTRY POINT
  531. -------------------------
  532.  
  533. local function main()
  534.     bootAnimation()
  535.     loginScreen()
  536.     networkInit()
  537.     mainMenu()
  538.     networkShutdown()
  539.  
  540.     clearScreen()
  541.     centerText(6, "SYSTEM SHUTDOWN")
  542.     sleep(1)
  543.     term.clear()
  544. end
  545.  
  546. main()
  547.  
Advertisement
Add Comment
Please, Sign In to add comment