Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("CodevoxOSC/apis/cvPrint")
- os.loadAPI("CodevoxOSC/apis/cvMenu")
- os.loadAPI("CodevoxOSC/apis/cvRednet")
- local x,y = term.getSize()
- local finished = false
- local selected = {"Login","valid"}
- local accountsServerID = 67
- local lastX, lastY
- local modemOpened
- local myWindow
- local showTime
- local currentPage
- local valid
- modemOpened = cvRednet.OpenModem()
- if modemOpened == false then
- cvPrint.Centre("No modem detected,",7)
- cvPrint.Centre("Entering Debug Mode",8)
- shell.run("codevox/debug")
- end
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.red)
- term.clear()
- term.setCursorPos(2,1)
- write ("Codevox")
- paintutils.drawLine(1,2,x,2,colors.red)
- paintutils.drawLine(14,1,14,y,colors.gray)
- term.setBackgroundColor(colors.white)
- cvMenu.DrawOption("Login",1,4)
- cvMenu.DrawOption("Create User",1,5)
- cvMenu.DrawOption("Shutdown",1,6)
- function CreateWindow(windowName)
- myWindow = window.create(term.current(),15,3,37,17)
- myWindow.setBackgroundColor(colors.white)
- myWindow.clear()
- paintutils.drawLine(15,4,x,4,colors.gray)
- cvPrint.Menu(windowName,4)
- end
- function Login()
- while finished == false do
- term.setTextColor(colors.black)
- term.setCursorPos(x/2+2,8)
- local username = read()
- term.setCursorPos(x/2+2,10)
- local password = read("*")
- rednet.send(accountsServerID,"login")
- rednet.send(accountsServerID,username)
- rednet.send(accountsServerID,password)
- local id, signIn = rednet.receive()
- if signIn == "successful" then
- os.setComputerLabel(username)
- term.setTextColor(colors.green)
- cvPrint.LeftWindow("Correct Password,",14)
- cvPrint.LeftWindow("Entering Codevox OS",15)
- sleep(1.5)
- term.clear()
- finished = true
- elseif signIn == "unsuccessful" or signIn == "unfound" then
- term.setTextColor(colors.red)
- cvPrint.LeftWindow("Incorrect Username/Password,",14)
- cvPrint.LeftWindow("Please try again",15)
- sleep(1.5)
- username = nil
- password = nil
- shell.run("CodevoxOSC/cvLoginmenu")
- end
- end
- end
- function CreateUser()
- while finished == false do
- term.setTextColor(colors.black)
- term.setCursorPos(x/2+2,8)
- local username = read()
- term.setCursorPos(x/2+2,10)
- local password = read("*")
- term.setCursorPos(x/2+11,12)
- local password2 = read("*")
- if password2 ~= password then
- term.setTextColor(colors.red)
- cvPrint.LeftWindow("Passwords did not match,",14)
- cvPrint.LeftWindow("Please try again",15)
- sleep(1.5)
- username = nil
- password = nil
- password2 = nil
- shell.run("CodevoxOSC/cvLoginmenu")
- end
- rednet.send(accountsServerID,"createAccount")
- rednet.send(accountsServerID,username)
- rednet.send(accountsServerID,password)
- local id, signIn = rednet.receive()
- if signIn == "created" then
- os.setComputerLabel(username)
- term.setTextColor(colors.green)
- cvPrint.LeftWindow("Account Created,",14)
- cvPrint.LeftWindow("Entering Codevox OS",15)
- sleep(1.5)
- finished = true
- elseif signIn == "notCreated" then
- term.setTextColour(colours.red)
- cvPrint.LeftWindow("That username already exists,",14)
- cvPrint.LeftWindow("Please try again",15)
- sleep(1.5)
- username = nil
- password = nil
- password2 = nil
- shell.run("CodevoxOSC/cvLoginmenu")
- end
- end
- end
- function GetClicks()
- valid = false
- repeat
- event, button, clickX, clickY = os.pullEvent("mouse_click")
- cvMenu.ResetSelected()
- selected = cvMenu.GetSelected(button,clickX,clickY)
- if selected[1] ~= currentPage and selected[2] == "valid" then
- valid = true
- end
- until valid == true
- end
- function LoginMenu()
- while finished == false do
- if selected[1] == currentPage then
- selected = {}
- GetClicks()
- elseif selected[2] == "valid" then
- CreateWindow(selected[1])
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.red)
- if selected[1] == "Login" then
- currentPage = selected[1]
- cvPrint.Menu("Username: ",8)
- cvPrint.Menu("Password: ",10)
- parallel.waitForAny(GetClicks,Login)
- elseif selected[1] == "Create User" then
- currentPage = selected[1]
- cvPrint.Menu("Username: ",8)
- cvPrint.Menu("Password: ",10)
- cvPrint.Menu("Re-Enter Password: ", 12)
- parallel.waitForAny(GetClicks,CreateUser)
- elseif selected[1] == "Shutdown" then
- cvPrint.Menu("Shutting Down",10)
- sleep(1.5)
- os.shutdown()
- end
- end
- end
- end
- function ShowTime()
- while finished == false do
- lastX, lastY = term.getCursorPos()
- showTime = textutils.formatTime(os.time(),false)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.red)
- cvPrint.Right(showTime,1)
- term.setCursorPos(lastX,lastY)
- term.setTextColor(colors.black)
- sleep(1)
- end
- end
- while finished == false do
- parallel.waitForAny(LoginMenu,ShowTime)
- end
- term.redirect(term.native())
- shell.run("CodevoxOSC/cvMain","loggedIn")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement