Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local termWidth, termHeight = term.getSize()
- local onMainMenu = true
- local modemSide = "back"
- local server = 25
- local auth = false
- function testColor(color)
- rednet.open(modemSide)
- colorQuery = "qcol." .. color
- sleep(0.1)
- rednet.send(server, colorQuery)
- _, answer = rednet.receive()
- return answer
- end
- function gui(x, y, gtext)
- term.clear()
- term.setCursorPos(1,1)
- print ("*****************")
- print ("* SpyderOS v0.8 *")
- print ("*****************")
- print (" ")
- -- move stuff here to display factory status??
- term.setCursorPos(x, y)
- write(gtext)
- end
- function bsod()
- term.clear()
- term.setCursorPos(22,4)
- write ("SpyderOS")
- term.setCursorPos(1,6)
- print (" A fatal exception has occured at 0028:C0129E2 in")
- print (" module SpyderOS.input. The current application")
- print (" will be terminated.")
- print ("")
- print (" * Press CTRL+R to restart terminal now. You will")
- print (" lose any unsaved information in all")
- print (" applications.")
- print ("")
- print ("")
- print (" The system will shutdown in 10 seconds")
- sleep(10)
- os.shutdown()
- end
- function menu(adminFlag)
- logout = false
- while logout == false do
- if testColor("white") == "0" then hlight = "Off" else hlight = "On" end
- if testColor("red") == "0" then hdoor = "Closed" else hdoor = "Open" end
- if testColor("yellow") == "0" then flight = "Off" else flight = "On" end
- if testColor("orange") == "0" then fdoor = "Closed" else fdoor = "Open" end
- if testColor("blue") == "0" then maint = "Closed" else maint = "Open" end
- gui(1,5, " 1. House Lights (" .. hlight .. ")\n")
- print (" 2. House Door (" .. hdoor .. ")")
- print (" 3. Factory Lights (" .. flight .. ")")
- print (" 4. Factory Door (" .. fdoor .. ")")
- if adminFlag == true then print (" 5. Maintenance Access (" .. maint .. ")") end
- print ("\n L. Logout")
- term.setCursorPos(1, 17)
- write("Selection: ")
- selection = read()
- if selection == "1" then
- rednet.send(server, "togl.white")
- elseif selection == "2" then
- rednet.send(server, "togl.red")
- elseif selection == "3" then
- rednet.send(server, "togl.yellow")
- elseif selection == "4" then
- rednet.send(server, "togl.orange")
- elseif (selection == "5") and (adminFlag == true) then
- rednet.send(server, "togl.blue")
- elseif selection == "L" then
- logout = true
- elseif selection == "l" then
- logout = true
- else
- term.clearLine(17)
- term.setCursorPos(2, 17)
- print ("Invalid Selection")
- sleep(3)
- end
- end
- end
- function login()
- menuexit = false
- while menuexit == false do
- gui(1,17,"User:")
- status, login = pcall(read)
- if login == "spyder" then
- gui(1,16,"User Accepted\n")
- write("Password: ")
- status, password = pcall(read)
- if password == "superSecret" then
- gui(1,17,"Access Granted")
- sleep(0.5)
- menu(true)
- else
- gui(1,17,"Password Incorrect!")
- sleep(1)
- end
- elseif login == "exit" then
- gui(1,17,"Goodbye")
- sleep(1)
- os.shutdown()
- elseif login == "jarrod" then
- bsod()
- elseif login == "guest" then
- menu()
- else
- gui(1,17,"Login Incorrect")
- sleep(2)
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- end
- rednet.open(modemSide)
- term.clear()
- term.setCursorPos(1,1)
- write ("Logging In... ")
- loginTries = 0
- loggedIn = false
- while loggedIn == false do
- rednet.send(server, "ping")
- replyId, pong = rednet.receive(5)
- if (replyId == server) and (pong == "pong") then
- write ("Logged In")
- sleep(0.5)
- if auth == true then login() else menu() end
- else
- write ("\nBad Response (" .. pong .. ":" .. replyId .. "), Retrying")
- loginTries = loginTries + 1
- end
- if loginTries == 6 then
- print ("\n\nToo many bad logins!")
- sleep(4)
- os.shutdown()
- end
- end
Add Comment
Please, Sign In to add comment