infiniteblock

Untitled

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