Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Loading dependencies
- os.loadAPI("/disk/setup/arcui")
- os.loadAPI("/disk/setup/db")
- --os.loadAPI("StringUtils")
- local bRun = true
- local nTimerErrMsg = 0
- local nPingCount = 0
- local sUsername = ""
- local sPassword = ""
- local tErrorMessages = {[1] = "Bad type", [2] = "Unknown User", [3] = "Nil token: Outdated", [4] = "Bad token: Outdated", [5] = "Bad Password", [6] = "Bad accesslevel", [7] = "?", [8] = "Not enough money", [9] = "Unknown user to send"}
- -- Open the window
- arcui.drawWindow("Bank - Login", false)
- -- Setup the verification UI
- arcui.drawLabel("lbl_ping", 1, 18, "Checking the connection...", nil, colors.gray)
- arcui.drawMarqueeProgress("marq_ping", 1, 19, 51)
- -- Check the server at boot time
- local function checkServer()
- while true do
- if db.ping() then
- arcui.deleteWidget("lbl_ping")
- arcui.deleteWidget("marq_ping")
- break
- else
- nPingCount = nPingCount + 1
- end
- end
- end
- parallel.waitForAny(checkServer, arcui.marqueeAnim)
- -- Setup the login UI
- arcui.drawTextbox("txtbox_username", 10, 9, 41, "Username")
- arcui.drawTextbox("txtbox_password", 10, 11, 41, "Password", "*")
- arcui.drawButton("btn_ok", 24, 15, 26, 17, colors.green, ">")
- arcui.drawLabel("lbl_thebank", (51 / 2) - (string.len("TheBank") / 2), 4, "TheBank")
- arcui.drawLabel("lbl_err", 1, 19, "", nil, colors.red)
- -- Def functions
- local function isStringEmpty(string)
- return string:match("%S") == nil
- end
- local function verifyCreditentials()
- if not db.ping() then
- return false, "Unable to connect to the server"
- end
- if isStringEmpty(sUsername) or isStringEmpty(sPassword) then
- return false, "Username/Password missing"
- end
- local nResponse = db.getInfo(sUsername, sPassword)
- if type(nResponse) == "table" or nResponse == 0 then
- return true
- else
- return false, tErrorMessages[nResponse] or nResponse
- end
- end
- -- Main loop
- local function loop()
- while bRun do
- event, p1, p2, p3 = os.pullEvent()
- if event == "button_clicked" then
- if p1 == "btn_ok" then
- local bIsSuccess, sErrorMessage = verifyCreditentials()
- if bIsSuccess then
- -- Login successful
- arcui.closeWindow()
- bRun = false
- if not fs.exists("/disk/vms/users/"..sUsername) then fs.makeDir("/disk/vms/users/"..sUsername) end
- ntmvar = "/disk/vms/users/"..sUsername
- shell.run("/disk/setup/vOS --biosPath=/disk/bios.lua --name="..sUsername.." --pass="..sPassword.." --rootPath="..ntmvar.." --romPath=/disk/rom")
- os.reboot()
- else
- -- Login failed
- arcui.changeValue("lbl_err", "text", sErrorMessage)
- nTimerErrMsg = os.startTimer(5)
- arcui.changeValue("txtbox_username", "value", "")
- sUsername = ""
- arcui.changeValue("txtbox_password", "value", "")
- sPassword = ""
- end
- end
- elseif event == "textbox_text" then
- if p1 == "txtbox_username" then
- sUsername = p2
- elseif p1 == "txtbox_password" then
- sPassword = p2
- end
- elseif event == "timer" then
- if p1 == nTimerErrMsg then
- arcui.changeValue("lbl_err", "text", "")
- end
- end
- end
- end
- parallel.waitForAll(loop, arcui.eventHandler, arcui.marqueeAnim, arcui.progressAnim)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement