infiniteblock

Untitled

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