Advertisement
Guest User

startup

a guest
Apr 25th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.99 KB | None | 0 0
  1. -- Load API
  2. os.loadAPI("sha256")
  3. os.loadAPI("gui")
  4.  
  5. local textStart = gui.textStart
  6. local diskSide = "bottom"
  7. local serverId = 3
  8. local withdrawId = 14
  9. local version = "GAB-0.1"
  10. local url = "http://147.135.59.131/index.php"
  11.  
  12. -- Import GUI functions
  13. local drawHeader, drawButtons, drawButton, drawError, center = gui.drawHeader, gui.drawButtons, gui.drawButton, gui.drawError, gui.center
  14. local waitForMouse, waitForButton, waitForChar, waitForKey, waitForEnter = gui.waitForMouse, gui.waitForButton, gui.waitForChar, gui.waitForKey, gui.waitForEnter
  15. local waitForDisk = gui.waitForDisk
  16.  
  17. function otherAmount()
  18.     local amount = ""
  19.     term.clear()    drawHeader()
  20.     term.setCursorPos(center(textStart, "Amount : $   ") + 12, textStart)
  21.     return read()
  22. end
  23.  
  24. function balance(acc, pin)
  25.     term.clear()    drawHeader()    drawButtons()
  26.  
  27.     drawButton(4, "Cancel")
  28.     drawButton(5, "Galleon Dollars")
  29.  
  30.     local mult = nil
  31.     while true do
  32.         local button = waitForButton()
  33.         if     button == 4 then        return
  34.         elseif button == 5 then        mult = 1        break
  35.         end
  36.     end
  37.  
  38.     request = http.post(url, "command="..textutils.urlEncode(tostring("balance")).."&".."username="..textutils.urlEncode(tostring(acc)))--.."&".."password="..textutils.urlEncode(tostring(crypt.hashPassword(pin))))
  39.     response = request.readAll()
  40.     term.clear()    drawHeader()    drawButtons()
  41.     drawButton(8, "OK")
  42.  
  43.     if response ~= "-" then
  44.         local displayBalance = math.floor(tonumber(response) * mult * 100) / 100
  45.         center(textStart, "Balance: $" .. displayBalance .. " Galleons.")
  46.     else
  47.         drawError("Transaction Error")
  48.     end
  49.  
  50.     while true do
  51.         local button = waitForButton()
  52.         if     button == 8 then        return        end
  53.     end
  54. end
  55.  
  56. function deposit(acc, pin)
  57.     term.clear()    drawHeader()    drawButtons()
  58.  
  59.     drawButton(4, "Cancel")
  60.  
  61.     local mult = nil
  62.     --while true do
  63.      --   local button = waitForButton()
  64.       --  if     button == 4 then        return
  65.        -- end
  66.    -- end
  67.  
  68.     request = http.post(url, "command="..textutils.urlEncode(tostring("deposit")).."&".."username="..textutils.urlEncode(tostring(acc)))
  69.     response = request.readAll()
  70.     term.clear()    drawHeader()    drawButtons()
  71.     drawButton(8, "OK")
  72.        redstone.setOutput("back",true)
  73.     center(textStart, "Now Accepting:")
  74.     center(textStart + 1, "Gold Blocks, Ingots, Nuggets ")
  75.     center(textStart + 2, "Please Close Terminal.")
  76.        center(textStart + 3, "Then drop stacks of items ONLY")
  77. sleep(10)
  78.   --  if response ~= "-" then
  79.        -- local displayBalance = math.floor(tonumber(response) * mult * 100) / 100
  80.         --center(textStart, "Balance: $" .. displayBalance .. " Galleons.")
  81.   --  else
  82.   --      drawError("Transaction Error")
  83.    -- end
  84.  
  85.     while true do
  86.         local button = waitForButton()
  87.         if     button == 8 then  redstone.setOutput("back",false)      return        end
  88.     end
  89. end
  90.  
  91. function transfer(acc, pin)
  92.     term.clear()    drawHeader()    drawButtons()
  93.  
  94.     drawButton(1, "$100")
  95.     drawButton(2, "$200")
  96.     drawButton(3, "$500")
  97.     drawButton(5, "$1000")
  98.     drawButton(6, "$2000")
  99.     drawButton(7, "$5000")
  100.  
  101.     drawButton(4, "Cancel")
  102.     drawButton(8, "Other Amount")
  103.  
  104.     local amountS = nil
  105.     while true do
  106.         local button = waitForButton()
  107.         if     button == 1 then        amountS = "100"            break
  108.         elseif button == 2 then        amountS = "200"            break
  109.         elseif button == 3 then        amountS = "500"            break
  110.         elseif button == 5 then        amountS = "1000"        break
  111.         elseif button == 6 then        amountS = "2000"        break
  112.         elseif button == 7 then        amountS = "5000"        break
  113.         elseif button == 4 then        return
  114.         elseif button == 8 then        amountS = otherAmount()    break
  115.         end
  116.     end
  117.  
  118.     term.clear()    drawHeader()    drawButtons()
  119.  
  120.     local amount = tonumber(amountS)
  121.     if amount ~= nil and (amount % 1) == 0 then
  122.         term.clear()    drawHeader()
  123.         term.setCursorPos(center(textStart, "Amount : $   ") + 12, textStart)
  124.         term.write(amountS)
  125.         term.setCursorPos(center(textStart + 1, "Account :        ") + 10, textStart + 1)
  126.         local account = read()
  127.  
  128.         drawButtons()
  129.         drawButton(4, "Cancel")
  130.         drawButton(8, "Confirm")
  131.  
  132.         while true do
  133.             local button = waitForButton()
  134.             if     button == 4 then        return
  135.             elseif button == 8 then        break
  136.             end
  137.         end
  138.  
  139.         --local senderId, response = nil, nil
  140.         --rednet.open(modemSide)
  141.  
  142. --        rednet.send(serverId, version .. textutils.serialize( { "TRANSFER", acc, crypt.hashPassword(pin), account, amountS } ) )
  143.  
  144. --        while true do
  145.   --          senderId, response = rednet.receive(5)
  146.     --        if senderId == serverId then    break    end
  147.       --  end
  148.        -- rednet.close(modemSide)
  149. --        request = http.post(url, "command="..textutils.urlEncode(tostring("transfer")).."&".."username="..textutils.urlEncode(tostring(acc)).."&".."password="..textutils.urlEncode(tostring(sha256.sha256(pin)).."&".."account="..textutils.urlEncode(tostring(account)).."&".."amountS="..textutils.urlEncode(tostring(amountS))))
  150. request = http.post(url,"command="..textutils.urlEncode(tostring("trans")).."&".."username="..textutils.urlEncode(tostring(acc)).."&".."account="..textutils.urlEncode(tostring(account)).."&".."amount="..textutils.urlEncode(tostring(amount)).."&".."password="..textutils.urlEncode(tostring(sha256.sha256(pin))))
  151.                 term.clear()    drawHeader()    drawButtons()
  152.  response = request.readAll()
  153.         if response == "sendok" then
  154.             center(textStart, "Transfer Successful")
  155.         else
  156.             drawError("Transaction Error")
  157.         end
  158.  
  159.     else
  160.         term.clear()    drawHeader()    drawButtons()
  161.         drawError("Invalid Amount")
  162.  
  163.         --[[
  164.         while true do
  165.             local button = waitForButton()
  166.             if     button == 8 then        return        end
  167.         end
  168.         --]]
  169.     end
  170.  
  171.     drawButton(8, "OK")
  172.     while true do
  173.         local button = waitForButton()
  174.         if     button == 8 then        return        end
  175.     end
  176. end
  177.  
  178. function withdraw(acc, pin)
  179.     term.clear()    drawHeader()    drawButtons()
  180.  
  181.     drawButton(1, "$100")
  182.     drawButton(2, "$200")
  183.     drawButton(3, "$500")
  184.     drawButton(5, "$1000")
  185.     drawButton(6, "$2000")
  186.     drawButton(7, "$5000")
  187.  
  188.     drawButton(4, "Cancel")
  189.     drawButton(8, "Other Amount")
  190.  
  191.     local amountS = nil
  192.     while true do
  193.         local button = waitForButton()
  194.         if     button == 1 then        amountS = "100"            break
  195.         elseif button == 2 then        amountS = "200"            break
  196.         elseif button == 3 then        amountS = "500"            break
  197.         elseif button == 5 then        amountS = "1000"        break
  198.         elseif button == 6 then        amountS = "2000"        break
  199.         elseif button == 7 then        amountS = "5000"        break
  200.         elseif button == 4 then        return
  201.         elseif button == 8 then        amountS = otherAmount()    break
  202.         end
  203.     end
  204.  
  205.     term.clear()    drawHeader()    drawButtons()
  206.  
  207.     local amount = tonumber(amountS)
  208.     if amount ~= nil and (amount % 100) == 0 then
  209.         term.clear()    drawHeader()
  210.         term.setCursorPos(center(textStart, "Amount : MC$   ") + 12, textStart)
  211.         term.write(amountS)
  212.         drawButtons()
  213.         drawButton(4, "Cancel")
  214.         drawButton(8, "Confirm")
  215.  
  216.         while true do
  217.             local button = waitForButton()
  218.             if     button == 4 then        return
  219.             elseif button == 8 then        break
  220.             end
  221.         end
  222.  
  223.         local senderId, response = nil, nil
  224.         rednet.open(modemSide)
  225.  
  226.         rednet.send(serverId, version .. textutils.serialize( { "WITHDRAW", acc, crypt.hashPassword(pin), amountS } ) )
  227.  
  228.         while true do
  229.             senderId, response = rednet.receive(5)
  230.             if senderId == serverId then    break    end
  231.         end
  232.         rednet.close(modemSide)
  233.  
  234.         term.clear()    drawHeader()
  235.  
  236.         if response ~= "-" then
  237.             center(textStart, "Withdrawing " .. (amount) .. " MC$")
  238.             rednet.open(modemSide)
  239.             rednet.send(withdrawId, version .. textutils.serialize( { "WITHDRAW", (amount) .. "" } ) )
  240.            
  241.             while true do
  242.                 senderId, response = rednet.receive(5)
  243.                 if senderId == withdrawId then    break    end
  244.             end
  245.             rednet.close(modemSide)
  246.            
  247.             term.clear()    drawHeader()
  248.             if response ~= "-" then
  249.                 center(textStart, "Please take your cash")
  250.                 sleep(2)
  251.                 return
  252.             else
  253.                 drawButtons()
  254.                 drawError("Withdrawal Error")
  255.             end
  256.         else
  257.             drawError("Transaction Error")
  258.         end
  259.  
  260.     else
  261.         term.clear()    drawHeader()    drawButtons()
  262.         drawError("Invalid Amount")
  263.  
  264.         --[[
  265.         while true do
  266.             local button = waitForButton()
  267.             if     button == 8 then        return        end
  268.         end
  269.         --]]
  270.     end
  271.  
  272.     drawButton(8, "OK")
  273.     while true do
  274.         local button = waitForButton()
  275.         if     button == 8 then        return        end
  276.     end
  277. end
  278.  
  279. function bank(acc, pin)
  280.     while true do
  281.         term.clear()    drawHeader()    drawButtons()
  282.  
  283.         drawButton(4, "Return Card")
  284.         drawButton(5, "Balance Check")
  285.         drawButton(6, "Withdrawal")
  286.         drawButton(7, "Deposit")
  287.         drawButton(8, "Transfer")
  288.  
  289.         local button = waitForButton()
  290.         if     button == 4 then        return
  291.         elseif button == 5 then        balance(acc, pin)
  292.         elseif button == 6 then        withdraw(acc, pin)
  293.         elseif button == 7 then        deposit(acc, pin)
  294.         elseif button == 8 then        transfer(acc, pin)
  295.         end
  296.     end
  297. end
  298.  
  299. function begin()
  300.     local acc, pin
  301.  
  302.      
  303.     term.clear()    drawHeader()
  304.     drawButtons()
  305.     drawButton(4, "Login")
  306.     drawButton(8, "Open Account")
  307.     while true do
  308.     local button = waitForButton()
  309.     if     button == 4 then        break
  310.     elseif button == 8 then        register()
  311.     end
  312. end
  313. --while true do
  314.         center(textStart, "Insert keycard or press ENTER")
  315.     center(textStart + 1, "to transact without a keycard")
  316.     parallel.waitForAny(waitForEnter, waitForDisk)
  317.  
  318.     term.clear()    drawHeader()
  319.  
  320.     term.setCursorPos(center(textStart, "Account No :           ") + 13, textStart)
  321. -- local button = waitForButton()
  322. -- if button == 4 then return
  323. -- elseif button == 8 then
  324. -- os.reboot()
  325. -- end
  326.     if disk.hasData(diskSide) then
  327.         acc = disk.getLabel(diskSide)
  328.         term.write(acc)
  329.     else
  330.         acc = read()
  331.     end
  332.  
  333.     term.setCursorPos(center(textStart + 1, "PIN :    ") + 6, textStart + 1)
  334.     pin = read("*")
  335.    
  336.     sleep(1)
  337.     request = http.post(url, "command="..textutils.urlEncode(tostring("login")).."&".."username="..textutils.urlEncode(tostring(acc)).."&".."password="..textutils.urlEncode(tostring(sha256.sha256(pin))))
  338.     response = request.readAll()
  339.  
  340.          term.clear()    drawHeader()
  341.  
  342.         if response == "true" then
  343.             bank(acc, pin)
  344.  
  345.              term.clear()    drawHeader()
  346.    
  347.     disk.eject(diskSide)
  348.     center(textStart, "Thank you for banking with GA")
  349.     center(textStart + 1, "Please take your keycard")
  350.  
  351.     sleep(6)
  352. os.reboot()
  353.     else
  354.         drawError("Login Error")
  355.         sleep(4)
  356.         os.reboot()
  357.     end
  358.  
  359.     while true do
  360.         local button = waitForButton()
  361.         if     button == 8 then       return        end
  362.     end
  363. end
  364.  
  365. while true do
  366.     begin()
  367. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement