Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Konfiguration & Pfade
- local CONFIG_FILE = ".sys_config"
- local redstone_side = "back" -- Seite, an der Project Red Kabel hängen
- -- System-Status (wird zur Laufzeit gehalten)
- local sys_config = {
- adminCreated = false,
- adminName = "",
- adminPass = "",
- users = {},
- systemsActive = false
- }
- -- Helfer: Konfiguration laden
- local function loadConfig()
- if fs.exists(CONFIG_FILE) then
- local f = fs.open(CONFIG_FILE, "r")
- local data = f.readAll()
- f.close()
- sys_config = textutils.unserialize(data) or sys_config
- end
- end
- -- Helfer: Konfiguration speichern
- local function saveConfig()
- local f = fs.open(CONFIG_FILE, "w")
- f.write(textutils.serialize(sys_config))
- f.close()
- end
- -- Grafischer Helfer: Bildschirm leeren mit Hintergrundfarbe
- local function clearScreen(bgColor, textColor)
- term.setBackgroundColor(bgColor or colors.gray)
- term.setTextColor(textColor or colors.white)
- term.clear()
- term.setCursorPos(1,1)
- end
- -- Grafischer Helfer: Zentrierter Text
- local function printCentered(y, text, bgColor, textColor)
- local w, h = term.getSize()
- local x = math.floor((w - #text) / 2) + 1
- term.setCursorPos(x, y)
- if bgColor then term.setBackgroundColor(bgColor) end
- if textColor then term.setTextColor(textColor) end
- term.write(text)
- end
- -- Grafischer Helfer: Ladebalken
- local function drawProgressBar(y, progress, max)
- local w, h = term.getSize()
- local barWidth = w - 10
- local filled = math.floor((progress / max) * barWidth)
- term.setCursorPos(6, y)
- term.setBackgroundColor(colors.lightGray)
- term.write(string.rep(" ", barWidth))
- term.setCursorPos(6, y)
- term.setBackgroundColor(colors.lime)
- term.write(string.rep(" ", filled))
- end
- -- 1. DER BOOT-VORGANG
- local function bootSequence()
- clearScreen(colors.black, colors.cyan)
- os.sleep(0.5)
- printCentered(4, "OS-SYSTEMS V1.12.2", colors.black, colors.cyan)
- printCentered(5, "------------------", colors.black, colors.gray)
- local modules = {"Lade Kernel...", "Initialisiere Multishell...", "Pruefe Redstone-Verbindungen...", "Verbinde mit Project Red...", "System Bereit."}
- for i, msg do
- printCentered(8, msg .. string.rep(" ", 15), colors.black, colors.white)
- drawProgressBar(10, i, #modules)
- os.sleep(0.6)
- end
- os.sleep(0.5)
- end
- -- 2. PROFIL-ERSTELLUNG
- local function createProfileUI()
- clearScreen(colors.blue, colors.white)
- if not sys_config.adminCreated then
- -- Admin Erstellung
- printCentered(3, "=== ERSTEINSCHALTUNG: ADMIN ERSTELLEN ===", colors.blue, colors.yellow)
- term.setCursorPos(5, 7)
- term.write("Admin Name: ")
- local name = read()
- term.setCursorPos(5, 9)
- term.write("Passwort: ")
- local pass = read("*") -- Versteckt die Eingabe
- sys_config.adminName = name
- sys_config.adminPass = pass
- sys_config.adminCreated = true
- saveConfig()
- printCentered(13, "Admin-Profil erfolgreich erstellt!", colors.blue, colors.lime)
- os.sleep(2)
- else
- -- Normaler User Erstellung (Optional aus dem Menü aufrufbar)
- clearScreen(colors.blue, colors.white)
- printCentered(3, "=== NEUEN NUTZER ANLEGEN ===", colors.blue, colors.yellow)
- term.setCursorPos(5, 7)
- term.write("Username: ")
- local name = read()
- term.setCursorPos(5, 9)
- term.write("Passwort: ")
- local pass = read("*")
- sys_config.users[name] = pass
- saveConfig()
- printCentered(13, "Nutzer erfolgreich angelegt!", colors.blue, colors.lime)
- os.sleep(2)
- end
- end
- -- 3. LOGIN SCREEN
- local function loginUI()
- while true do
- clearScreen(colors.gray, colors.white)
- printCentered(3, "=== SYSTEM LOGIN ===", colors.gray, colors.cyan)
- term.setCursorPos(5, 7)
- term.write("Benutzername: ")
- local user = read()
- term.setCursorPos(5, 9)
- term.write("Passwort: ")
- local pass = read("*")
- if user == sys_config.adminName and pass == sys_config.adminPass then
- return "admin"
- elseif sys_config.users[user] and sys_config.users[user] == pass then
- return "user"
- else
- printCentered(12, "Falsches Passwort oder Benutzer!", colors.gray, colors.red)
- os.sleep(2)
- end
- end
- end
- -- 4. ADMIN & USER DASHBOARDS (Die Steuerung)
- local function updateRedstone()
- -- Gibt ein Redstone-Signal aus, wenn die Basissysteme aktiv sind
- redstone.setOutput(redstone_side, sys_config.systemsActive)
- end
- local function adminDashboard()
- while true do
- clearScreen(colors.lightGray, colors.black)
- printCentered(2, "=== ADMIN DASHBOARD ===", colors.lightGray, colors.red)
- -- Status-Anzeige
- local statusText = sys_config.systemsActive and "[ ONLINE ]" or "[ OFFLINE ]"
- local statusColor = sys_config.systemsActive and colors.green or colors.red
- printCentered(4, "Basis-Systeme: " .. statusText, colors.lightGray, statusColor)
- -- Optionen
- term.setCursorPos(5, 7) term.write("1. Basissysteme Umschalten (An/Aus)")
- term.setCursorPos(5, 9) term.write("2. Neuen Standard-User anlegen")
- term.setCursorPos(5, 11) term.write("3. Abmelden")
- printCentered(14, "Waehle eine Option (1-3): ", colors.lightGray, colors.black)
- local _, char = os.pullEvent("char")
- if char == "1" then
- sys_config.systemsActive = not sys_config.systemsActive
- updateRedstone()
- saveConfig()
- elseif char == "2" then
- createProfileUI()
- elseif char == "3" then
- break
- end
- end
- end
- local function userDashboard()
- while true do
- clearScreen(colors.lightGray, colors.black)
- printCentered(2, "=== USER DASHBOARD ===", colors.lightGray, colors.blue)
- if not sys_config.systemsActive then
- printCentered(6, "!! AUF_ZUEGE SPERRT !!", colors.lightGray, colors.red)
- printCentered(8, "Die Basissysteme sind offline.", colors.lightGray, colors.black)
- printCentered(9, "Bitte den Admin, sie zu starten.", colors.lightGray, colors.black)
- else
- printCentered(6, "Aufzuege: BEREIT", colors.lightGray, colors.green)
- printCentered(8, "[Hier koennte deine Aufzugssteuerung stehen]", colors.lightGray, colors.gray)
- end
- printCentered(13, "Druecke 'Q' zum Abmelden", colors.lightGray, colors.gray)
- local _, char = os.pullEvent("char")
- if char == "q" or char == "Q" then
- break
- end
- end
- end
- -- HAUPTPROGRAMM-SCHLEIFE
- loadConfig()
- bootSequence()
- if not sys_config.adminCreated then
- createProfileUI()
- end
- -- Aktualisiere Redstone-Status direkt nach dem Boot (falls Server-Neustart)
- updateRedstone()
- while true do
- local role = loginUI()
- if role == "admin" then
- adminDashboard()
- type = "user"
- userDashboard()
- end
- end
Advertisement