infiniteblock

Untitled

Aug 28th, 2020
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.62 KB | None | 0 0
  1. -- Load API
  2. os.loadAPI("sha256")
  3. os.loadAPI("gui")
  4. mesData = {}
  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://infaknox.space/main.php"
  11. local all = "0123456789abcdefghijklmnopqrstuvwxyz"
  12. local e = ""
  13. -- Import GUI functions
  14. local drawHeader, drawButton, drawError, center = gui.drawHeader, gui.drawButton, gui.drawError, gui.center
  15. local waitForMouse, waitForButton, waitForChar, waitForKey, waitForEnter =
  16.     gui.waitForMouse,
  17.     gui.waitForButton,
  18.     gui.waitForChar,
  19.     gui.waitForKey,
  20.     gui.waitForEnter
  21. local waitForDisk = gui.waitForDisk
  22. -- Withdrawal Amount
  23. function otherAmount()
  24.     local amount = ""
  25.     term.clear()
  26.     drawHeader()
  27.     term.setCursorPos(center(textStart, "Amount : $   ") + 12, textStart)
  28.     return read()
  29. end
  30. -- MessageBoard
  31. function message(acc, pin)
  32.     while true do
  33.         term.clear()
  34.         drawHeader()
  35.         drawButton(4, "Post Message")
  36.         drawButton(8, "Return")
  37.         pos = 5
  38.         local a = http.get("http://infaknox.space/messages")
  39.         for line in a.readLine do
  40.             local location = (line:find(":", 1))
  41.             if location then
  42.                 local usr = line:sub(1, location - 1)
  43.                 local msg = line:sub(location + 1)
  44.                 pos = pos + 2
  45.                 term.setCursorPos(3, pos)
  46.                 term.write("Message: " .. usr)
  47.                 term.setCursorPos(3, pos + 1)
  48.                 term.write("By: " .. msg)
  49.             end
  50.         end
  51.         local button = waitForButton()
  52.         if button == 4 then
  53.             post(acc, pin)
  54.         elseif button == 8 then
  55.             return
  56.         end
  57.     end
  58. end
  59. -- Balance
  60. function balance(acc, pin)
  61.     term.clear()
  62.     drawHeader()
  63.  
  64.     drawButton(4, "Cancel")
  65.     drawButton(5, "Galleon Dollars")
  66.  
  67.     local mult = nil
  68.     while true do
  69.         local button = waitForButton()
  70.         if button == 4 then
  71.             return
  72.         elseif button == 5 then
  73.             mult = 1
  74.             break
  75.         end
  76.     end
  77.  
  78.     request =
  79.         http.post(
  80.         url,
  81.         "command=" ..
  82.             textutils.urlEncode(tostring("balance")) .. "&" .. "username=" .. textutils.urlEncode(tostring(acc))
  83.     )
  84.      --.."&".."password="..textutils.urlEncode(tostring(crypt.hashPassword(pin))))
  85.     response = request.readAll()
  86.     term.clear()
  87.     drawHeader()
  88.     drawButton(8, "OK")
  89.  
  90.     if response ~= "-" then
  91.         local displayBalance = math.floor(tonumber(response) * mult * 100) / 100
  92.         center(textStart, "Balance: $" .. displayBalance .. " Galleons.")
  93.     else
  94.         drawError("Transaction Error")
  95.     end
  96.  
  97.     while true do
  98.         local button = waitForButton()
  99.         if button == 8 then
  100.             return
  101.         end
  102.     end
  103. end
  104. -- Registration
  105. function register()
  106.     local accname, accpin
  107.  
  108.     term.clear()
  109.     drawHeader()
  110.  
  111.     center(textStart, "Insert keycard or press ENTER")
  112.     center(textStart + 1, "to transact without a keycard")
  113.     parallel.waitForAny(waitForEnter, waitForDisk)
  114.  
  115.     term.clear()
  116.     drawHeader()
  117.     for i = 1, 10 do
  118.         r = math.random(#all)
  119.         e = e .. string.sub(all, r, r)
  120.     end
  121.     term.setCursorPos(center(textStart, "Account No : " .. e .. "") + 13, textStart)
  122.  
  123.     accname = e
  124.     if disk.hasData(diskSide) then
  125.         disk.setLabel(diskSide, accname)
  126.     else
  127.     end
  128.     term.setCursorPos(center(textStart + 1, "PIN :    ") + 6, textStart + 1)
  129.     accpin = read("*")
  130.     request =
  131.         http.post(
  132.         url,
  133.         "command=" ..
  134.             textutils.urlEncode(tostring("register")) ..
  135.                 "&" ..
  136.                     "username=" ..
  137.                         textutils.urlEncode(tostring(e)) ..
  138.                             "&" .. "password=" .. textutils.urlEncode(tostring(sha256.sha256(accpin)))
  139.     )
  140.     response = request.readAll()
  141.     term.clear()
  142.     drawHeader()
  143.     drawButton(8, "OK")
  144.  
  145.     if response == "Saved!" then
  146.         center(textStart, "Added User: " .. accname .. "")
  147.         sleep(3)
  148.         disk.eject(diskSide)
  149.         os.reboot()
  150.     else
  151.         drawError("ERROR")
  152.     end
  153.  
  154.     while true do
  155.         local button = waitForButton()
  156.         if button == 8 then
  157.             return
  158.         end
  159.     end
  160. end
  161. -- Deposit System
  162. function deposit(acc, pin)
  163.     term.clear()
  164.     drawHeader()
  165.  
  166.     drawButton(4, "Cancel")
  167.  
  168.     local mult = nil
  169.     request =
  170.         http.post(
  171.         url,
  172.         "command=" ..
  173.             textutils.urlEncode(tostring("deposit")) .. "&" .. "username=" .. textutils.urlEncode(tostring(acc))
  174.     )
  175.     response = request.readAll()
  176.     term.clear()
  177.     drawHeader()
  178.     drawButton(8, "OK")
  179.     redstone.setOutput("back", true)
  180.     center(textStart, "Now Accepting:")
  181.     center(textStart + 1, "Gold Blocks, Ingots, Nuggets ")
  182.     center(textStart + 2, "Please Close Terminal.")
  183.     center(textStart + 3, "Then drop stacks of items ONLY")
  184.     sleep(10)
  185.     --  if response ~= "-" then
  186.     -- local displayBalance = math.floor(tonumber(response) * mult * 100) / 100
  187.     --center(textStart, "Balance: $" .. displayBalance .. " Galleons.")
  188.     --  else
  189.     --      drawError("Transaction Error")
  190.     -- end
  191.  
  192.     while true do
  193.         local button = waitForButton()
  194.         if button == 8 then
  195.             redstone.setOutput("back", false)
  196.             return
  197.         end
  198.     end
  199. end
  200. -- Money Transfer
  201. function transfer(acc, pin)
  202.     term.clear()
  203.     drawHeader()
  204.     drawButton(1, "$100")
  205.     drawButton(2, "$200")
  206.     drawButton(3, "$500")
  207.     drawButton(5, "$1000")
  208.     drawButton(6, "$2000")
  209.     drawButton(7, "$5000")
  210.     drawButton(4, "Cancel")
  211.     drawButton(8, "Other Amount")
  212.  
  213.     local amountS = nil
  214.     while true do
  215.         local button = waitForButton()
  216.         if button == 1 then
  217.             amountS = "100"
  218.             break
  219.         elseif button == 2 then
  220.             amountS = "200"
  221.             break
  222.         elseif button == 3 then
  223.             amountS = "500"
  224.             break
  225.         elseif button == 5 then
  226.             amountS = "1000"
  227.             break
  228.         elseif button == 6 then
  229.             amountS = "2000"
  230.             break
  231.         elseif button == 7 then
  232.             amountS = "5000"
  233.             break
  234.         elseif button == 4 then
  235.             return
  236.         elseif button == 8 then
  237.             amountS = otherAmount()
  238.             break
  239.         end
  240.     end
  241.  
  242.     term.clear()
  243.     drawHeader()
  244.  
  245.     local amount = tonumber(amountS)
  246.     if amount ~= nil and (amount % 1) == 0 then
  247.         term.clear()
  248.         drawHeader()
  249.         term.setCursorPos(center(textStart, "Amount : $   ") + 12, textStart)
  250.         term.write(amountS)
  251.         term.setCursorPos(center(textStart + 1, "Account :        ") + 10, textStart + 1)
  252.         local account = read()
  253.  
  254.         drawButton(4, "Cancel")
  255.         drawButton(8, "Confirm")
  256.  
  257.         while true do
  258.             local button = waitForButton()
  259.             if button == 4 then
  260.                 return
  261.             elseif button == 8 then
  262.                 break
  263.             end
  264.         end
  265.         request =
  266.             http.post(
  267.             url,
  268.             "command=" ..
  269.                 textutils.urlEncode(tostring("trans")) ..
  270.                     "&" ..
  271.                         "username=" ..
  272.                             textutils.urlEncode(tostring(acc)) ..
  273.                                 "&" ..
  274.                                     "account=" ..
  275.                                         textutils.urlEncode(tostring(account)) ..
  276.                                             "&" ..
  277.                                                 "amount=" ..
  278.                                                     textutils.urlEncode(tostring(amount)) ..
  279.                                                         "&" ..
  280.                                                             "password=" ..
  281.                                                                 textutils.urlEncode(tostring(sha256.sha256(pin)))
  282.         )
  283.         term.clear()
  284.         drawHeader()
  285.         response = request.readAll()
  286.         if response == "sendok" then
  287.             center(textStart, "Transfer Successful")
  288.         else
  289.             drawError("Transaction Error")
  290.         end
  291.     else
  292.         term.clear()
  293.         drawHeader()
  294.         drawError("Invalid Amount")
  295.     end
  296.  
  297.     drawButton(8, "OK")
  298.     while true do
  299.         local button = waitForButton()
  300.         if button == 8 then
  301.             return
  302.         end
  303.     end
  304. end
  305. -- Withdrawal
  306. function withdraw(acc, pin)
  307.     term.clear()
  308.     drawHeader()
  309.  
  310.     drawButton(1, "$100")
  311.     drawButton(2, "$200")
  312.     drawButton(3, "$500")
  313.     drawButton(5, "$1000")
  314.     drawButton(6, "$2000")
  315.     drawButton(7, "$5000")
  316.  
  317.     drawButton(4, "Cancel")
  318.     drawButton(8, "Other Amount")
  319.  
  320.     local amountS = nil
  321.     while true do
  322.         local button = waitForButton()
  323.         if button == 1 then
  324.             amountS = "100"
  325.             break
  326.         elseif button == 2 then
  327.             amountS = "200"
  328.             break
  329.         elseif button == 3 then
  330.             amountS = "500"
  331.             break
  332.         elseif button == 5 then
  333.             amountS = "1000"
  334.             break
  335.         elseif button == 6 then
  336.             amountS = "2000"
  337.             break
  338.         elseif button == 7 then
  339.             amountS = "5000"
  340.             break
  341.         elseif button == 4 then
  342.             return
  343.         elseif button == 8 then
  344.             amountS = otherAmount()
  345.             break
  346.         end
  347.     end
  348.  
  349.     term.clear()
  350.     drawHeader()
  351.  
  352.     local amount = tonumber(amountS)
  353.     if amount ~= nil and (amount % 100) == 0 then
  354.         term.clear()
  355.         drawHeader()
  356.         term.setCursorPos(center(textStart, "Amount : MC$   ") + 12, textStart)
  357.         term.write(amountS)
  358.         drawButton(4, "Cancel")
  359.         drawButton(8, "Confirm")
  360.  
  361.         while true do
  362.             local button = waitForButton()
  363.             if button == 4 then
  364.                 return
  365.             elseif button == 8 then
  366.                 break
  367.             end
  368.         end
  369.  
  370.         local senderId, response = nil, nil
  371.         rednet.open(modemSide)
  372.  
  373.         rednet.send(serverId, version .. textutils.serialize({"WITHDRAW", acc, crypt.hashPassword(pin), amountS}))
  374.  
  375.         while true do
  376.             senderId, response = rednet.receive(5)
  377.             if senderId == serverId then
  378.                 break
  379.             end
  380.         end
  381.         rednet.close(modemSide)
  382.  
  383.         term.clear()
  384.         drawHeader()
  385.  
  386.         if response ~= "-" then
  387.             center(textStart, "Withdrawing " .. (amount) .. " MC$")
  388.             rednet.open(modemSide)
  389.             rednet.send(withdrawId, version .. textutils.serialize({"WITHDRAW", (amount) .. ""}))
  390.  
  391.             while true do
  392.                 senderId, response = rednet.receive(5)
  393.                 if senderId == withdrawId then
  394.                     break
  395.                 end
  396.             end
  397.             rednet.close(modemSide)
  398.  
  399.             term.clear()
  400.             drawHeader()
  401.             if response ~= "-" then
  402.                 center(textStart, "Please take your cash")
  403.                 sleep(2)
  404.                 return
  405.             else
  406.                 drawError("Withdrawal Error")
  407.             end
  408.         else
  409.             drawError("Transaction Error")
  410.         end
  411.     else
  412.         term.clear()
  413.         drawHeader()
  414.         drawError("Invalid Amount")
  415.     end
  416.  
  417.     drawButton(8, "OK")
  418.     while true do
  419.         local button = waitForButton()
  420.         if button == 8 then
  421.             return
  422.         end
  423.     end
  424. end
  425. -- Main Menu
  426. function bank(acc, pin)
  427.     while true do
  428.         term.clear()
  429.         drawHeader()
  430.         drawButton(1, "Market")
  431.         drawButton(2, "Bounty")
  432.         drawButton(3, "Message Board")
  433.         drawButton(4, "Return Card")
  434.         drawButton(5, "Balance Check")
  435.         drawButton(6, "Withdrawal")
  436.         drawButton(7, "Deposit")
  437.         drawButton(8, "Transfer")
  438.  
  439.         local button = waitForButton()
  440.         if button == 1 then
  441.             market(acc, pin)
  442.         elseif button == 2 then
  443.             bounty(acc, pin)
  444.         elseif button == 3 then
  445.             message(acc, pin)
  446.         elseif button == 4 then
  447.             return
  448.         elseif button == 5 then
  449.             balance(acc, pin)
  450.         elseif button == 6 then
  451.             withdraw(acc, pin)
  452.         elseif button == 7 then
  453.             deposit(acc, pin)
  454.         elseif button == 8 then
  455.             transfer(acc, pin)
  456.         end
  457.     end
  458. end
  459. -- Login/Register Menu
  460. function begin()
  461.     local acc, pin
  462.  
  463.     term.clear()
  464.     drawHeader()
  465.     drawButton(4, "Login")
  466.     drawButton(8, "Open Account")
  467.     while true do
  468.         local button = waitForButton()
  469.         if button == 4 then
  470.             break
  471.         elseif button == 8 then
  472.             register()
  473.         end
  474.     end
  475.     center(textStart, "Insert keycard or press ENTER")
  476.     center(textStart + 1, "to transact without a keycard")
  477.     parallel.waitForAny(waitForEnter, waitForDisk)
  478.  
  479.     term.clear()
  480.     drawHeader()
  481.  
  482.     term.setCursorPos(center(textStart, "Account No :           ") + 13, textStart)
  483.     if disk.hasData(diskSide) then
  484.         acc = disk.getLabel(diskSide)
  485.         term.write(acc)
  486.     else
  487.         acc = read()
  488.     end
  489.  
  490.     term.setCursorPos(center(textStart + 1, "PIN :    ") + 6, textStart + 1)
  491.     pin = read("*")
  492.  
  493.     sleep(1)
  494.     request =
  495.         http.post(
  496.         url,
  497.         "command=" ..
  498.             textutils.urlEncode(tostring("login")) ..
  499.                 "&" ..
  500.                     "username=" ..
  501.                         textutils.urlEncode(tostring(acc)) ..
  502.                             "&" .. "password=" .. textutils.urlEncode(tostring(sha256.sha256(pin)))
  503.     )
  504.     if request == nil then
  505.         term.clear()
  506.         drawHeader()
  507.         drawError("Login Server Is DOWN!")
  508.         sleep(6)
  509.         os.reboot()
  510.     else
  511.         response = request.readAll()
  512.         term.clear()
  513.         drawHeader()
  514.  
  515.         if response == "true" then
  516.             bank(acc, pin)
  517.  
  518.             term.clear()
  519.             drawHeader()
  520.  
  521.             disk.eject(diskSide)
  522.             center(textStart, "Thank you for banking with GA")
  523.             center(textStart + 1, "Please take your keycard")
  524.  
  525.             sleep(6)
  526.             os.reboot()
  527.         else
  528.             drawError("Login Error")
  529.             sleep(4)
  530.             os.reboot()
  531.         end
  532.     end
  533.     while true do
  534.         local button = waitForButton()
  535.         if button == 8 then
  536.             return
  537.         end
  538.     end
  539. end
  540.  
  541. while true do
  542.     begin()
  543. end
  544.  
Add Comment
Please, Sign In to add comment