Advertisement
Catboy_Riku

General NyatOS

Aug 22nd, 2024 (edited)
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.74 KB | None | 0 0
  1. local side = "back"
  2. local opentime = 5
  3. local userFile = "users.dat"
  4. local maxAttempts = 3
  5. local lockoutFile = "lockout.dat"
  6. local lockoutDuration = 600
  7.  
  8. -- User data
  9. local users = {
  10. {username = "Riku", password = "1111", admin = true},
  11. --Yo a little help here!?... Alright alright I got it, stand back son.. One, one, one, uhhmmmuhhhhh one!
  12. {username = "Guest", password = "$pass42", admin = false},
  13. }
  14.  
  15. -- Function to read the lockout state from the file
  16. local function readLockoutState()
  17. local file, err = fs.open(lockoutFile, "r")
  18. if file then
  19. local state = file.readAll()
  20. file.close()
  21. return tonumber(state) or 0
  22. else
  23. print("Error reading lockout file:", err)
  24. return 0
  25. end
  26. end
  27.  
  28. -- Function to write the lockout state to the file
  29. local function writeLockoutState(attempts)
  30. local file, err = fs.open(lockoutFile, "w")
  31. if file then
  32. file.write(tostring(attempts))
  33. file.close()
  34. else
  35. print("Error writing to lockout file:", err)
  36. end
  37. end
  38.  
  39. -- Function to load user data from file
  40. local function loadUserData()
  41. local file, err = fs.open(userFile, "r")
  42. if file then
  43. local data = file.readAll()
  44. file.close()
  45. return textutils.unserialize(data) or users
  46. else
  47. print("Error reading user file:", err)
  48. return users
  49. end
  50. end
  51.  
  52. -- Function to save user data to file
  53. local function saveUserData()
  54. local file, err = fs.open(userFile, "w")
  55. if file then
  56. file.write(textutils.serialize(users))
  57. file.close()
  58. else
  59. print("Error writing to user file:", err)
  60. end
  61. end
  62.  
  63. -- Forest Quest Code
  64. local function playForestQuest()
  65. term.clear()
  66. term.setCursorPos(1, 1)
  67. print("Welcome to Forest Quest!")
  68. print("You find yourself at the edge of an ancient forest.")
  69. print("What do you want to do?")
  70. print("[1.] Enter the forest")
  71. print("[2.] Walk along the edge")
  72. print("[3.] Check your inventory")
  73. print("[4.] Quit game")
  74.  
  75. local choice = read()
  76.  
  77. if choice == "1" then
  78. term.clear()
  79. term.setCursorPos(1, 1)
  80. print("You step into the forest and feel the temperature drop.")
  81. print("You see a path to the north leading deeper into the forest and a small hut to the east.")
  82. print("What do you want to do?")
  83. print("[1.] Follow the path north")
  84. print("[2.] Investigate the hut")
  85. print("[3.] Go back")
  86. local nextChoice = read()
  87. if nextChoice == "1" then
  88. term.clear()
  89. term.setCursorPos(1, 1)
  90. print("You follow the path north and find yourself at a large, ancient tree.")
  91. print("You can see a rope ladder hanging from the tree and a hidden entrance to a cave nearby.")
  92. print("What do you want to do?")
  93. print("[1.] Climb the rope ladder")
  94. print("[2.] Enter the cave")
  95. print("[3.] Return to the forest path")
  96. local treeChoice = read()
  97. if treeChoice == "1" then
  98. term.clear()
  99. term.setCursorPos(1, 1)
  100. print("You climb the rope ladder and find yourself in a treehouse with a great view.")
  101. print("There's a box here, but it seems to be locked.")
  102. print("What do you want to do?")
  103. print("[1.] Try to unlock the box")
  104. print("[2.] Climb down and go to the cave")
  105. print("[3.] Go back to the forest path")
  106. local boxChoice = read()
  107. if boxChoice == "1" then
  108. term.clear()
  109. term.setCursorPos(1, 1)
  110. print("You manage to unlock the box and find a key inside!")
  111. print("With this key, you can now open the hidden treasure chest in the clearing.")
  112. print("What do you want to do?")
  113. print("[1.] Return to the forest path")
  114. print("[2.] Quit game")
  115. local keyChoice = read()
  116. if keyChoice == "1" then
  117. term.clear()
  118. term.setCursorPos(1, 1)
  119. print("You return to the forest path with the key.")
  120. print("You find a hidden clearing with a treasure chest.")
  121. print("What do you want to do?")
  122. print("[1.] Open the treasure chest")
  123. print("[2.] Quit game")
  124. local chestChoice = read()
  125. if chestChoice == "1" then
  126. term.clear()
  127. term.setCursorPos(1, 1)
  128. print("You unlock the chest with the key and find a treasure!")
  129. print("Congratulations! You've won the game!")
  130. elseif chestChoice == "2" then
  131. term.clear()
  132. term.setCursorPos(1, 1)
  133. print("You quit the game. Goodbye!")
  134. else
  135. term.clear()
  136. term.setCursorPos(1, 1)
  137. print("Invalid choice. You remain at the clearing.")
  138. end
  139. elseif keyChoice == "2" then
  140. term.clear()
  141. term.setCursorPos(1, 1)
  142. print("You quit the game. Goodbye!")
  143. else
  144. term.clear()
  145. term.setCursorPos(1, 1)
  146. print("Invalid choice. You remain in the treehouse.")
  147. end
  148. elseif boxChoice == "2" then
  149. term.clear()
  150. term.setCursorPos(1, 1)
  151. print("You climb down the ladder and head towards the cave.")
  152. print("Inside the cave, you find some ancient ruins but no treasure.")
  153. print("You decide to leave and head back to the forest path.")
  154. playForestQuest()
  155. elseif boxChoice == "3" then
  156. playForestQuest()
  157. else
  158. term.clear()
  159. term.setCursorPos(1, 1)
  160. print("Invalid choice. You remain at the large tree.")
  161. playForestQuest()
  162. end
  163. elseif treeChoice == "2" then
  164. term.clear()
  165. term.setCursorPos(1, 1)
  166. print("You enter the cave and find some ancient ruins.")
  167. print("There's nothing of interest here. You decide to return to the forest path.")
  168. playForestQuest()
  169. elseif treeChoice == "3" then
  170. playForestQuest()
  171. else
  172. term.clear()
  173. term.setCursorPos(1, 1)
  174. print("Invalid choice. You remain at the large tree.")
  175. playForestQuest()
  176. end
  177. elseif nextChoice == "2" then
  178. term.clear()
  179. term.setCursorPos(1, 1)
  180. print("You walk along the forest edge but don't find anything interesting.")
  181. print("You can return to the forest entrance.")
  182. print("What do you want to do?")
  183. print("[1.] Enter the forest")
  184. print("[2.] Quit game")
  185. local edgeChoice = read()
  186. if edgeChoice == "1" then
  187. playForestQuest()
  188. elseif edgeChoice == "2" then
  189. term.clear()
  190. term.setCursorPos(1, 1)
  191. print("You quit the game. Goodbye!")
  192. else
  193. term.clear()
  194. term.setCursorPos(1, 1)
  195. print("Invalid choice. You remain walking along the forest edge.")
  196. playForestQuest()
  197. end
  198. elseif nextChoice == "3" then
  199. term.clear()
  200. term.setCursorPos(1, 1)
  201. print("You check your inventory but find it empty. There's nothing to see here.")
  202. print("What do you want to do?")
  203. print("[1.] Enter the forest")
  204. print("[2.] Walk along the edge")
  205. print("[3.] Quit game")
  206. local inventoryChoice = read()
  207. if inventoryChoice == "1" then
  208. playForestQuest()
  209. elseif inventoryChoice == "2" then
  210. playForestQuest()
  211. elseif inventoryChoice == "3" then
  212. term.clear()
  213. term.setCursorPos(1, 1)
  214. print("You quit the game. Goodbye!")
  215. else
  216. term.clear()
  217. term.setCursorPos(1, 1)
  218. print("Invalid choice. You remain at the forest edge.")
  219. playForestQuest()
  220. end
  221. elseif choice == "4" then
  222. term.clear()
  223. term.setCursorPos(1, 1)
  224. print("Thank you for playing. Goodbye!")
  225. else
  226. term.clear()
  227. term.setCursorPos(1, 1)
  228. print("Invalid choice. You are still at the edge of the forest.")
  229. playForestQuest()
  230. end
  231. end
  232. end
  233.  
  234. -- Function to authenticate user credentials
  235. local function authenticateUser(inputUser, inputPass)
  236. for _, user in ipairs(users) do
  237. if user.username == inputUser and user.password == inputPass then
  238. return true, nil, user
  239. end
  240. end
  241. return false, "Invalid credentials!"
  242. end
  243.  
  244. -- Function to handle user login with input validation
  245. local function handleLogin()
  246. term.clear()
  247. term.setCursorPos(1, 1)
  248. print("NyatOS Public v2.4")
  249. print("")
  250. print("")
  251. print("")
  252. print("Please log in to continue.")
  253. print("")
  254.  
  255. local inputUser
  256. repeat
  257. write("Username: ")
  258. inputUser = read()
  259. if inputUser == "" then
  260. print("Username cannot be empty. Please try again.")
  261. sleep(2)
  262. return true
  263. end
  264. until inputUser ~= ""
  265.  
  266. local inputPass
  267. repeat
  268. write("Password: ")
  269. inputPass = read("*")
  270. if inputPass == "" then
  271. print("Password cannot be empty. Please try again.")
  272. end
  273. until inputPass ~= ""
  274.  
  275. return authenticateUser(inputUser, inputPass)
  276. end
  277.  
  278. -- Variables to manage menu pages
  279. local currentPage = 1
  280. local maxPages = 2
  281.  
  282. -- Function to display the menu and handle menu options
  283. local function showMenu(user, currentPage)
  284. term.clear()
  285. term.setCursorPos(1, 1)
  286. print("Welcome, " .. user.username .. "!")
  287. print("")
  288. print("Main Menu:")
  289.  
  290. if currentPage == 1 then
  291. print("[1.] Output RS Signal")
  292. print("[2.] Display System Info")
  293. print("[3.] List Files")
  294. print("[4.] Change Username")
  295. print("[5.] Change Password")
  296. print("[6.] Play Forest Quest")
  297. print("[7.] Dispense ULTRA BREW!")
  298. print("[8.] Music Player")
  299. print("[9.] Logout")
  300. if user.admin then
  301. print("")
  302. print("[N] Next Page")
  303. end
  304. elseif currentPage == 2 then
  305. print("[10.] Create New User")
  306. print("[11.] Change User Admin Status")
  307. print("[12.] View File Contents")
  308. print("[13.] Create File")
  309. print("[14.] Edit File")
  310. print("[15.] Delete File")
  311. print("[16.] Open Shell Prompt")
  312. print("[17.] Open Operator Prompt")
  313. print("[18.] Update NyatOS")
  314. print("")
  315. print("[P] Previous Page")
  316. end
  317.  
  318. print("")
  319. print("")
  320. write("Choose an option (" .. (user.admin and (currentPage == 1 and "1-9" or "10-18") or "1-9") .. "): ")
  321. local choice = read()
  322. return choice, tonumber(choice)
  323. end
  324.  
  325. -- Function to handle menu options based on user input
  326. local function handleMenuOption(option, user)
  327. if user.username == "Guest" then
  328. if option == 3 then
  329. term.clear()
  330. term.setCursorPos(1, 1)
  331. print("Guest user is not allowed to change username.")
  332. print("")
  333. print("")
  334. print("Press Enter to return to the menu...")
  335. read()
  336. return true
  337. elseif option == 4 then
  338. term.clear()
  339. term.setCursorPos(1, 1)
  340. print("Guest user is not allowed to change password.")
  341. print("")
  342. print("")
  343. print("Press Enter to return to the menu...")
  344. read()
  345. return true
  346. end
  347. end
  348. if option == 1 then
  349. term.clear()
  350. term.setCursorPos(1, 1)
  351. print("Activating RS Signal...")
  352. rs.setOutput(side, true)
  353. sleep(opentime)
  354. rs.setOutput(side, false)
  355. print("RS Signal deactivated.")
  356. sleep(1)
  357. print("Logging out...")
  358. sleep(1)
  359. return false
  360. elseif option == 2 then
  361. term.clear()
  362. term.setCursorPos(1, 1)
  363. print("System Info:")
  364. print("CPU Usage: 5%")
  365. print("Memory Usage: 30MB")
  366. print("Disk Space: 100GB")
  367. print("")
  368. print("Press Enter to return to the menu...")
  369. read()
  370. elseif option == 3 then
  371. term.clear()
  372. term.setCursorPos(1, 1)
  373. print("Files in Current Directory:")
  374. local files = fs.list(".")
  375. for _, file in ipairs(files) do
  376. print(file)
  377. end
  378. print("")
  379. print("Press Enter to return to the menu...")
  380. read()
  381. elseif option == 4 then
  382. term.clear()
  383. term.setCursorPos(1, 1)
  384. write("Enter current username: ")
  385. local currentUsername = read()
  386.  
  387. if currentUsername == user.username then
  388. write("Enter new username: ")
  389. local newUsername = read()
  390.  
  391. if newUsername == "" then
  392. print("Username cannot be empty.")
  393. else
  394. for _, u in ipairs(users) do
  395. if u.username == newUsername then
  396. print("Username already exists.")
  397. return true
  398. end
  399. end
  400. user.username = newUsername
  401. saveUserData()
  402. print("Username changed successfully.")
  403. end
  404. else
  405. print("Current username is incorrect.")
  406. end
  407.  
  408. print("")
  409. print("Press Enter to return to the menu...")
  410. read()
  411. elseif option == 5 then
  412. term.clear()
  413. term.setCursorPos(1, 1)
  414. write("Enter current password: ")
  415. local currentPassword = read("*")
  416.  
  417. if currentPassword == user.password then
  418. write("Enter new password: ")
  419. local newPassword = read("*")
  420.  
  421. if newPassword == "" then
  422. print("Password cannot be empty.")
  423. else
  424. user.password = newPassword
  425. saveUserData()
  426. print("Password changed successfully.")
  427. end
  428. else
  429. print("Current password is incorrect.")
  430. end
  431.  
  432. print("")
  433. print("Press Enter to return to the menu...")
  434. read()
  435. elseif option == 6 then
  436. playForestQuest()
  437. elseif option == 7 then
  438. local function handlePresetCommands(presetOption)
  439. local success, err
  440.  
  441. if presetOption == 1 then
  442. print("Dispensing Plutonium Punch...")
  443. sleep(1)
  444. 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)
  445. elseif presetOption == 2 then
  446. print("Dispensing Plutonium Punch (Share size)...")
  447. sleep(1)
  448. 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)
  449. elseif presetOption == 3 then
  450. print("Dispensing Blunarium Berry...")
  451. sleep(1)
  452. 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)
  453. elseif presetOption == 4 then
  454. print("Dispensing Blunarium Berry (Share size)...")
  455. sleep(1)
  456. 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)
  457. elseif presetOption == 5 then
  458. print("Dispensing Uranium Upsurge...")
  459. sleep(1)
  460. 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)
  461. elseif presetOption == 6 then
  462. print("Dispensing Uranium Upsurge (Share size)...")
  463. sleep(1)
  464. 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)
  465. else
  466. print("Invalid option.")
  467. sleep(2)
  468. return true
  469. end
  470.  
  471. if not success then
  472. term.clear()
  473. term.setCursorPos(1, 1)
  474. print("ULTRA BREW! only available from command PCs.")
  475. print("(The copper/purple ones)")
  476. print("")
  477. print("Sorry <3")
  478. sleep(4)
  479. end
  480. end
  481.  
  482. local backToMainMenu = false
  483.  
  484. repeat
  485. term.clear()
  486. term.setCursorPos(1, 1)
  487. print("Choose your ULTRA BREW flavor! :")
  488. print("")
  489. print("[1.] PLUTONIUM PUNCH!")
  490. print("[2.] (Share size)")
  491. print("")
  492. print("[3.] BLUNARIUM BERRY!")
  493. print("[4.] (Share size)")
  494. print("")
  495. print("[5.] URANIUM UPSURGE!")
  496. print("[6.] (Share size)")
  497. print("")
  498. print("")
  499. print("")
  500. print("[7.] Return to Main Menu")
  501. print("")
  502. write("Choose an option: ")
  503. local presetOption = tonumber(read())
  504.  
  505. if presetOption == 7 then
  506. backToMainMenu = true
  507. else
  508. if handlePresetCommands(presetOption) then
  509. sleep(1)
  510. end
  511. end
  512. until backToMainMenu
  513. elseif option == 8 then
  514. local success, err
  515. term.clear()
  516. term.setCursorPos(1, 1)
  517. success, err = pcall(function() shell.run("musicify gui") end)
  518. if not success then
  519. term.clear()
  520. term.setCursorPos(1, 1)
  521. print("Music Player only available for Advanced PCs.")
  522. sleep(3)
  523. end
  524. elseif option == 9 then
  525. term.clear()
  526. term.setCursorPos(1, 1)
  527. print("Logging out...")
  528. sleep(2)
  529. return false
  530. elseif option == 69420 then
  531. term.clear()
  532. term.setCursorPos(1, 1)
  533. print("Enter username to backdoor admin status C:<")
  534. write(":")
  535. local targetUsername = read()
  536.  
  537. local targetUser = nil
  538. for _, u in ipairs(users) do
  539. if u.username == targetUsername then
  540. targetUser = u
  541. break
  542. end
  543. end
  544.  
  545. if targetUser then
  546. targetUser.admin = not targetUser.admin
  547. saveUserData()
  548. local status = targetUser.admin and "admin" or "non-admin"
  549. print("User " .. targetUsername .. " is now " .. status .. ".")
  550. else
  551. print("User not found.")
  552. end
  553.  
  554. print("")
  555. print("Press Enter to return to the menu...")
  556. read()
  557. elseif user.admin then
  558. if option == 10 then
  559. term.clear()
  560. term.setCursorPos(1, 1)
  561. write("Enter new username: ")
  562. local newUsername = read()
  563.  
  564. if newUsername == "" then
  565. print("Username cannot be empty.")
  566. return true
  567. end
  568.  
  569. for _, u in ipairs(users) do
  570. if u.username == newUsername then
  571. print("Username already exists.")
  572. return true
  573. end
  574. end
  575.  
  576. write("Enter password for new user: ")
  577. local newPassword = read("*")
  578.  
  579. if newPassword == "" then
  580. print("Password cannot be empty.")
  581. return true
  582. end
  583.  
  584. write("Is the new user an admin? (yes/no): ")
  585. local isAdmin = read()
  586. local isAdminFlag = isAdmin:lower() == "yes"
  587.  
  588. table.insert(users, {username = newUsername, password = newPassword, admin = isAdminFlag})
  589. saveUserData()
  590. print("New user created successfully.")
  591.  
  592. print("")
  593. print("Press Enter to return to the menu...")
  594. read()
  595. elseif option == 11 then
  596. term.clear()
  597. term.setCursorPos(1, 1)
  598. write("Enter username to change admin status: ")
  599. local targetUsername = read()
  600.  
  601. local targetUser = nil
  602. for _, u in ipairs(users) do
  603. if u.username == targetUsername then
  604. targetUser = u
  605. break
  606. end
  607. end
  608.  
  609. if targetUser then
  610. if targetUser.username == user.username then
  611. print("You cannot change your own admin status.")
  612. else
  613. targetUser.admin = not targetUser.admin
  614. saveUserData()
  615. local status = targetUser.admin and "admin" or "non-admin"
  616. print("User " .. targetUsername .. " is now " .. status .. ".")
  617. end
  618. else
  619. print("User not found.")
  620. end
  621.  
  622. print("")
  623. print("Press Enter to return to the menu...")
  624. read()
  625. elseif option == 12 then
  626. term.clear()
  627. term.setCursorPos(1, 1)
  628. write("Enter the filename to view: ")
  629. local filename = read()
  630. local file = fs.open(filename, "r")
  631. if file then
  632. term.clear()
  633. term.setCursorPos(1, 1)
  634. print("Contents of " .. filename .. ":")
  635.  
  636. local delay = 0.3
  637. for line in file.readLine do
  638. print(line)
  639. sleep(delay)
  640. end
  641. file.close()
  642. else
  643. print("File not found.")
  644. end
  645. print("")
  646. print("Press Enter to return to the menu...")
  647. read()
  648. elseif option == 13 then
  649. term.clear()
  650. term.setCursorPos(1, 1)
  651. write("Enter the filename to create: ")
  652. local filename = read()
  653. write("Enter the content for the file: ")
  654. local content = read()
  655. local file = fs.open(filename, "w")
  656. if file then
  657. file.write(content)
  658. file.close()
  659. print("File created successfully.")
  660. else
  661. print("Failed to create file.")
  662. end
  663. print("")
  664. print("Press Enter to return to the menu...")
  665. read()
  666. elseif option == 14 then
  667. term.clear()
  668. term.setCursorPos(1, 1)
  669. write("Enter the filename to edit: ")
  670. local filename = read()
  671. local file = fs.open(filename, "r")
  672. if file then
  673. local oldContent = file.readAll()
  674. file.close()
  675. term.clear()
  676. term.setCursorPos(1, 1)
  677. print("Current contents of " .. filename .. ":")
  678. print(oldContent)
  679. print("")
  680. write("Enter new content for the file: ")
  681. local newContent = read()
  682. file = fs.open(filename, "w")
  683. if file then
  684. file.write(newContent)
  685. file.close()
  686. print("File edited successfully.")
  687. else
  688. print("Failed to edit file.")
  689. end
  690. else
  691. print("File not found.")
  692. end
  693. print("")
  694. print("Press Enter to return to the menu...")
  695. read()
  696. elseif option == 15 then
  697. local done = false
  698.  
  699. repeat
  700. term.clear()
  701. term.setCursorPos(1, 1)
  702. write("Enter the filename to delete: ")
  703. local filename = read()
  704.  
  705. if filename:match("^%s*$") then
  706. term.clear()
  707. term.setCursorPos(1, 1)
  708. print("Filename cannot be empty. Please try again.")
  709. elseif fs.exists(filename) then
  710. term.clear()
  711. term.setCursorPos(1, 1)
  712. fs.delete(filename)
  713. print("File deleted successfully.")
  714. done = true
  715. else
  716. term.clear()
  717. term.setCursorPos(1, 1)
  718. print("File not found.")
  719. done = true
  720. end
  721.  
  722. print("")
  723. print("Press Enter to return to the menu...")
  724. read()
  725. until done
  726. elseif option == 16 then
  727. local backToMenu = false
  728.  
  729. repeat
  730. term.clear()
  731. term.setCursorPos(1, 1)
  732. print("Enter the shell command to execute")
  733. print("(or 'R' to return to the menu):")
  734. write("")
  735. local command = read()
  736.  
  737. if command:match("^%s*$") then
  738. term.clear()
  739. term.setCursorPos(1, 1)
  740. print("Error: You did not enter a command. Please try again.")
  741. print("")
  742. print("Press Enter to try again...")
  743. read()
  744. elseif command:lower() == 'r' then
  745. backToMenu = true
  746. term.clear()
  747. term.setCursorPos(1, 1)
  748. return true
  749. else
  750. term.clear()
  751. term.setCursorPos(1, 1)
  752. print("Executing command: " .. command)
  753. sleep(2)
  754. shell.run(command)
  755. end
  756. until backToMenu
  757.  
  758. elseif option == 17 then
  759. local backToMenu = false
  760.  
  761. repeat
  762. term.clear()
  763. term.setCursorPos(1, 1)
  764. print("Enter the Minecraft command to execute")
  765. print("(or 'R' to return to the menu):")
  766. write("")
  767. local command = read()
  768.  
  769. if command:match("^%s*$") then
  770. term.clear()
  771. term.setCursorPos(1, 1)
  772. print("Error: You did not enter a command. Please try again.")
  773. print("")
  774. print("Press Enter to try again...")
  775. read()
  776. elseif command:lower() == 'r' then
  777. backToMenu = true
  778. term.clear()
  779. term.setCursorPos(1, 1)
  780. return true
  781. else
  782. term.clear()
  783. term.setCursorPos(1, 1)
  784. print("Executing command: " .. command)
  785. sleep(2)
  786. success, err = pcall(function() commands.exec(command) end)
  787. end
  788.  
  789. if not success then
  790. term.clear()
  791. term.setCursorPos(1, 1)
  792. print("MC commands only available for command PCs.")
  793. print("(Duh)")
  794. sleep(4)
  795. end
  796. until backToMenu
  797.  
  798. elseif option == 18 then
  799. term.clear()
  800. term.setCursorPos(1, 1)
  801. print("Updating NyatOS Public...")
  802. fs.delete("startup")
  803. sleep(2)
  804. shell.run("pastebin get jewpSesL startup")
  805. sleep(3)
  806. print("")
  807. print("NyatOS Public update complete! Rebooting...")
  808. sleep(3)
  809. shell.run("reboot")
  810. elseif user.admin and option == "N" then
  811. return 2
  812. elseif user.admin and option == "P" then
  813. return 1
  814. else
  815. return true
  816. end
  817. return true
  818. end
  819. return true
  820. end
  821.  
  822. -- Function to handle login attempts and manage lockout
  823. local function handleLoginAttempts()
  824. local attempts = readLockoutState()
  825. if attempts >= maxAttempts then
  826. term.clear()
  827. term.setCursorPos(1, 1)
  828. print("System Locked Due to Too Many Failed Attempts! Try again in 10 minutes.")
  829. sleep(lockoutDuration)
  830. writeLockoutState(0)
  831. end
  832.  
  833. local isAuthenticated, message, user = handleLogin()
  834.  
  835. if isAuthenticated then
  836. local loggedIn = true
  837. local currentPage = 1
  838. while loggedIn do
  839. local option, choice = showMenu(user, currentPage)
  840. if option == "N" then
  841. if user.admin then
  842. currentPage = 2
  843. end
  844. elseif option == "P" then
  845. if user.admin then
  846. currentPage = 1
  847. end
  848. else
  849. loggedIn = handleMenuOption(choice, user)
  850. end
  851. end
  852. writeLockoutState(0)
  853. else
  854. term.clear()
  855. term.setCursorPos(1, 1)
  856. print(message)
  857. sleep(3)
  858. if message == "Invalid credentials!" then
  859. attempts = attempts + 1
  860. writeLockoutState(attempts)
  861. end
  862. end
  863.  
  864. return attempts
  865. end
  866.  
  867. -- Main function to run the application
  868. local function main()
  869.  
  870. users = loadUserData()
  871. while true do
  872. local attempts = handleLoginAttempts()
  873. end
  874. end
  875.  
  876. -- Protected call to handle errors
  877. while true do
  878. local ok, err = pcall(main)
  879.  
  880. if not ok then
  881. if err == "Terminated" then
  882. print("Sorry, but we can't have you terminating this now can we?")
  883. pcall(sleep, 2)
  884. else
  885. printError("Unexpected error: " .. err)
  886. end
  887. end
  888. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement