Advertisement
infiniteblock

Untitled

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