Advertisement
Guest User

startup.lua

a guest
May 21st, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.67 KB | None | 0 0
  1. local speaker = peripheral.find("speaker")
  2. if fs.exists("govry/") == false then
  3.     fs.makeDir("govry")
  4. end
  5. if speaker then
  6.     sound = speaker.playNote
  7. end
  8. local _defAccounts = {
  9.     { user = 'admin', pass = 'admin', admin = true },
  10.     { user = 'guest', pass = 'guest', admin = false },
  11. }
  12.  
  13. if fs.exists("govry/users/") == false then
  14.     fs.makeDir("govry/users")
  15. end
  16. if fs.exists("govry/accounts.cfg") == false then
  17.     local file = fs.open("govry/accounts.cfg","w")
  18.     file.write(textutils.serialise(_defAccounts))
  19.     file.close()
  20.     file = nil
  21. end
  22. file = fs.open("govry/accounts.cfg","r")
  23. if not file then
  24.   error('Unable to open file')
  25. end
  26. local accounts = {}
  27. local temp = 0
  28. local accounts = textutils.unserialise(file.readAll())
  29. if not accounts then
  30.     accounts = _defAccounts
  31.     fs.delete("govry/accounts.cfg")
  32.     printError("Improperly formated account file!")
  33.     printError()""
  34. end
  35. --local length = fs.getSize("govry/accounts.cfg")
  36. --length is size in bytes / not # lines
  37. --while true do
  38. --    temp = temp + 1
  39. --    line = file.readLine()
  40. --    if not line then break end
  41. --    unline = textutils.unserialise(line)
  42. --    table.insert(accounts, unline)  
  43. --end
  44. term.setPaletteColor(1,0xC9C9FF)
  45. term.setPaletteColor(256,0xB9B9FF)
  46. term.setPaletteColor(32768,0x222299)
  47. term.setPaletteColor(128,0x6666FF)
  48. term.setPaletteColor(32,0x6699AA)
  49. term.setPaletteColor(16384,0x9966AA)
  50. term.setPaletteColor(2,0x000099)
  51. file.close()
  52. term.setBackgroundColor(colors.white)
  53. term.clear()
  54. local width, height = term.getSize()
  55. term.setCursorPos(3,13)
  56. term.setTextColor(colors.gray)
  57. if os.getComputerLabel() ~= nil then
  58.     write("Computer Label: ")
  59.     write(os.getComputerLabel())
  60. else
  61.     term.setTextColor(colors.red)
  62.     write("No Label!")
  63.     term.setTextColor(colors.gray)
  64. end
  65. term.setCursorPos(3,10)
  66. write("Computer ID: ")
  67. write(os.getComputerID())
  68. paintutils.drawFilledBox(1,1,width,3,colors.gray)
  69. paintutils.drawFilledBox(1,height - 3,width,height,colors.gray)
  70. term.setBackgroundColor(colors.white)
  71. term.setTextColor(colors.black)
  72. term.setCursorPos(width - 30, 6)
  73. write("Username")
  74. term.setCursorPos(width - 30, 8)
  75. write("Password")
  76. entry = false
  77. local admin = false
  78. term.setTextColor(colors.gray)
  79. local length = #accounts
  80. function main()
  81. repeat
  82.     paintutils.drawLine(width - 20, 8, width - 1, 8, colors.lightGray)
  83.     paintutils.drawLine(width - 20, 6, width - 1, 6, colors.lightGray)
  84.     term.setCursorPos(width - 20, 6)
  85.     username = read()
  86.     term.setCursorPos(width - 20, 8)
  87.     password = read()
  88.     for id = 1, length do
  89.         if accounts[id].user == username then
  90.             if accounts[id].pass == password then
  91.                 entry = true
  92.                 admin = accounts[id].admin
  93.                 name = accounts[id].user
  94.             end
  95.         end
  96.     end
  97.     if entry == false then
  98.         term.setTextColor(colors.red)
  99.         term.setBackgroundColor(colors.white)
  100.         term.setCursorPos(width - 20, 10)
  101.         write("Login failed!")
  102.         sleep(1)
  103.         term.setCursorPos(width - 20, 10)
  104.         write("             ")
  105.         term.setTextColor(colors.gray)
  106.         term.setBackgroundColor(colors.lightGray)
  107.     end
  108. until entry == true
  109. term.setBackgroundColor(colors.white)
  110. term.setCursorPos(width - 20, 10)
  111. write("Login successful!")
  112. term.setCursorPos(width - 20, 11)
  113. if admin == true then
  114.     term.setTextColor(colors.lime)
  115.     write("Admin")
  116. else
  117.     term.setTextColor(colors.orange)
  118.     write("Normal")
  119. end
  120. write(" account")
  121. sleep(2)
  122. term.setBackgroundColor(colors.white)
  123. term.clear()
  124. if speaker then
  125.     sound("harp",1,5)
  126.     sleep(0.2)
  127.     sound("harp",1,9)
  128.     sleep(0.2)
  129.     sound("harp",1,8)
  130.     sleep(0.2)
  131.     sound("harp",1,6)
  132. end
  133. sleep(0.2)
  134. paintutils.drawFilledBox(1, height - 1, width, height, colors.gray)
  135. local modem = peripheral.find("modem")
  136. term.setCursorPos(width - 4, height)
  137. if modem then
  138.     term.setTextColor(colors.black)
  139.     write("Ooo")
  140. end
  141. local dir = "/"
  142. if fs.exists("govry/users/"..name.."/") == false then
  143.     fs.makeDir("govry/users/"..name)
  144. end
  145. if admin == false then
  146.     dir = "govry/users/"..name.."/"
  147. end
  148. local files = fs.list("govry/users/"..name.."/")
  149. pos = 1
  150. while true do
  151.     term.setTextColor(colors.white)
  152.     for pc = 1, height - 2 do
  153.         term.setCursorPos(2,pc)
  154.         if files[pc] then
  155.             write(files[pc])
  156.         end
  157.     end
  158.     _, m, x, y = os.pullEvent("mouse_click")
  159. end
  160. end
  161. function stop()
  162. while true do
  163.     local ok, msg = pcall(main)
  164.     if not ok then
  165.         term.setCursorBlink(false)
  166.         term.setPaletteColor(32768,0x570000)
  167.         term.setPaletteColor(16384,0xAA0000)
  168.         term.setBackgroundColor(colors.red)
  169.         term.setTextColor(colors.black)
  170.         term.clear()
  171.         term.setCursorPos(2,2)
  172.         write("Uh oh! The system has crashed!")
  173.         term.setCursorPos(2,4)
  174.         write("The error was caused by:")
  175.         term.setCursorPos(1,6)
  176.         write("-"..msg)
  177.         sleep(2)
  178.         term.setCursorPos(2,10)
  179.         write("Rebooting system...")
  180.         sleep(1)
  181.         os.reboot()
  182.     end
  183. end
  184. end
  185. while true do
  186.     local ok, msg = pcall(stop)
  187.     if not ok then
  188.         if admin == true then
  189.             local color = term.setPaletteColor
  190.             color(1,0xF0F0F0)
  191.             color(2,0xF2B223)
  192.             color(32,0x7FCC19)
  193.             color(128,0x4C4C4C)
  194.             color(256,0x999999)
  195.             color(16384,0xCC4C4C)
  196.             color(32768,0x191919)
  197.             term.setBackgroundColor(colors.black)
  198.             term.clear()
  199.             term.setCursorPos(1,1)
  200.             error("Closed by admin")
  201.         else
  202.             os.reboot()
  203.         end
  204.     end
  205. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement