Guest User

startup

a guest
Jul 26th, 2012
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. noLogin = true
  2. if fs.exists('/disk/startup')
  3. then
  4. if fs.exists('/startup') then
  5.  
  6. if fs.exists('/startup.bak') then
  7. fs.delete('/startup.bak')
  8. end
  9.  
  10. fs.move('/startup', '/startup.bak')
  11. end
  12.  
  13. fs.copy('/disk/startup', '/startup')
  14. end
  15. if fs.exists('/disk/door') then
  16.  
  17. if fs.exists('/door.bak') then
  18. fs.delete('/door.bak')
  19. end
  20. if fs.exists('/door') then
  21. fs.move('/door', '/door.bak')
  22. end
  23. fs.copy('/disk/door', '/door')
  24. end
  25.  
  26. term.clear()
  27. x, y = term.getSize()
  28.  
  29.  
  30. function main()
  31. term.setCursorPos(x/2-11, y/2)
  32. term.write("Username: ")
  33.  
  34. term.setCursorPos(x/2-11, y/2+1)
  35. term.write("Password: ")
  36.  
  37. term.setCursorPos(24,9)
  38. userN = read('*')
  39.  
  40.  
  41. term.setCursorPos(24,10)
  42. userP = read('*')
  43.  
  44. userName = userN
  45. userPass = userP
  46. if fs.exists('/settings') then
  47. file = io.open('settings', 'r')
  48. if userN == file:read() then
  49.  
  50. if userP == file:read() then
  51. noLogin = false
  52. return
  53. else main()
  54. file:close()
  55. end
  56. else main()
  57. file:close()
  58. end
  59. file:close()
  60. else
  61. print(userName.." " ..userPass)
  62. print("Is this correct? yes/no")
  63. answer = read()
  64. answer = answer:lower()
  65. print(answer)
  66. if answer == "yes" then
  67. writeSettings()
  68. elseif answer == 49 then
  69. print("Restarting Log In Procedure.")
  70. sleep(15)
  71. os.reboot()
  72. else
  73. os.reboot()
  74. end
  75. end
  76. end -- end main
  77.  
  78. function writeSettings()
  79. file = io.open('/settings', 'w')
  80. file:write(userN.."\n")
  81. file:write(userP.."\n")
  82. file:write(" ")
  83. file:close()
  84. end --writesettings
  85.  
  86. function os.pullEvent()
  87. local event, arg1, arg2, arg3, arg4, arg5 = os.pullEventRaw()
  88. if event == "terminate" then
  89. sleep(1)
  90. end
  91. return event, arg1, arg2, arg3, arg4, arg5
  92. end
  93.  
  94. function stayClosed()
  95. while noLogin == true do
  96. rs.setOutput('left', false)
  97. rs.setOutput('top', false)
  98. rs.setOutput('bottom', false)
  99. rs.setOutput('right', false)
  100. os.pullEvent()
  101. end
  102. end
  103.  
  104. parallel.waitForAny(main, stayClosed)
Advertisement
Add Comment
Please, Sign In to add comment