Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- ROBCO INDUSTRIES UNIFIED OPERATING SYSTEM
- Single-file terminal system for ComputerCraft / CC:Tweaked
- Features:
- - Boot animation (FO4-inspired)
- - Login system with users + passwords
- - Secondary auth for secure systems
- - Simple UI framework (screens + menus)
- - Network system (rednet)
- - File editor (create/edit/delete/save)
- - File viewer (read files with pagination)
- - Speaker usage (if attached)
- ]]
- -------------------------
- -- CONFIG & STATE
- -------------------------
- local VERSION = "v1.0"
- local SYSTEM_NAME = "ROBCO TERMINAL"
- local SECURE_SYSTEM_NAME = "SECURE SUBSYSTEM"
- -- Users database
- local USERS = {
- admin = { password = "admin123", clearance = 3 },
- overseer = { password = "vaulttec", clearance = 2 },
- guest = { password = "guest", clearance = 1 },
- }
- -- Secondary auth users
- local SECURE_USERS = {
- secadmin = { password = "secpass" },
- }
- -- Runtime state
- local state = {
- currentUser = nil,
- currentClearance = 0,
- running = true,
- modemSide = nil,
- speaker = nil,
- }
- -------------------------
- -- UTILITIES
- -------------------------
- local function centerText(y, text)
- local w = term.getSize()
- term.setCursorPos(math.floor((w - #text) / 2) + 1, y)
- term.write(text)
- end
- local function clearScreen()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.green)
- term.clear()
- term.setCursorPos(1,1)
- end
- local function beep(freq, dur)
- if state.speaker then
- state.speaker.playNote("harp", 1, math.floor(freq / 100))
- sleep(dur or 0.1)
- end
- end
- local function promptInput(label, hidden)
- term.setTextColor(colors.green)
- write(label .. ": ")
- if hidden then
- local s = ""
- while true do
- local e, p = os.pullEvent()
- if e == "char" then
- s = s .. p
- write("*")
- elseif e == "key" then
- if p == keys.enter then
- print()
- break
- elseif p == keys.backspace and #s > 0 then
- s = s:sub(1, -2)
- local x, y = term.getCursorPos()
- term.setCursorPos(x-1, y)
- write(" ")
- term.setCursorPos(x-1, y)
- end
- end
- end
- return s
- else
- return read()
- end
- end
- local function waitKey(msg)
- if msg then print(msg) end
- print("Press any key to continue...")
- os.pullEvent("key")
- end
- -------------------------
- -- BOOT ANIMATION
- -------------------------
- local function bootAnimation()
- clearScreen()
- centerText(3, "ROBCO INDUSTRIES UNIFIED OPERATING SYSTEM")
- centerText(4, "COPYRIGHT 2075-2077 ROBCO INDUSTRIES")
- centerText(5, "LOADED FROM: " .. SYSTEM_NAME)
- sleep(1.5)
- term.setCursorPos(1,7)
- print("Initializing system...")
- sleep(0.5)
- print("Performing memory check.................. OK")
- sleep(0.4)
- print("Checking peripherals.....................")
- for _, side in ipairs(rs.getSides()) do
- if peripheral.getType(side) == "modem" then
- state.modemSide = side
- elseif peripheral.getType(side) == "speaker" then
- state.speaker = peripheral.wrap(side)
- end
- end
- if state.modemSide then
- print(" - Network modem: " .. state.modemSide .. "........ OK")
- else
- print(" - Network modem: NOT FOUND")
- end
- if state.speaker then
- print(" - Audio device: SPEAKER................. OK")
- beep(400, 0.1)
- beep(600, 0.1)
- else
- print(" - Audio device: NOT FOUND")
- end
- sleep(0.6)
- print("Loading kernel modules................... OK")
- sleep(0.6)
- print("Mounting file system..................... OK")
- sleep(0.6)
- local w = term.getSize()
- local barWidth = math.floor(w * 0.6)
- local startX = math.floor((w - barWidth) / 2) + 1
- local y = 14
- term.setCursorPos(startX, y)
- term.write("[")
- term.setCursorPos(startX + barWidth - 1, y)
- term.write("]")
- for i = 1, barWidth - 2 do
- term.setCursorPos(startX + i, y)
- term.write("=")
- beep(800 + i * 5, 0.02)
- sleep(0.03)
- end
- sleep(0.5)
- centerText(16, "BOOT COMPLETE")
- sleep(1.2)
- end
- -------------------------
- -- LOGIN SYSTEM
- -------------------------
- local function loginScreen()
- while true do
- clearScreen()
- centerText(3, SYSTEM_NAME)
- centerText(4, VERSION)
- centerText(6, "USER LOGIN REQUIRED")
- term.setCursorPos(1,8)
- local user = promptInput("USERNAME", false)
- local pass = promptInput("PASSWORD", true)
- local record = USERS[user]
- if record and record.password == pass then
- state.currentUser = user
- state.currentClearance = record.clearance
- beep(1000, 0.1)
- clearScreen()
- centerText(5, "ACCESS GRANTED")
- centerText(7, "WELCOME, " .. string.upper(user))
- sleep(1.5)
- return
- else
- beep(200, 0.2)
- clearScreen()
- centerText(5, "ACCESS DENIED")
- sleep(1.5)
- end
- end
- end
- -------------------------
- -- SECONDARY AUTH
- -------------------------
- local function secondaryAuth()
- clearScreen()
- centerText(3, SECURE_SYSTEM_NAME)
- centerText(5, "SECONDARY AUTHENTICATION REQUIRED")
- term.setCursorPos(1,7)
- local user = promptInput("SECURE USER", false)
- local pass = promptInput("SECURE PASS", true)
- local record = SECURE_USERS[user]
- if record and record.password == pass then
- beep(1200, 0.1)
- clearScreen()
- centerText(6, "SECONDARY ACCESS GRANTED")
- sleep(1.2)
- return true
- else
- beep(200, 0.2)
- clearScreen()
- centerText(6, "SECONDARY ACCESS DENIED")
- sleep(1.2)
- return false
- end
- end
- -------------------------
- -- NETWORK SYSTEM
- -------------------------
- local function networkInit()
- if state.modemSide then
- rednet.open(state.modemSide)
- end
- end
- local function networkShutdown()
- if state.modemSide then
- rednet.close(state.modemSide)
- end
- end
- local function networkSend()
- clearScreen()
- centerText(3, "NETWORK SEND")
- term.setCursorPos(1,5)
- local idStr = promptInput("TARGET ID", false)
- local msg = promptInput("MESSAGE", false)
- local id = tonumber(idStr)
- if id then
- rednet.send(id, { from = state.currentUser, msg = msg }, "robco_net")
- beep(900, 0.1)
- print("Message sent.")
- else
- print("Invalid ID.")
- end
- waitKey()
- end
- local function networkListen()
- clearScreen()
- centerText(3, "NETWORK LISTEN (CTRL+T TO EXIT)")
- term.setCursorPos(1,5)
- while true do
- local e = { os.pullEvent() }
- if e[1] == "rednet_message" then
- local sender, msg, proto = e[2], e[3], e[4]
- if proto == "robco_net" then
- print("[" .. sender .. "] " .. msg.from .. ": " .. msg.msg)
- beep(700, 0.05)
- end
- elseif e[1] == "terminate" then
- break
- end
- end
- end
- local function networkMenu()
- while true do
- clearScreen()
- centerText(3, "NETWORK SYSTEM")
- term.setCursorPos(1,5)
- print("1) Send Message")
- print("2) Listen")
- print("3) Back")
- term.write("> ")
- local choice = read()
- if choice == "1" then networkSend()
- elseif choice == "2" then networkListen()
- elseif choice == "3" then return end
- end
- end
- -------------------------
- -- FILE VIEWER (READ FILES)
- -------------------------
- local function fileRead(path)
- clearScreen()
- centerText(2, "FILE VIEWER")
- term.setCursorPos(1,4)
- if not fs.exists(path) then
- print("File not found.")
- waitKey()
- return
- end
- local h = fs.open(path, "r")
- local content = h.readAll()
- h.close()
- local w, hgt = term.getSize()
- local lines = {}
- for line in string.gmatch(content, "([^\n]*)\n?") do
- table.insert(lines, line)
- end
- local index = 1
- while index <= #lines do
- clearScreen()
- centerText(2, "FILE VIEWER: " .. path)
- term.setCursorPos(1,4)
- for i = 0, hgt - 7 do
- local line = lines[index + i]
- if not line then break end
- print(line)
- end
- print("")
- print("Press ENTER for next page, or Q to quit.")
- local e, key = os.pullEvent("key")
- if key == keys.q then break
- elseif key == keys.enter then index = index + (hgt - 7)
- end
- end
- end
- -------------------------
- -- FILE EDITOR
- -------------------------
- local function fileEditor(path)
- clearScreen()
- centerText(2, "FILE EDITOR")
- term.setCursorPos(1,4)
- print("Editing: " .. path)
- print("CTRL+T to exit editor")
- print("Enter lines. Empty line to finish.")
- print("")
- local lines = {}
- if fs.exists(path) then
- local h = fs.open(path, "r")
- for line in h.readAll():gmatch("([^\n]*)\n?") do
- table.insert(lines, line)
- end
- h.close()
- print("--- Existing content loaded. ---")
- end
- while true do
- local line = read()
- if line == "" then break end
- table.insert(lines, line)
- end
- local h = fs.open(path, "w")
- for i, l in ipairs(lines) do
- h.write(l)
- if i < #lines then h.write("\n") end
- end
- h.close()
- beep(800, 0.1)
- print("File saved.")
- waitKey()
- end
- local function fileDelete(path)
- if fs.exists(path) then
- fs.delete(path)
- beep(500, 0.1)
- print("File deleted.")
- else
- print("File not found.")
- end
- waitKey()
- end
- local function filesMenu()
- while true do
- clearScreen()
- centerText(2, "FILE SYSTEM")
- term.setCursorPos(1,4)
- print("Files in root:")
- for _, f in ipairs(fs.list("")) do
- print(" - " .. f)
- end
- print("")
- print("1) Create/Edit File")
- print("2) Read File")
- print("3) Delete File")
- print("4) Back")
- term.write("> ")
- local choice = read()
- if choice == "1" then
- term.write("Enter filename: ")
- local name = read()
- if name ~= "" then fileEditor(name) end
- elseif choice == "2" then
- term.write("Enter filename to read: ")
- local name = read()
- if name ~= "" then fileRead(name) end
- elseif choice == "3" then
- term.write("Enter filename to delete: ")
- local name = read()
- if name ~= "" then fileDelete(name) end
- elseif choice == "4" then
- return
- end
- end
- end
- -------------------------
- -- SECURE SYSTEM
- -------------------------
- local function secureSystem()
- if not secondaryAuth() then return end
- while true do
- clearScreen()
- centerText(3, SECURE_SYSTEM_NAME)
- term.setCursorPos(1,5)
- print("1) Secure Logs")
- print("2) Secure Network Ping")
- print("3) Back")
- term.write("> ")
- local choice = read()
- if choice == "1" then
- clearScreen()
- centerText(3, "SECURE LOGS")
- term.setCursorPos(1,5)
- print("User: " .. state.currentUser)
- print("Time: " .. textutils.formatTime(os.time(), true))
- waitKey()
- elseif choice == "2" then
- clearScreen()
- centerText(3, "SECURE NETWORK PING")
- term.setCursorPos(1,5)
- if state.modemSide then
- rednet.broadcast({ type = "secure_ping", from = state.currentUser }, "robco_secure")
- beep(1000, 0.1)
- print("Ping sent.")
- else
- print("No modem detected.")
- end
- waitKey()
- elseif choice == "3" then
- return
- end
- end
- end
- -------------------------
- -- MAIN MENU
- -------------------------
- local function mainMenu()
- while state.running do
- clearScreen()
- centerText(2, SYSTEM_NAME)
- centerText(3, VERSION)
- term.setCursorPos(1,5)
- print("USER: " .. state.currentUser .. " CLR: " .. state.currentClearance)
- print("")
- print("1) Files")
- print("2) Network")
- print("3) Secure Systems")
- print("4) Logout")
- print("5) Shutdown")
- term.write("> ")
- local choice = read()
- if choice == "1" then filesMenu()
- elseif choice == "2" then networkMenu()
- elseif choice == "3" then
- if state.currentClearance >= 2 then secureSystem()
- else
- clearScreen()
- centerText(6, "INSUFFICIENT CLEARANCE")
- beep(200, 0.2)
- sleep(1.5)
- end
- elseif choice == "4" then
- state.currentUser = nil
- state.currentClearance = 0
- loginScreen()
- elseif choice == "5" then
- state.running = false
- end
- end
- end
- -------------------------
- -- ENTRY POINT
- -------------------------
- local function main()
- bootAnimation()
- loginScreen()
- networkInit()
- mainMenu()
- networkShutdown()
- clearScreen()
- centerText(6, "SYSTEM SHUTDOWN")
- sleep(1)
- term.clear()
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment