Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local variables
- -- Main() variables --
- local mainLoop1 = true
- local doLogin = false
- local doCreate = false
- local doStartMenu = true
- local doBlinkLogin = true
- local doBlinkCreate = true
- local loggedMenu = false
- local loggedBalance = false
- local loggedSettings = false
- local balanceDeposit = false
- local balanceWithdraw = false
- local username
- local password
- local continueBalance = false
- local accountMenu = true
- -- logged Variables
- local currentBalance = 0
- local respond = false
- local tries = 0
- local tries1 = 0
- local respond1 = false
- -- Help Var's
- local clear = term.clear
- local sP = term.setCursorPos
- local scroll = term.scroll
- local pull = os.pullEvent
- local tCol = term.setTextColor
- local bCol = term.setBackgroundColor
- function reset()
- mainLoop1 = true
- doLogin = false
- doCreate = false
- doBlinkLogin = true
- doBlinkCreate = true
- doStartMenu = true
- loggedMenu = false
- loggedBalance = false
- loggedSettings = false
- balanceDeposit = false
- balanceWithdraw = false
- respond = false
- respond1 = false
- tries = 0
- tries1 = 0
- stopNoLoop = false
- continueBalance = false
- end
- -- local themes --
- local themes = {
- ["bRed"] = {bC = colors.red};
- ["bBlack"] = {bC = colors.black};
- ["bWhite"] = {bC = colors.white};
- ["bBlue"] = {bC = colors.blue};
- ["bGray"] = {bC = colors.gray};
- ["bLightGray"] = {bC = colors.lightGray};
- ["bGreen"] = {bC = colors.green};
- ["bLime"] = {bC = colors.lime};
- ["bYellow"] = {bC = colors.yellow};
- ["bOrange"] = {bC = colors.orange};
- ["tOrange"] = {tC = colors.orange};
- ["tYellow"] = {tC = colors.yellow};
- ["tRed"] = {tC = colors.red};
- ["tBlack"] = {tC = colors.Black};
- ["tWhite"] = {tC = colors.white};
- ["tBlue"] = {tC = colors.blue};
- ["tGray"] = {tC = colors.gray};
- ["tLightGray"] = {tC = colors.lightGray};
- ["tGreen"] = {tC = colors.green};
- ["tLime"] = {tC = colors.lime};
- }
- function theme(themer)
- if not themer then
- error("Theme is not valid", 2)
- end
- if string.find(themer, "t", 1) then
- local setTheme = themes[themer].tC
- tCol(setTheme)
- else
- local setTheme = themes[themer].bC
- bCol(setTheme)
- end
- end
- function cWrite(text, yPos)
- local termX, termY = term.getSize()
- --api.send(api.getMaster(), "error yPos = "..tostring(yPos))
- if not yPos then
- local x,y = term.getCursorPos()
- yPos = y + 1
- end
- term.setCursorPos(math.floor((termX / 2) - (string.len(text) / 2)), yPos)
- write(text)
- end
- function drawButton(sX, sY, eX, eY, bC, tC, text)
- theme(tC)
- theme(bC)
- local ySpot = math.floor((sY + eY) / 2)
- local xSpot = math.floor((eX - sX - string.len(text)) / 2) + 1
- for y = sY, eY do
- sP(sX, y)
- if y == ySpot then
- for x = 0, eX - sX - string.len(text) + 1 do
- if x == xSpot then
- write(text)
- else
- write(" ")
- end
- end
- else
- for x = sX, eX do
- write(" ")
- end
- end
- end
- end
- function screen()
- local sizeX, sizeY = term.getSize()
- while true do
- if doStartMenu then
- theme("bGray")
- theme("tYellow")
- clear()
- if api.getGlobalMessage() == "Connected" then
- cWrite("Connected to server", 2)
- end
- drawButton(20, 8, 30, 10, "tYellow", "bGreen", "LOGIN")
- drawButton(18, 14, 32, 16, "tYellow", "bGreen", "Create User")
- elseif doLogin then
- if doBlinkLogin then
- drawButton(20, 8, 30, 10, "bYellow", "tGreen", "LOGIN")
- sleep(0.05)
- doBlinkLogin = false
- end
- function ask()
- theme("bGray")
- theme("tYellow")
- clear()
- sP(1,19)
- write("Enter Username > ")
- theme("tOrange")
- username = read()
- scroll(1)
- theme("tYellow")
- write("Enter Password > ")
- theme("tOrange")
- password = read("*")
- scroll(2)
- print("Contacting server...")
- api.send(api.getMaster(), "apply $usr="..encrypt.hash(username).."&pwd="..encrypt.hash(password))
- scroll(1)
- while not respond1 and tries1 <= 3 do
- print("Waiting for authentification...")
- local id, msg = rednet.receive(2)
- if id == api.getMaster() then
- respond1 = true
- if msg == encrypt.hash("OK") then
- theme("tLime")
- print("Authentificated")
- scroll(2)
- print("Loading GUI...")
- sleep(1)
- doLogin = false
- loggedMenu = true
- elseif msg == encrypt.hash("FAIL") then
- theme("tRed")
- print("NOT AUTHENTIFICATED!")
- for i = 1, 5 do scroll(1) sleep(0.2) end
- print("PLEASE TRY AGAIN!")
- sleep(2)
- respond1 = false
- ask()
- end
- else
- theme("tRed")
- scroll(1)
- textutils.slowPrint("Server did not respond...")
- scroll(1)
- textutils.slowPrint("Trying again...")
- for i = 1, 10 do scroll(1) sleep(0.05) end
- end
- tries1 = tries1 + 1
- end
- if not respond1 then
- theme("tRed")
- scroll(1)
- textutils.slowPrint("Server is OFFLINE...")
- scroll(1)
- textutils.slowPrint("Rebooting computer...")
- sleep(2)
- os.reboot()
- end
- end
- ask()
- elseif doCreate then
- if doBlinkCreate then
- drawButton(18, 14, 32, 16, "bYellow", "tGreen", "Create User")
- sleep(0.05)
- doBlinkCreate = false
- end
- theme("bGray")
- theme("tYellow")
- clear()
- elseif loggedMenu then
- api.send(api.getMaster(), "error accountMenu = "..tostring(accountMenu).." loggedBal = ".. tostring(loggedBalance).." loggedSet = ".. tostring(loggedSettings))
- if accountMenu == true and loggedBalance == false and loggedSettings == false and balanceWithdraw == false or balanceDeposit == false then
- theme("bGray")
- theme("tLime")
- clear()
- cWrite("---_-------------------------------------_---", 2)
- cWrite(" /_\\ ___ ___ ___ _ _ _ __ | |_ ", 3)
- cWrite(" //_\\\\ / __| / __| / _ \\ | | | || '_ \\ | __|", 4)
- cWrite("/ _ \\| (__ | (__ | (_) || |_| || | | || |_ ", 5)
- cWrite("\\_/ \\_/ \\___| \\___| \\___/ \\__,_||_| |_| \\__|", 6)
- cWrite("---------------------------------------------", 7)
- theme("tYellow")
- cWrite("Choose an option", 9)
- drawButton(15, 12, 35, 14, "bGreen", "tOrange", "Balance")
- drawButton(20, 17, 30, 19, "bGreen", "tRed", "Settings")
- api.send(api.getMaster(), "error ran first if")
- sleep(0.3)
- elseif loggedBalance == true and loggedSettings == false then
- api.send(api.getMaster(), "error This works")
- sleep(2)
- function load()
- while not respond and tries <= 3 do
- theme("bGray")
- theme("tLime")
- clear()
- sP(1, 19)
- theme("tYellow")
- print("Contacting server for balance info...")
- api.send(api.getMaster(), "balance &usr="..encrypt.hash(username).."&pwd="..encrypt.hash(password))
- scroll(1)
- print("Loading GUI")
- local id, msg = rednet.receive(2)
- sleep(0.8)
- if id == api.getMaster() then
- respond = true
- tries = 0
- currentBalance = tonumber(msg)
- continueBalance = true
- elseif not id then
- theme("tRed")
- scroll(1)
- textutils.slowPrint("Server did not respond...")
- scroll(1)
- textutils.slowPrint("Trying again...")
- for i = 1, 10 do scroll(1) sleep(0.05) end
- end
- tries = tries + 1
- end
- if not respond then
- theme("tRed")
- scroll(1)
- textutils.slowPrint("Server is OFFLINE...")
- scroll(1)
- textutils.slowPrint("Rebooting computer...")
- sleep(2)
- os.reboot()
- end
- end
- load()
- if continueBalance then
- theme("bGray")
- theme("tLime")
- clear()
- cWrite("---_-------------------------------------_---", 2)
- cWrite(" /_\\ ___ ___ ___ _ _ _ __ | |_ ", 3)
- cWrite(" //_\\\\ / __| / __| / _ \\ | | | || '_ \\ | __|", 4)
- cWrite("/ _ \\| (__ | (__ | (_) || |_| || | | || |_ ", 5)
- cWrite("\\_/ \\_/ \\___| \\___| \\___/ \\__,_||_| |_| \\__|", 6)
- cWrite("--____------------_-------------------------------", 7)
- cWrite(" | __ ) __ _ | | __ _ _ __ ___ ___ ", 8)
- cWrite(" | _ \\ / _' | | | / _' | | '_ \\ / __| / _ \\", 9)
- cWrite(" | |_) | | (_| | | | | (_| | | | | | | (__ | __/", 10)
- cWrite(" |____/ \\__,_| |_| \\__,_| |_| |_| \\___| \\___|", 11)
- cWrite("--------------------------------------------------", 12)
- cWrite("Current balance", 14)
- cWrite("$"..currentBalance, 16)
- drawButton(3, 16, 18, 18, "bGreen", "tOrange", "Withdraw")
- drawButton(33, 16, 49, 18, "bGreen", "tOrange", "Deposit")
- api.send(api.getMaster(), "error ContinueBalance after IF = ".. tostring(continueBalance))
- end
- elseif balanceWithdraw then
- elseif balanceDeposit then
- elseif not loggedBalance and loggedSettings then
- elseif loggedSettings and loggedBalance then
- loggedBalance = false
- loggedSettings = false
- error("loggedSettings and loggedBalance is both set to TRUE", 2)
- end
- end
- sleep(1)
- end
- end
- function main()
- reset()
- while true do
- local event, button, xP, yP = pull("mouse_click")
- if button == 1 then
- if doStartMenu then
- if xP >= 20 and xP <= 30 and yP >= 8 and yP <= 10 then
- doStartMenu = false
- doLogin = true
- elseif xP >= 18 and xP <= 32 and yP >= 14 and yP <= 16 then
- doStartMenu = false
- doCreate = true
- end
- elseif not doLogin then
- if loggedMenu then
- if xP >= 15 and xP <= 35 and yP >= 12 and yP <= 14 then
- api.send(api.getMaster(), "error BalanceButtonClicked")
- accountMenu = false
- loggedBalance = true
- continueBalance = true
- loggedSettings = false
- api.send(api.getMaster(), "error Acc = "..tostring(accountMenu).." \nloggedBalance = "..tostring(loggedBalance).."\nloggedSettings = "..tostring(loggedSettings))
- elseif xP >= 20 and xP <= 30 and yP >= 17 and yP <= 19 then
- api.send(api.getMaster(), "error SettingsButtonClicked")
- loggedSettings = true
- loggedBalance = false
- else
- api.send(api.getMaster(), "error NoButtons Clicked")
- end
- elseif loggedSettings then
- elseif loggedBalance then
- if continueBalance then
- if xP >= 3 and xP <= 18 and yP >= 16 and yP <= 18 then
- loggedSettings = false
- balanceWithdraw = true
- elseif xP >= 33 and xP <= 49 and yP >= 16 and yP <= 18 then
- loggedSettings = false
- balanceDeposit = true
- end
- elseif not continueBalance then
- if balanceWithdraw then
- elseif balanceDeposit then
- end
- end
- end
- elseif doCreate then
- end
- end
- end
- end
- parallel.waitForAll(main, screen)
- --screen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement