Guest User

Untitled

a guest
Jan 3rd, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. local termWidth, termHeight = term.getSize()
  2. local onMainMenu = true
  3. local modemSide = "back"
  4. local server = 25
  5. local auth = false
  6.  
  7. function testColor(color)
  8. rednet.open(modemSide)
  9. colorQuery = "qcol." .. color
  10. sleep(0.1)
  11. rednet.send(server, colorQuery)
  12. _, answer = rednet.receive()
  13. return answer
  14. end
  15.  
  16. function gui(x, y, gtext)
  17. term.clear()
  18. term.setCursorPos(1,1)
  19. print ("*****************")
  20. print ("* SpyderOS v0.8 *")
  21. print ("*****************")
  22. print (" ")
  23. -- move stuff here to display factory status??
  24. term.setCursorPos(x, y)
  25. write(gtext)
  26. end
  27.  
  28. function bsod()
  29. term.clear()
  30. term.setCursorPos(22,4)
  31. write ("SpyderOS")
  32. term.setCursorPos(1,6)
  33. print (" A fatal exception has occured at 0028:C0129E2 in")
  34. print (" module SpyderOS.input. The current application")
  35. print (" will be terminated.")
  36. print ("")
  37. print (" * Press CTRL+R to restart terminal now. You will")
  38. print (" lose any unsaved information in all")
  39. print (" applications.")
  40. print ("")
  41. print ("")
  42. print (" The system will shutdown in 10 seconds")
  43. sleep(10)
  44. os.shutdown()
  45. end
  46.  
  47. function menu(adminFlag)
  48. logout = false
  49. while logout == false do
  50. if testColor("white") == "0" then hlight = "Off" else hlight = "On" end
  51. if testColor("red") == "0" then hdoor = "Closed" else hdoor = "Open" end
  52. if testColor("yellow") == "0" then flight = "Off" else flight = "On" end
  53. if testColor("orange") == "0" then fdoor = "Closed" else fdoor = "Open" end
  54. if testColor("blue") == "0" then maint = "Closed" else maint = "Open" end
  55. gui(1,5, " 1. House Lights (" .. hlight .. ")\n")
  56. print (" 2. House Door (" .. hdoor .. ")")
  57. print (" 3. Factory Lights (" .. flight .. ")")
  58. print (" 4. Factory Door (" .. fdoor .. ")")
  59. if adminFlag == true then print (" 5. Maintenance Access (" .. maint .. ")") end
  60. print ("\n L. Logout")
  61. term.setCursorPos(1, 17)
  62. write("Selection: ")
  63. selection = read()
  64. if selection == "1" then
  65. rednet.send(server, "togl.white")
  66. elseif selection == "2" then
  67. rednet.send(server, "togl.red")
  68. elseif selection == "3" then
  69. rednet.send(server, "togl.yellow")
  70. elseif selection == "4" then
  71. rednet.send(server, "togl.orange")
  72. elseif (selection == "5") and (adminFlag == true) then
  73. rednet.send(server, "togl.blue")
  74. elseif selection == "L" then
  75. logout = true
  76. elseif selection == "l" then
  77. logout = true
  78. else
  79. term.clearLine(17)
  80. term.setCursorPos(2, 17)
  81. print ("Invalid Selection")
  82. sleep(3)
  83. end
  84. end
  85. end
  86.  
  87. function login()
  88. menuexit = false
  89. while menuexit == false do
  90. gui(1,17,"User:")
  91. status, login = pcall(read)
  92. if login == "spyder" then
  93. gui(1,16,"User Accepted\n")
  94. write("Password: ")
  95. status, password = pcall(read)
  96. if password == "superSecret" then
  97. gui(1,17,"Access Granted")
  98. sleep(0.5)
  99. menu(true)
  100. else
  101. gui(1,17,"Password Incorrect!")
  102. sleep(1)
  103. end
  104. elseif login == "exit" then
  105. gui(1,17,"Goodbye")
  106. sleep(1)
  107. os.shutdown()
  108. elseif login == "jarrod" then
  109. bsod()
  110. elseif login == "guest" then
  111. menu()
  112. else
  113. gui(1,17,"Login Incorrect")
  114. sleep(2)
  115. end
  116. end
  117. term.clear()
  118. term.setCursorPos(1,1)
  119. end
  120.  
  121. rednet.open(modemSide)
  122. term.clear()
  123. term.setCursorPos(1,1)
  124. write ("Logging In... ")
  125. loginTries = 0
  126. loggedIn = false
  127. while loggedIn == false do
  128. rednet.send(server, "ping")
  129. replyId, pong = rednet.receive(5)
  130. if (replyId == server) and (pong == "pong") then
  131. write ("Logged In")
  132. sleep(0.5)
  133. if auth == true then login() else menu() end
  134. else
  135. write ("\nBad Response (" .. pong .. ":" .. replyId .. "), Retrying")
  136. loginTries = loginTries + 1
  137. end
  138. if loginTries == 6 then
  139. print ("\n\nToo many bad logins!")
  140. sleep(4)
  141. os.shutdown()
  142. end
  143. end
Add Comment
Please, Sign In to add comment