Advertisement
Guest User

Screen.exe

a guest
Sep 2nd, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.17 KB | None | 0 0
  1. local variables
  2.  
  3.  
  4. -- Main() variables --
  5. local mainLoop1 = true
  6. local doLogin = false
  7. local doCreate = false
  8. local doStartMenu = true
  9. local doBlinkLogin = true
  10. local doBlinkCreate = true
  11. local loggedMenu = false
  12. local loggedBalance = false
  13. local loggedSettings = false
  14. local balanceDeposit = false
  15. local balanceWithdraw = false
  16. local username
  17. local password
  18. local continueBalance = false
  19. local accountMenu = true
  20. -- logged Variables
  21. local currentBalance = 0
  22.  
  23. local respond = false
  24. local tries = 0
  25.  
  26. local tries1 = 0
  27. local respond1 = false
  28.  
  29. -- Help Var's
  30.  
  31. local clear = term.clear
  32. local sP = term.setCursorPos
  33. local scroll = term.scroll
  34. local pull = os.pullEvent
  35. local tCol = term.setTextColor
  36. local bCol = term.setBackgroundColor
  37.  
  38.  
  39.  
  40. function reset()
  41.     mainLoop1 = true
  42.     doLogin = false
  43.     doCreate = false
  44.     doBlinkLogin = true
  45.     doBlinkCreate = true
  46.     doStartMenu = true
  47.     loggedMenu = false
  48.     loggedBalance = false
  49.     loggedSettings = false
  50.     balanceDeposit = false
  51.     balanceWithdraw = false
  52.     respond = false
  53.     respond1 = false
  54.     tries = 0
  55.     tries1 = 0
  56.     stopNoLoop = false
  57.     continueBalance = false
  58. end
  59.  
  60.  
  61. -- local themes --
  62. local themes = {
  63.     ["bRed"] = {bC = colors.red};
  64.     ["bBlack"] = {bC = colors.black};
  65.     ["bWhite"] = {bC = colors.white};
  66.     ["bBlue"] = {bC = colors.blue};
  67.     ["bGray"] = {bC = colors.gray};
  68.     ["bLightGray"] = {bC = colors.lightGray};
  69.     ["bGreen"] = {bC = colors.green};
  70.     ["bLime"] = {bC = colors.lime};
  71.     ["bYellow"] = {bC = colors.yellow};
  72.     ["bOrange"] = {bC = colors.orange};
  73.     ["tOrange"] = {tC = colors.orange};
  74.     ["tYellow"] = {tC = colors.yellow};
  75.     ["tRed"] = {tC = colors.red};
  76.     ["tBlack"] = {tC = colors.Black};
  77.     ["tWhite"] = {tC = colors.white};
  78.     ["tBlue"] = {tC = colors.blue};
  79.     ["tGray"] = {tC = colors.gray};
  80.     ["tLightGray"] = {tC = colors.lightGray};
  81.     ["tGreen"] = {tC = colors.green};
  82.     ["tLime"] = {tC = colors.lime};
  83. }
  84.  
  85. function theme(themer)
  86.     if not themer then
  87.         error("Theme is not valid", 2)
  88.     end
  89.     if string.find(themer, "t", 1) then
  90.         local setTheme = themes[themer].tC
  91.         tCol(setTheme)
  92.     else
  93.         local setTheme = themes[themer].bC
  94.         bCol(setTheme)
  95.     end
  96. end
  97.  
  98. function cWrite(text, yPos)
  99.     local termX, termY = term.getSize()
  100.     --api.send(api.getMaster(), "error yPos = "..tostring(yPos))
  101.     if not yPos then
  102.         local x,y = term.getCursorPos()
  103.         yPos = y + 1
  104.     end
  105.     term.setCursorPos(math.floor((termX / 2) - (string.len(text) / 2)), yPos)
  106.     write(text)
  107. end
  108.  
  109. function drawButton(sX, sY, eX, eY, bC, tC, text)
  110.     theme(tC)
  111.     theme(bC)
  112.     local ySpot = math.floor((sY + eY) / 2)
  113.     local xSpot = math.floor((eX - sX - string.len(text)) / 2) + 1
  114.     for y = sY, eY do
  115.         sP(sX, y)
  116.         if y == ySpot then
  117.             for x = 0, eX - sX - string.len(text) + 1 do
  118.                 if x == xSpot then
  119.                     write(text)
  120.                 else
  121.                     write(" ")
  122.                 end
  123.             end
  124.         else
  125.             for x = sX, eX do
  126.                 write(" ")
  127.             end
  128.         end
  129.     end
  130. end
  131.  
  132. function screen()
  133.     local sizeX, sizeY = term.getSize()
  134.     while true do
  135.         if doStartMenu then
  136.             theme("bGray")
  137.             theme("tYellow")
  138.             clear()
  139.             if api.getGlobalMessage() == "Connected" then
  140.                 cWrite("Connected to server", 2)
  141.             end
  142.             drawButton(20, 8, 30, 10, "tYellow", "bGreen", "LOGIN")
  143.             drawButton(18, 14, 32, 16, "tYellow", "bGreen", "Create User")
  144.         elseif doLogin then
  145.             if doBlinkLogin then
  146.                 drawButton(20, 8, 30, 10, "bYellow", "tGreen", "LOGIN")
  147.                 sleep(0.05)
  148.                 doBlinkLogin = false
  149.             end
  150.             function ask()
  151.                 theme("bGray")
  152.                 theme("tYellow")
  153.                 clear()
  154.                 sP(1,19)
  155.                 write("Enter Username > ")
  156.                 theme("tOrange")
  157.                 username = read()
  158.                 scroll(1)
  159.                 theme("tYellow")
  160.                 write("Enter Password > ")
  161.                 theme("tOrange")
  162.                 password = read("*")
  163.                 scroll(2)
  164.                 print("Contacting server...")
  165.                 api.send(api.getMaster(), "apply $usr="..encrypt.hash(username).."&pwd="..encrypt.hash(password))
  166.                 scroll(1)
  167.                 while not respond1 and tries1 <= 3 do
  168.                     print("Waiting for authentification...")
  169.                     local id, msg = rednet.receive(2)
  170.                     if id == api.getMaster() then
  171.                         respond1 = true
  172.                         if msg == encrypt.hash("OK") then
  173.                             theme("tLime")
  174.                             print("Authentificated")
  175.                             scroll(2)
  176.                             print("Loading GUI...")
  177.                             sleep(1)
  178.                             doLogin = false
  179.                             loggedMenu = true
  180.                         elseif msg == encrypt.hash("FAIL") then
  181.                             theme("tRed")
  182.                             print("NOT AUTHENTIFICATED!")
  183.                             for i = 1, 5 do scroll(1) sleep(0.2) end
  184.                             print("PLEASE TRY AGAIN!")
  185.                             sleep(2)
  186.                             respond1 = false
  187.                             ask()
  188.                         end
  189.                     else
  190.                         theme("tRed")
  191.                         scroll(1)
  192.                         textutils.slowPrint("Server did not respond...")
  193.                         scroll(1)
  194.                         textutils.slowPrint("Trying again...")
  195.                         for i = 1, 10 do scroll(1) sleep(0.05) end
  196.                     end
  197.                     tries1 = tries1 + 1
  198.                 end
  199.                 if not respond1 then
  200.                     theme("tRed")
  201.                     scroll(1)
  202.                     textutils.slowPrint("Server is OFFLINE...")
  203.                     scroll(1)
  204.                     textutils.slowPrint("Rebooting computer...")
  205.                     sleep(2)
  206.                     os.reboot()
  207.                 end
  208.             end
  209.             ask()  
  210.         elseif doCreate then
  211.             if doBlinkCreate then
  212.                 drawButton(18, 14, 32, 16, "bYellow", "tGreen", "Create User")
  213.                 sleep(0.05)
  214.                 doBlinkCreate = false
  215.             end
  216.             theme("bGray")
  217.             theme("tYellow")
  218.             clear()
  219.         elseif loggedMenu then
  220.             api.send(api.getMaster(), "error accountMenu = "..tostring(accountMenu).." loggedBal = ".. tostring(loggedBalance).." loggedSet = ".. tostring(loggedSettings))
  221.             if accountMenu == true and loggedBalance == false and loggedSettings == false and balanceWithdraw == false or balanceDeposit == false then
  222.                 theme("bGray")
  223.                 theme("tLime")
  224.                 clear()
  225.  
  226.                 cWrite("---_-------------------------------------_---", 2)
  227.                 cWrite("  /_\\    ___   ___   ___   _   _  _ __  | |_ ", 3)
  228.                 cWrite(" //_\\\\  / __| / __| / _ \\ | | | || '_ \\ | __|", 4)
  229.                 cWrite("/  _  \\| (__ | (__ | (_) || |_| || | | || |_ ", 5)
  230.                 cWrite("\\_/ \\_/ \\___| \\___| \\___/  \\__,_||_| |_| \\__|", 6)
  231.                 cWrite("---------------------------------------------", 7)
  232.                 theme("tYellow")
  233.                 cWrite("Choose an option", 9)
  234.  
  235.                 drawButton(15, 12, 35, 14, "bGreen", "tOrange", "Balance")
  236.                 drawButton(20, 17, 30, 19, "bGreen", "tRed", "Settings")
  237.                 api.send(api.getMaster(), "error ran first if")
  238.                 sleep(0.3)
  239.             elseif loggedBalance == true and loggedSettings == false then
  240.                 api.send(api.getMaster(), "error This works")
  241.                 sleep(2)
  242.                 function load()
  243.                    
  244.                     while not respond and tries <= 3 do
  245.                         theme("bGray")
  246.                         theme("tLime")
  247.                         clear()
  248.                         sP(1, 19)
  249.                         theme("tYellow")
  250.                         print("Contacting server for balance info...")
  251.                         api.send(api.getMaster(), "balance &usr="..encrypt.hash(username).."&pwd="..encrypt.hash(password))
  252.                         scroll(1)
  253.                         print("Loading GUI")
  254.                         local id, msg = rednet.receive(2)
  255.                         sleep(0.8)
  256.                         if id == api.getMaster() then
  257.                             respond = true
  258.                             tries = 0
  259.                             currentBalance = tonumber(msg)
  260.                             continueBalance = true
  261.                         elseif not id then
  262.                             theme("tRed")
  263.                             scroll(1)
  264.                             textutils.slowPrint("Server did not respond...")
  265.                             scroll(1)
  266.                             textutils.slowPrint("Trying again...")
  267.                             for i = 1, 10 do scroll(1) sleep(0.05) end
  268.                         end
  269.                         tries = tries + 1
  270.                     end
  271.                     if not respond then
  272.                         theme("tRed")
  273.                         scroll(1)
  274.                         textutils.slowPrint("Server is OFFLINE...")
  275.                         scroll(1)
  276.                         textutils.slowPrint("Rebooting computer...")
  277.                         sleep(2)
  278.                         os.reboot()
  279.                     end
  280.                 end
  281.                 load()
  282.                 if continueBalance then
  283.                     theme("bGray")
  284.                     theme("tLime")
  285.                     clear()
  286.                     cWrite("---_-------------------------------------_---", 2)
  287.                     cWrite("  /_\\    ___   ___   ___   _   _  _ __  | |_ ", 3)
  288.                     cWrite(" //_\\\\  / __| / __| / _ \\ | | | || '_ \\ | __|", 4)
  289.                     cWrite("/  _  \\| (__ | (__ | (_) || |_| || | | || |_ ", 5)
  290.                     cWrite("\\_/ \\_/ \\___| \\___| \\___/  \\__,_||_| |_| \\__|", 6)
  291.                     cWrite("--____------------_-------------------------------", 7)
  292.                     cWrite(" | __ )    __ _  | |   __ _   _ __     ___    ___ ", 8)
  293.                     cWrite(" |  _ \\   / _' | | |  / _' | | '_ \\   / __|  / _ \\", 9)
  294.                     cWrite(" | |_) | | (_| | | | | (_| | | | | | | (__  |  __/", 10)
  295.                     cWrite(" |____/   \\__,_| |_|  \\__,_| |_| |_|  \\___|  \\___|", 11)
  296.                     cWrite("--------------------------------------------------", 12)
  297.                     cWrite("Current balance", 14)
  298.                     cWrite("$"..currentBalance, 16)
  299.                     drawButton(3, 16, 18, 18, "bGreen", "tOrange", "Withdraw")
  300.                     drawButton(33, 16, 49, 18, "bGreen", "tOrange", "Deposit")
  301.                     api.send(api.getMaster(), "error ContinueBalance after IF = ".. tostring(continueBalance))
  302.                 end
  303.             elseif balanceWithdraw then
  304.  
  305.             elseif balanceDeposit then
  306.  
  307.             elseif not loggedBalance and loggedSettings then
  308.             elseif loggedSettings and loggedBalance then
  309.                 loggedBalance = false
  310.                 loggedSettings = false
  311.                 error("loggedSettings and loggedBalance is both set to TRUE", 2)
  312.             end
  313.         end
  314.         sleep(1)
  315.     end
  316. end
  317.  
  318. function main()
  319.     reset()
  320.     while true do
  321.         local event, button, xP, yP = pull("mouse_click")
  322.         if button == 1 then
  323.             if doStartMenu then
  324.                 if xP >= 20 and xP <= 30 and yP >= 8 and yP <= 10 then
  325.                     doStartMenu = false
  326.                     doLogin = true
  327.                 elseif xP >= 18 and xP <= 32 and yP >= 14 and yP <= 16 then
  328.                     doStartMenu = false
  329.                     doCreate = true
  330.                 end
  331.             elseif not doLogin then
  332.                 if loggedMenu then
  333.                     if xP >= 15 and xP <= 35 and yP >= 12 and yP <= 14 then
  334.                         api.send(api.getMaster(), "error BalanceButtonClicked")
  335.                         accountMenu = false
  336.                         loggedBalance = true
  337.                         continueBalance = true
  338.                         loggedSettings = false
  339.                         api.send(api.getMaster(), "error Acc = "..tostring(accountMenu).." \nloggedBalance = "..tostring(loggedBalance).."\nloggedSettings = "..tostring(loggedSettings))
  340.                     elseif xP >= 20 and xP <= 30 and yP >= 17 and yP <= 19 then
  341.                         api.send(api.getMaster(), "error SettingsButtonClicked")
  342.                         loggedSettings = true
  343.                         loggedBalance = false
  344.                     else
  345.                         api.send(api.getMaster(), "error NoButtons Clicked")   
  346.                     end
  347.                 elseif loggedSettings then
  348.                 elseif loggedBalance then
  349.                     if continueBalance then
  350.                         if xP >= 3 and xP <= 18 and yP >= 16 and yP <= 18 then
  351.                             loggedSettings = false
  352.                             balanceWithdraw = true
  353.  
  354.                         elseif xP >= 33 and xP <= 49 and yP >= 16 and yP <= 18 then
  355.                             loggedSettings = false
  356.                             balanceDeposit = true
  357.  
  358.                         end
  359.                     elseif not continueBalance then
  360.                         if balanceWithdraw then
  361.  
  362.                         elseif balanceDeposit then
  363.  
  364.                         end
  365.                     end
  366.                 end
  367.             elseif doCreate then
  368.  
  369.             end
  370.         end
  371.     end
  372. end
  373.  
  374. parallel.waitForAll(main, screen)
  375. --screen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement