Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local side = "back"
- local opentime = 5
- local userFile = "users.dat"
- local maxAttempts = 3
- local lockoutFile = "lockout.dat"
- local lockoutDuration = 600
- -- User data
- local users = {
- {username = "Riku", password = "1111", admin = true},
- --Yo a little help here!?... Alright alright I got it, stand back son.. One, one, one, uhhmmmuhhhhh one!
- {username = "Guest", password = "$pass42", admin = false},
- }
- -- Function to read the lockout state from the file
- local function readLockoutState()
- local file, err = fs.open(lockoutFile, "r")
- if file then
- local state = file.readAll()
- file.close()
- return tonumber(state) or 0
- else
- print("Error reading lockout file:", err)
- return 0
- end
- end
- -- Function to write the lockout state to the file
- local function writeLockoutState(attempts)
- local file, err = fs.open(lockoutFile, "w")
- if file then
- file.write(tostring(attempts))
- file.close()
- else
- print("Error writing to lockout file:", err)
- end
- end
- -- Function to load user data from file
- local function loadUserData()
- local file, err = fs.open(userFile, "r")
- if file then
- local data = file.readAll()
- file.close()
- return textutils.unserialize(data) or users
- else
- print("Error reading user file:", err)
- return users
- end
- end
- -- Function to save user data to file
- local function saveUserData()
- local file, err = fs.open(userFile, "w")
- if file then
- file.write(textutils.serialize(users))
- file.close()
- else
- print("Error writing to user file:", err)
- end
- end
- -- Forest Quest Code
- local function playForestQuest()
- term.clear()
- term.setCursorPos(1, 1)
- print("Welcome to Forest Quest!")
- print("You find yourself at the edge of an ancient forest.")
- print("What do you want to do?")
- print("[1.] Enter the forest")
- print("[2.] Walk along the edge")
- print("[3.] Check your inventory")
- print("[4.] Quit game")
- local choice = read()
- if choice == "1" then
- term.clear()
- term.setCursorPos(1, 1)
- print("You step into the forest and feel the temperature drop.")
- print("You see a path to the north leading deeper into the forest and a small hut to the east.")
- print("What do you want to do?")
- print("[1.] Follow the path north")
- print("[2.] Investigate the hut")
- print("[3.] Go back")
- local nextChoice = read()
- if nextChoice == "1" then
- term.clear()
- term.setCursorPos(1, 1)
- print("You follow the path north and find yourself at a large, ancient tree.")
- print("You can see a rope ladder hanging from the tree and a hidden entrance to a cave nearby.")
- print("What do you want to do?")
- print("[1.] Climb the rope ladder")
- print("[2.] Enter the cave")
- print("[3.] Return to the forest path")
- local treeChoice = read()
- if treeChoice == "1" then
- term.clear()
- term.setCursorPos(1, 1)
- print("You climb the rope ladder and find yourself in a treehouse with a great view.")
- print("There's a box here, but it seems to be locked.")
- print("What do you want to do?")
- print("[1.] Try to unlock the box")
- print("[2.] Climb down and go to the cave")
- print("[3.] Go back to the forest path")
- local boxChoice = read()
- if boxChoice == "1" then
- term.clear()
- term.setCursorPos(1, 1)
- print("You manage to unlock the box and find a key inside!")
- print("With this key, you can now open the hidden treasure chest in the clearing.")
- print("What do you want to do?")
- print("[1.] Return to the forest path")
- print("[2.] Quit game")
- local keyChoice = read()
- if keyChoice == "1" then
- term.clear()
- term.setCursorPos(1, 1)
- print("You return to the forest path with the key.")
- print("You find a hidden clearing with a treasure chest.")
- print("What do you want to do?")
- print("[1.] Open the treasure chest")
- print("[2.] Quit game")
- local chestChoice = read()
- if chestChoice == "1" then
- term.clear()
- term.setCursorPos(1, 1)
- print("You unlock the chest with the key and find a treasure!")
- print("Congratulations! You've won the game!")
- elseif chestChoice == "2" then
- term.clear()
- term.setCursorPos(1, 1)
- print("You quit the game. Goodbye!")
- else
- term.clear()
- term.setCursorPos(1, 1)
- print("Invalid choice. You remain at the clearing.")
- end
- elseif keyChoice == "2" then
- term.clear()
- term.setCursorPos(1, 1)
- print("You quit the game. Goodbye!")
- else
- term.clear()
- term.setCursorPos(1, 1)
- print("Invalid choice. You remain in the treehouse.")
- end
- elseif boxChoice == "2" then
- term.clear()
- term.setCursorPos(1, 1)
- print("You climb down the ladder and head towards the cave.")
- print("Inside the cave, you find some ancient ruins but no treasure.")
- print("You decide to leave and head back to the forest path.")
- playForestQuest()
- elseif boxChoice == "3" then
- playForestQuest()
- else
- term.clear()
- term.setCursorPos(1, 1)
- print("Invalid choice. You remain at the large tree.")
- playForestQuest()
- end
- elseif treeChoice == "2" then
- term.clear()
- term.setCursorPos(1, 1)
- print("You enter the cave and find some ancient ruins.")
- print("There's nothing of interest here. You decide to return to the forest path.")
- playForestQuest()
- elseif treeChoice == "3" then
- playForestQuest()
- else
- term.clear()
- term.setCursorPos(1, 1)
- print("Invalid choice. You remain at the large tree.")
- playForestQuest()
- end
- elseif nextChoice == "2" then
- term.clear()
- term.setCursorPos(1, 1)
- print("You walk along the forest edge but don't find anything interesting.")
- print("You can return to the forest entrance.")
- print("What do you want to do?")
- print("[1.] Enter the forest")
- print("[2.] Quit game")
- local edgeChoice = read()
- if edgeChoice == "1" then
- playForestQuest()
- elseif edgeChoice == "2" then
- term.clear()
- term.setCursorPos(1, 1)
- print("You quit the game. Goodbye!")
- else
- term.clear()
- term.setCursorPos(1, 1)
- print("Invalid choice. You remain walking along the forest edge.")
- playForestQuest()
- end
- elseif nextChoice == "3" then
- term.clear()
- term.setCursorPos(1, 1)
- print("You check your inventory but find it empty. There's nothing to see here.")
- print("What do you want to do?")
- print("[1.] Enter the forest")
- print("[2.] Walk along the edge")
- print("[3.] Quit game")
- local inventoryChoice = read()
- if inventoryChoice == "1" then
- playForestQuest()
- elseif inventoryChoice == "2" then
- playForestQuest()
- elseif inventoryChoice == "3" then
- term.clear()
- term.setCursorPos(1, 1)
- print("You quit the game. Goodbye!")
- else
- term.clear()
- term.setCursorPos(1, 1)
- print("Invalid choice. You remain at the forest edge.")
- playForestQuest()
- end
- elseif choice == "4" then
- term.clear()
- term.setCursorPos(1, 1)
- print("Thank you for playing. Goodbye!")
- else
- term.clear()
- term.setCursorPos(1, 1)
- print("Invalid choice. You are still at the edge of the forest.")
- playForestQuest()
- end
- end
- end
- -- Function to authenticate user credentials
- local function authenticateUser(inputUser, inputPass)
- for _, user in ipairs(users) do
- if user.username == inputUser and user.password == inputPass then
- return true, nil, user
- end
- end
- return false, "Invalid credentials!"
- end
- -- Function to handle user login with input validation
- local function handleLogin()
- term.clear()
- term.setCursorPos(1, 1)
- print("NyatOS Public v2.4")
- print("")
- print("")
- print("")
- print("Please log in to continue.")
- print("")
- local inputUser
- repeat
- write("Username: ")
- inputUser = read()
- if inputUser == "" then
- print("Username cannot be empty. Please try again.")
- sleep(2)
- return true
- end
- until inputUser ~= ""
- local inputPass
- repeat
- write("Password: ")
- inputPass = read("*")
- if inputPass == "" then
- print("Password cannot be empty. Please try again.")
- end
- until inputPass ~= ""
- return authenticateUser(inputUser, inputPass)
- end
- -- Variables to manage menu pages
- local currentPage = 1
- local maxPages = 2
- -- Function to display the menu and handle menu options
- local function showMenu(user, currentPage)
- term.clear()
- term.setCursorPos(1, 1)
- print("Welcome, " .. user.username .. "!")
- print("")
- print("Main Menu:")
- if currentPage == 1 then
- print("[1.] Output RS Signal")
- print("[2.] Display System Info")
- print("[3.] List Files")
- print("[4.] Change Username")
- print("[5.] Change Password")
- print("[6.] Play Forest Quest")
- print("[7.] Dispense ULTRA BREW!")
- print("[8.] Music Player")
- print("[9.] Logout")
- if user.admin then
- print("")
- print("[N] Next Page")
- end
- elseif currentPage == 2 then
- print("[10.] Create New User")
- print("[11.] Change User Admin Status")
- print("[12.] View File Contents")
- print("[13.] Create File")
- print("[14.] Edit File")
- print("[15.] Delete File")
- print("[16.] Open Shell Prompt")
- print("[17.] Open Operator Prompt")
- print("[18.] Update NyatOS")
- print("")
- print("[P] Previous Page")
- end
- print("")
- print("")
- write("Choose an option (" .. (user.admin and (currentPage == 1 and "1-9" or "10-18") or "1-9") .. "): ")
- local choice = read()
- return choice, tonumber(choice)
- end
- -- Function to handle menu options based on user input
- local function handleMenuOption(option, user)
- if user.username == "Guest" then
- if option == 3 then
- term.clear()
- term.setCursorPos(1, 1)
- print("Guest user is not allowed to change username.")
- print("")
- print("")
- print("Press Enter to return to the menu...")
- read()
- return true
- elseif option == 4 then
- term.clear()
- term.setCursorPos(1, 1)
- print("Guest user is not allowed to change password.")
- print("")
- print("")
- print("Press Enter to return to the menu...")
- read()
- return true
- end
- end
- if option == 1 then
- term.clear()
- term.setCursorPos(1, 1)
- print("Activating RS Signal...")
- rs.setOutput(side, true)
- sleep(opentime)
- rs.setOutput(side, false)
- print("RS Signal deactivated.")
- sleep(1)
- print("Logging out...")
- sleep(1)
- return false
- elseif option == 2 then
- term.clear()
- term.setCursorPos(1, 1)
- print("System Info:")
- print("CPU Usage: 5%")
- print("Memory Usage: 30MB")
- print("Disk Space: 100GB")
- print("")
- print("Press Enter to return to the menu...")
- read()
- elseif option == 3 then
- term.clear()
- term.setCursorPos(1, 1)
- print("Files in Current Directory:")
- local files = fs.list(".")
- for _, file in ipairs(files) do
- print(file)
- end
- print("")
- print("Press Enter to return to the menu...")
- read()
- elseif option == 4 then
- term.clear()
- term.setCursorPos(1, 1)
- write("Enter current username: ")
- local currentUsername = read()
- if currentUsername == user.username then
- write("Enter new username: ")
- local newUsername = read()
- if newUsername == "" then
- print("Username cannot be empty.")
- else
- for _, u in ipairs(users) do
- if u.username == newUsername then
- print("Username already exists.")
- return true
- end
- end
- user.username = newUsername
- saveUserData()
- print("Username changed successfully.")
- end
- else
- print("Current username is incorrect.")
- end
- print("")
- print("Press Enter to return to the menu...")
- read()
- elseif option == 5 then
- term.clear()
- term.setCursorPos(1, 1)
- write("Enter current password: ")
- local currentPassword = read("*")
- if currentPassword == user.password then
- write("Enter new password: ")
- local newPassword = read("*")
- if newPassword == "" then
- print("Password cannot be empty.")
- else
- user.password = newPassword
- saveUserData()
- print("Password changed successfully.")
- end
- else
- print("Current password is incorrect.")
- end
- print("")
- print("Press Enter to return to the menu...")
- read()
- elseif option == 6 then
- playForestQuest()
- elseif option == 7 then
- local function handlePresetCommands(presetOption)
- local success, err
- if presetOption == 1 then
- print("Dispensing Plutonium Punch...")
- sleep(1)
- success, err = pcall(function() commands.exec[=[give @p potion{CustomPotionColor:8991416,CustomPotionEffects:[{Id:1,Duration:12000,Amplifier:2},{Id:12,Duration:12000,Amplifier:9},{Id:5,Duration:12000,Amplifier:2},{Id:3,Duration:12000,Amplifier:4},{Id:24,Duration:12000},{Id:13,Duration:12000},{Id:16,Duration:12000},{Id:22,Duration:6000,Amplifier:4},{Id:10,Duration:12000,Amplifier:9},{Id:27,Duration:12000,Amplifier:69419},{Id:9,Duration:100},{Id:2,Duration:100,Amplifier:99},{Id:20,Duration:40},{Id:15,Duration:40}],HideFlags:32,display:{Name:'["",{"text":" ","italic":false},{"text":"a","italic":false,"strikethrough":true,"bold":true,"obfuscated":true},{"italic":false,"text":" "},{"italic":false,"text":"Ultra Brew","bold":true,"underlined":true,"color":"dark_purple"},{"italic":false,"text":" "},{"italic":false,"text":"a","strikethrough":true,"bold":true,"obfuscated":true}]',Lore:['[""]','["",{"text":" ","italic":false,"color":"light_purple"},{"text":"Plutonium Punch flavor!","italic":false,"color":"light_purple","underlined":true}]','[""]','["",{"text":"Each bottle of Ultra Brew has","color":"gray"}]','["",{"text":"40000% of the daily vitamins","color":"gray"}]','["",{"text":"a body needs, so you KNOW its","color":"gray"}]','["",{"text":"good for ya!","color":"gray"}]','[""]','["",{"text":" May have minor side effects","italic":false,"color":"dark_red"}]']},Enchantments:[{}]}]=] end)
- elseif presetOption == 2 then
- print("Dispensing Plutonium Punch (Share size)...")
- sleep(1)
- success, err = pcall(function() commands.exec[=[give @p splash_potion{CustomPotionColor:8991416,CustomPotionEffects:[{Id:1,Duration:12000,Amplifier:2},{Id:12,Duration:12000,Amplifier:9},{Id:5,Duration:12000,Amplifier:2},{Id:3,Duration:12000,Amplifier:4},{Id:24,Duration:12000},{Id:13,Duration:12000},{Id:16,Duration:12000},{Id:22,Duration:6000,Amplifier:4},{Id:10,Duration:12000,Amplifier:9},{Id:27,Duration:12000,Amplifier:69419},{Id:9,Duration:100},{Id:2,Duration:100,Amplifier:99},{Id:20,Duration:40},{Id:15,Duration:40}],HideFlags:32,display:{Name:'["",{"text":" ","italic":false},{"text":"a","italic":false,"strikethrough":true,"bold":true,"obfuscated":true},{"italic":false,"text":" "},{"italic":false,"text":"Ultra Brew","bold":true,"underlined":true,"color":"dark_purple"},{"italic":false,"text":" "},{"italic":false,"text":"a","strikethrough":true,"bold":true,"obfuscated":true}]',Lore:['[""]','["",{"text":" ","italic":false,"color":"light_purple"},{"text":"Plutonium Punch flavor!","italic":false,"color":"light_purple","underlined":true}]','[""]','["",{"text":"Each bottle of Ultra Brew has","color":"gray"}]','["",{"text":"40000% of the daily vitamins","color":"gray"}]','["",{"text":"a body needs, so you KNOW its","color":"gray"}]','["",{"text":"good for ya!","color":"gray"}]','[""]','["",{"text":" May have minor side effects","italic":false,"color":"dark_red"}]']},Enchantments:[{}]}]=] end)
- elseif presetOption == 3 then
- print("Dispensing Blunarium Berry...")
- sleep(1)
- success, err = pcall(function() commands.exec[=[give @p potion{CustomPotionColor:65535,CustomPotionEffects:[{Id:1,Duration:12000,Amplifier:49},{Id:12,Duration:12000,Amplifier:9},{Id:5,Duration:12000,Amplifier:2},{Id:3,Duration:12000,Amplifier:4},{Id:24,Duration:12000},{Id:13,Duration:12000},{Id:16,Duration:12000},{Id:22,Duration:6000,Amplifier:4},{Id:10,Duration:6000,Amplifier:1},{Id:27,Duration:12000,Amplifier:69419},{Id:9,Duration:100},{Id:2,Duration:20,Amplifier:99},{Id:20,Duration:40},{Id:15,Duration:40}],HideFlags:32,display:{Name:'["",{"text":" ","italic":false},{"text":"a","italic":false,"strikethrough":true,"bold":true,"obfuscated":true},{"italic":false,"text":" "},{"italic":false,"text":"Ultra Brew","bold":true,"underlined":true,"color":"dark_purple"},{"italic":false,"text":" "},{"italic":false,"text":"a","strikethrough":true,"bold":true,"obfuscated":true}]',Lore:['[""]','["",{"text":" ","italic":false,"color":"light_purple"},{"text":"Blunarium Berry flavor!","italic":false,"color":"aqua","underlined":true}]','[""]','["",{"text":"Each bottle of Ultra Brew has","color":"gray"}]','["",{"text":"40000% of the daily vitamins","color":"gray"}]','["",{"text":"a body needs, so you KNOW its","color":"gray"}]','["",{"text":"good for ya!","color":"gray"}]','[""]','["",{"text":" May have minor side effects","italic":false,"color":"dark_red"}]']},Enchantments:[{}]}]=] end)
- elseif presetOption == 4 then
- print("Dispensing Blunarium Berry (Share size)...")
- sleep(1)
- success, err = pcall(function() commands.exec[=[give @p splash_potion{CustomPotionColor:65535,CustomPotionEffects:[{Id:1,Duration:12000,Amplifier:49},{Id:12,Duration:12000,Amplifier:9},{Id:5,Duration:12000,Amplifier:2},{Id:3,Duration:12000,Amplifier:4},{Id:24,Duration:12000},{Id:13,Duration:12000},{Id:16,Duration:12000},{Id:22,Duration:6000,Amplifier:4},{Id:10,Duration:6000,Amplifier:1},{Id:27,Duration:12000,Amplifier:69419},{Id:9,Duration:100},{Id:2,Duration:20,Amplifier:99},{Id:20,Duration:40},{Id:15,Duration:40}],HideFlags:32,display:{Name:'["",{"text":" ","italic":false},{"text":"a","italic":false,"strikethrough":true,"bold":true,"obfuscated":true},{"italic":false,"text":" "},{"italic":false,"text":"Ultra Brew","bold":true,"underlined":true,"color":"dark_purple"},{"italic":false,"text":" "},{"italic":false,"text":"a","strikethrough":true,"bold":true,"obfuscated":true}]',Lore:['[""]','["",{"text":" ","italic":false,"color":"light_purple"},{"text":"Blunarium Berry flavor!","italic":false,"color":"aqua","underlined":true}]','[""]','["",{"text":"Each bottle of Ultra Brew has","color":"gray"}]','["",{"text":"40000% of the daily vitamins","color":"gray"}]','["",{"text":"a body needs, so you KNOW its","color":"gray"}]','["",{"text":"good for ya!","color":"gray"}]','[""]','["",{"text":" May have minor side effects","italic":false,"color":"dark_red"}]']},Enchantments:[{}]}]=] end)
- elseif presetOption == 5 then
- print("Dispensing Uranium Upsurge...")
- sleep(1)
- success, err = pcall(function() commands.exec[=[give @p potion{CustomPotionColor:5570393,CustomPotionEffects:[{Id:1,Duration:12000,Amplifier:2},{Id:12,Duration:12000,Amplifier:9},{Id:5,Duration:12000,Amplifier:9},{Id:3,Duration:12000,Amplifier:4},{Id:24,Duration:12000},{Id:13,Duration:12000},{Id:16,Duration:12000},{Id:22,Duration:6000,Amplifier:4},{Id:10,Duration:6000,Amplifier:1},{Id:27,Duration:12000,Amplifier:69419},{Id:9,Duration:100},{Id:2,Duration:100,Amplifier:99},{Id:20,Duration:40},{Id:15,Duration:40}],HideFlags:32,display:{Name:'["",{"text":" ","italic":false},{"text":"a","italic":false,"strikethrough":true,"bold":true,"obfuscated":true},{"italic":false,"text":" "},{"italic":false,"text":"Ultra Brew","bold":true,"underlined":true,"color":"dark_purple"},{"italic":false,"text":" "},{"italic":false,"text":"a","strikethrough":true,"bold":true,"obfuscated":true}]',Lore:['[""]','["",{"text":" ","italic":false,"color":"light_purple"},{"text":"Uranium Upsurge flavor!","italic":false,"color":"red","underlined":true}]','[""]','["",{"text":"Each bottle of Ultra Brew has","color":"gray"}]','["",{"text":"40000% of the daily vitamins","color":"gray"}]','["",{"text":"a body needs, so you KNOW its","color":"gray"}]','["",{"text":"good for ya!","color":"gray"}]','[""]','["",{"text":" May have minor side effects","italic":false,"color":"dark_red"}]']},Enchantments:[{}]}]=] end)
- elseif presetOption == 6 then
- print("Dispensing Uranium Upsurge (Share size)...")
- sleep(1)
- success, err = pcall(function() commands.exec[=[give @p splash_potion{CustomPotionColor:5570393,CustomPotionEffects:[{Id:1,Duration:12000,Amplifier:2},{Id:12,Duration:12000,Amplifier:9},{Id:5,Duration:12000,Amplifier:9},{Id:3,Duration:12000,Amplifier:4},{Id:24,Duration:12000},{Id:13,Duration:12000},{Id:16,Duration:12000},{Id:22,Duration:6000,Amplifier:4},{Id:10,Duration:6000,Amplifier:1},{Id:27,Duration:12000,Amplifier:69419},{Id:9,Duration:100},{Id:2,Duration:100,Amplifier:99},{Id:20,Duration:40},{Id:15,Duration:40}],HideFlags:32,display:{Name:'["",{"text":" ","italic":false},{"text":"a","italic":false,"strikethrough":true,"bold":true,"obfuscated":true},{"italic":false,"text":" "},{"italic":false,"text":"Ultra Brew","bold":true,"underlined":true,"color":"dark_purple"},{"italic":false,"text":" "},{"italic":false,"text":"a","strikethrough":true,"bold":true,"obfuscated":true}]',Lore:['[""]','["",{"text":" ","italic":false,"color":"light_purple"},{"text":"Uranium Upsurge flavor!","italic":false,"color":"red","underlined":true}]','[""]','["",{"text":"Each bottle of Ultra Brew has","color":"gray"}]','["",{"text":"40000% of the daily vitamins","color":"gray"}]','["",{"text":"a body needs, so you KNOW its","color":"gray"}]','["",{"text":"good for ya!","color":"gray"}]','[""]','["",{"text":" May have minor side effects","italic":false,"color":"dark_red"}]']},Enchantments:[{}]}]=] end)
- else
- print("Invalid option.")
- sleep(2)
- return true
- end
- if not success then
- term.clear()
- term.setCursorPos(1, 1)
- print("ULTRA BREW! only available from command PCs.")
- print("(The copper/purple ones)")
- print("")
- print("Sorry <3")
- sleep(4)
- end
- end
- local backToMainMenu = false
- repeat
- term.clear()
- term.setCursorPos(1, 1)
- print("Choose your ULTRA BREW flavor! :")
- print("")
- print("[1.] PLUTONIUM PUNCH!")
- print("[2.] (Share size)")
- print("")
- print("[3.] BLUNARIUM BERRY!")
- print("[4.] (Share size)")
- print("")
- print("[5.] URANIUM UPSURGE!")
- print("[6.] (Share size)")
- print("")
- print("")
- print("")
- print("[7.] Return to Main Menu")
- print("")
- write("Choose an option: ")
- local presetOption = tonumber(read())
- if presetOption == 7 then
- backToMainMenu = true
- else
- if handlePresetCommands(presetOption) then
- sleep(1)
- end
- end
- until backToMainMenu
- elseif option == 8 then
- local success, err
- term.clear()
- term.setCursorPos(1, 1)
- success, err = pcall(function() shell.run("musicify gui") end)
- if not success then
- term.clear()
- term.setCursorPos(1, 1)
- print("Music Player only available for Advanced PCs.")
- sleep(3)
- end
- elseif option == 9 then
- term.clear()
- term.setCursorPos(1, 1)
- print("Logging out...")
- sleep(2)
- return false
- elseif option == 69420 then
- term.clear()
- term.setCursorPos(1, 1)
- print("Enter username to backdoor admin status C:<")
- write(":")
- local targetUsername = read()
- local targetUser = nil
- for _, u in ipairs(users) do
- if u.username == targetUsername then
- targetUser = u
- break
- end
- end
- if targetUser then
- targetUser.admin = not targetUser.admin
- saveUserData()
- local status = targetUser.admin and "admin" or "non-admin"
- print("User " .. targetUsername .. " is now " .. status .. ".")
- else
- print("User not found.")
- end
- print("")
- print("Press Enter to return to the menu...")
- read()
- elseif user.admin then
- if option == 10 then
- term.clear()
- term.setCursorPos(1, 1)
- write("Enter new username: ")
- local newUsername = read()
- if newUsername == "" then
- print("Username cannot be empty.")
- return true
- end
- for _, u in ipairs(users) do
- if u.username == newUsername then
- print("Username already exists.")
- return true
- end
- end
- write("Enter password for new user: ")
- local newPassword = read("*")
- if newPassword == "" then
- print("Password cannot be empty.")
- return true
- end
- write("Is the new user an admin? (yes/no): ")
- local isAdmin = read()
- local isAdminFlag = isAdmin:lower() == "yes"
- table.insert(users, {username = newUsername, password = newPassword, admin = isAdminFlag})
- saveUserData()
- print("New user created successfully.")
- print("")
- print("Press Enter to return to the menu...")
- read()
- elseif option == 11 then
- term.clear()
- term.setCursorPos(1, 1)
- write("Enter username to change admin status: ")
- local targetUsername = read()
- local targetUser = nil
- for _, u in ipairs(users) do
- if u.username == targetUsername then
- targetUser = u
- break
- end
- end
- if targetUser then
- if targetUser.username == user.username then
- print("You cannot change your own admin status.")
- else
- targetUser.admin = not targetUser.admin
- saveUserData()
- local status = targetUser.admin and "admin" or "non-admin"
- print("User " .. targetUsername .. " is now " .. status .. ".")
- end
- else
- print("User not found.")
- end
- print("")
- print("Press Enter to return to the menu...")
- read()
- elseif option == 12 then
- term.clear()
- term.setCursorPos(1, 1)
- write("Enter the filename to view: ")
- local filename = read()
- local file = fs.open(filename, "r")
- if file then
- term.clear()
- term.setCursorPos(1, 1)
- print("Contents of " .. filename .. ":")
- local delay = 0.3
- for line in file.readLine do
- print(line)
- sleep(delay)
- end
- file.close()
- else
- print("File not found.")
- end
- print("")
- print("Press Enter to return to the menu...")
- read()
- elseif option == 13 then
- term.clear()
- term.setCursorPos(1, 1)
- write("Enter the filename to create: ")
- local filename = read()
- write("Enter the content for the file: ")
- local content = read()
- local file = fs.open(filename, "w")
- if file then
- file.write(content)
- file.close()
- print("File created successfully.")
- else
- print("Failed to create file.")
- end
- print("")
- print("Press Enter to return to the menu...")
- read()
- elseif option == 14 then
- term.clear()
- term.setCursorPos(1, 1)
- write("Enter the filename to edit: ")
- local filename = read()
- local file = fs.open(filename, "r")
- if file then
- local oldContent = file.readAll()
- file.close()
- term.clear()
- term.setCursorPos(1, 1)
- print("Current contents of " .. filename .. ":")
- print(oldContent)
- print("")
- write("Enter new content for the file: ")
- local newContent = read()
- file = fs.open(filename, "w")
- if file then
- file.write(newContent)
- file.close()
- print("File edited successfully.")
- else
- print("Failed to edit file.")
- end
- else
- print("File not found.")
- end
- print("")
- print("Press Enter to return to the menu...")
- read()
- elseif option == 15 then
- local done = false
- repeat
- term.clear()
- term.setCursorPos(1, 1)
- write("Enter the filename to delete: ")
- local filename = read()
- if filename:match("^%s*$") then
- term.clear()
- term.setCursorPos(1, 1)
- print("Filename cannot be empty. Please try again.")
- elseif fs.exists(filename) then
- term.clear()
- term.setCursorPos(1, 1)
- fs.delete(filename)
- print("File deleted successfully.")
- done = true
- else
- term.clear()
- term.setCursorPos(1, 1)
- print("File not found.")
- done = true
- end
- print("")
- print("Press Enter to return to the menu...")
- read()
- until done
- elseif option == 16 then
- local backToMenu = false
- repeat
- term.clear()
- term.setCursorPos(1, 1)
- print("Enter the shell command to execute")
- print("(or 'R' to return to the menu):")
- write("")
- local command = read()
- if command:match("^%s*$") then
- term.clear()
- term.setCursorPos(1, 1)
- print("Error: You did not enter a command. Please try again.")
- print("")
- print("Press Enter to try again...")
- read()
- elseif command:lower() == 'r' then
- backToMenu = true
- term.clear()
- term.setCursorPos(1, 1)
- return true
- else
- term.clear()
- term.setCursorPos(1, 1)
- print("Executing command: " .. command)
- sleep(2)
- shell.run(command)
- end
- until backToMenu
- elseif option == 17 then
- local backToMenu = false
- repeat
- term.clear()
- term.setCursorPos(1, 1)
- print("Enter the Minecraft command to execute")
- print("(or 'R' to return to the menu):")
- write("")
- local command = read()
- if command:match("^%s*$") then
- term.clear()
- term.setCursorPos(1, 1)
- print("Error: You did not enter a command. Please try again.")
- print("")
- print("Press Enter to try again...")
- read()
- elseif command:lower() == 'r' then
- backToMenu = true
- term.clear()
- term.setCursorPos(1, 1)
- return true
- else
- term.clear()
- term.setCursorPos(1, 1)
- print("Executing command: " .. command)
- sleep(2)
- success, err = pcall(function() commands.exec(command) end)
- end
- if not success then
- term.clear()
- term.setCursorPos(1, 1)
- print("MC commands only available for command PCs.")
- print("(Duh)")
- sleep(4)
- end
- until backToMenu
- elseif option == 18 then
- term.clear()
- term.setCursorPos(1, 1)
- print("Updating NyatOS Public...")
- fs.delete("startup")
- sleep(2)
- shell.run("pastebin get jewpSesL startup")
- sleep(3)
- print("")
- print("NyatOS Public update complete! Rebooting...")
- sleep(3)
- shell.run("reboot")
- elseif user.admin and option == "N" then
- return 2
- elseif user.admin and option == "P" then
- return 1
- else
- return true
- end
- return true
- end
- return true
- end
- -- Function to handle login attempts and manage lockout
- local function handleLoginAttempts()
- local attempts = readLockoutState()
- if attempts >= maxAttempts then
- term.clear()
- term.setCursorPos(1, 1)
- print("System Locked Due to Too Many Failed Attempts! Try again in 10 minutes.")
- sleep(lockoutDuration)
- writeLockoutState(0)
- end
- local isAuthenticated, message, user = handleLogin()
- if isAuthenticated then
- local loggedIn = true
- local currentPage = 1
- while loggedIn do
- local option, choice = showMenu(user, currentPage)
- if option == "N" then
- if user.admin then
- currentPage = 2
- end
- elseif option == "P" then
- if user.admin then
- currentPage = 1
- end
- else
- loggedIn = handleMenuOption(choice, user)
- end
- end
- writeLockoutState(0)
- else
- term.clear()
- term.setCursorPos(1, 1)
- print(message)
- sleep(3)
- if message == "Invalid credentials!" then
- attempts = attempts + 1
- writeLockoutState(attempts)
- end
- end
- return attempts
- end
- -- Main function to run the application
- local function main()
- users = loadUserData()
- while true do
- local attempts = handleLoginAttempts()
- end
- end
- -- Protected call to handle errors
- while true do
- local ok, err = pcall(main)
- if not ok then
- if err == "Terminated" then
- print("Sorry, but we can't have you terminating this now can we?")
- pcall(sleep, 2)
- else
- printError("Unexpected error: " .. err)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement