Advertisement
Doug4347

Server

Aug 11th, 2017
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.12 KB | None | 0 0
  1. serverID = 0
  2.  
  3. creditItem = "CreditBill50"
  4.  
  5. creditPerItem = 50
  6.  
  7. depositExtractor = 18
  8. bankDepositer = 19
  9. bankExtractor = 20
  10.  
  11. withdrawalExtractor = 21
  12.  
  13. depositBox = peripheral.wrap("chest_1")
  14. bankBox = peripheral.wrap("chest_3")
  15.  
  16. depositSize = tonumber(depositBox.getInventorySize())
  17. bankSize = tonumber(bankBox.getInventorySize())
  18.  
  19. peripherals = peripheral.getNames()
  20. periph = true
  21. index = 1
  22. while periph do
  23.     periph = peripherals[index]
  24.     if periph then
  25.         periphType = peripheral.getType(periph)
  26.         if periphType == "modem" then
  27.             rednet.open(periph)
  28.         end
  29.     end
  30.     index = index + 1
  31. end
  32.  
  33. local info = { ... }
  34.  
  35. while true do
  36.     shell.run("clear")
  37.     print("Please enter one of the following options:")
  38.     print("Withdraw")
  39.     print("Deposit")
  40.     print("View Balance")
  41.     print("Transfer")
  42.     print("Register")
  43.     option = read()
  44.     info[1] = option
  45.     if option == "Register" then
  46.         shell.run("clear")
  47.         print("Please enter a username:")
  48.         info[2] = read()
  49.         if info[2] then
  50.             print("Please enter a password:")
  51.             info[3] = read('*')
  52.             if info[3] then
  53.                 rednet.send(serverID, info, "reg")
  54.                 id, servInfo, servProtocol = rednet.receive()
  55.                 if servProtocol == "failure" then
  56.                     print("Failed to register new account. Reason:")
  57.                     print(servInfo[1])
  58.                     os.sleep(5)
  59.                 else
  60.                     print("Account successfully registered.")
  61.                     os.sleep(5)
  62.                 end
  63.             else
  64.                 print("Please try again and enter a vaild password.")
  65.                 os.sleep(5)
  66.             end
  67.         else
  68.             print("Please try again and enter a vaild username.")
  69.             os.sleep(5)
  70.         end
  71.     elseif (option == "Withdraw") or (option == "Deposit") or (option == "View Balance") or (option == "Transfer") then
  72.         shell.run("clear")
  73.         print("Please enter your username:")
  74.         info[2] = read()
  75.         print("Please enter your password:")
  76.         info[3] = read('*')
  77.         rednet.send(serverID, info, "login")
  78.         id, servInfo, servProtocol = rednet.receive()
  79.         if servProtocol == "success" then
  80.             loggedIn = true
  81.         else
  82.             print("Failed to log in. Reason:")
  83.             print(servInfo[1])
  84.             sleep(5)
  85.         end
  86.     else
  87.         print("Please enter a vaild option.")
  88.         sleep(5)
  89.     end
  90.     if loggedIn then
  91.         loggedIn = false
  92.         if option == "Withdraw" then
  93.             info[1] = "View Balance"
  94.             rednet.send(serverID, info, "balCheck")
  95.             id, servInfo, servProtocol = rednet.receive()
  96.             Bal = servInfo[1]
  97.             info[1] = "Withdraw"
  98.             print("Please enter the amount you wish to withdraw (must be multiples of ยง".. creditPerItem.. ":")
  99.             withdrawalAmount = read()
  100.             if withdrawalAmount > Bal then
  101.                 print("Sorry, but you do not have that amount in your bank account. Your current balance is: ยง".. Bal)
  102.             else
  103.                 newBal = Bal - withdrawalAmount
  104.                 info[4] = newBal
  105.                 rednet.send(serverID, info, "withdrawal")
  106.                 info2 = withdrawalAmount/creditPerItem
  107.                 rednet.send(withdrawalExtractor, info2, "withdrawal")
  108.                 print("Your withdrawl was successful, thank you for banking with us.")
  109.             end
  110.         elseif option == "Deposit" then
  111.             info[1] = "View Balance"
  112.             rednet.send(serverID, info, "balCheck")
  113.             id, servInfo, servProtocol = rednet.receive()
  114.             oldBal = servInfo[1]
  115.             info[1] = "Deposit"
  116.             shell.run("clear")
  117.             print("Please place the items in the chest to the right.")
  118.             while not itemsInDepositBox do
  119.                 totalQty = 0
  120.                 loop = 0
  121.                 while loop < depositSize do
  122.                     loop = loop + 1
  123.                     num = depositBox.getStackInSlot(loop)
  124.                     if num ~= nil then
  125.                         if num.name == creditItem then
  126.                             totalQty = totalQty + num.qty
  127.                         end
  128.                     end
  129.                     if totalQty > 0 then
  130.                         itemsInDepositBox = true
  131.                     end
  132.                     os.sleep(0.1)
  133.                 end
  134.                 os.sleep(0.1)
  135.             end
  136.             rednet.send(depositExtractor, "true")
  137.             shell.run("clear")
  138.             print("Transfering items, please wait...")
  139.             while itemsInDepositBox do
  140.                 loop = 0
  141.                 totalQty = 0
  142.                 while loop < depositSize do
  143.                     loop = loop + 1
  144.                     num = depositBox.getStackInSlot(loop)
  145.                     if num ~= nil then
  146.                         if num.name == creditItem then
  147.                             totalQty = totalQty + num.qty
  148.                         end
  149.                     end
  150.                     if totalQty == 0 then
  151.                         loop = 0
  152.                         while loop < depositSize do
  153.                             loop = loop + 1
  154.                             num = depositBox.getStackInSlot(loop)
  155.                             if num ~= nil then
  156.                                 if num.name == creditItem then
  157.                                     totalQty = totalQty + num.qty
  158.                                 end
  159.                             end
  160.                         end
  161.                         if totalQty == 0 then
  162.                             itemsInDepositBox = false
  163.                         end
  164.                     end
  165.                     os.sleep(0.1)
  166.                 end
  167.                 os.sleep(0.1)
  168.             end
  169.             rednet.send(depositExtractor, "false")
  170.             os.sleep(10)
  171.             totalQty = 0
  172.             loop = 0
  173.             while loop < bankSize do
  174.                 loop = loop + 1
  175.                 num = bankBox.getStackInSlot(loop)
  176.                 if num ~= nil then
  177.                     if num.name == creditItem then
  178.                         totalQty = totalQty + num.qty
  179.                     end
  180.                 end
  181.             end
  182.             shell.run("clear")
  183.             print("Doing the math...")
  184.             addedCredit = creditPerItem*totalQty
  185.             newBal = oldBal + addedCredit
  186.             shell.run("clear")
  187.             print("ecoATM has counted ".. totalQty.. " Items, and your account will be credited with ยง".. addedCredit.. " credits, is this correct? (y/n)")
  188.             invalidInput = true
  189.             while invalidInput do
  190.                 ATMInput = read()
  191.                 if ATMInput == "y" or ATMInput == "n" then
  192.                     invalidInput = false
  193.                 else
  194.                     print("Invalid input, please enter either \"n\" (No) or \"y\" (Yes) to continue.")
  195.                 end
  196.             end
  197.             if ATMInput == "y" then
  198.                 info[4] = addedCredit
  199.                 info[5] = newBal
  200.                 rednet.send(serverID, info, "deposit")
  201.                 id, servInfo, servProtocol = rednet.receive()
  202.                 print("Your final balance is: $".. newBal)
  203.                 print("Thank you for banking with us.")
  204.                 rednet.send(bankDepositer, "true")
  205.                 itemsInBankBox = true
  206.                 while itemsInBankBox do
  207.                     loop = 0
  208.                     totalQty = 0
  209.                     while loop < bankSize do
  210.                         loop = loop + 1
  211.                         num = bankBox.getStackInSlot(loop)
  212.                         if num ~= nil then
  213.                             if num.name == creditItem then
  214.                                 totalQty = totalQty + num.qty
  215.                             end
  216.                         end
  217.                         if totalQty == 0 then
  218.                             loop = 0
  219.                             while loop < bankSize do
  220.                                 loop = loop + 1
  221.                                 num = bankBox.getStackInSlot(loop)
  222.                                 if num ~= nil then
  223.                                     if num.name == creditItem then
  224.                                         totalQty = totalQty + num.qty
  225.                                     end
  226.                                 end
  227.                             end
  228.                             if totalQty == 0 then
  229.                                 itemsInBankBox = false
  230.                             end
  231.                         end
  232.                         os.sleep(0.1)
  233.                     end
  234.                     os.sleep(0.1)
  235.                 end
  236.                 rednet.send(bankDepositer, "false")
  237.             else
  238.                 print("Transaction canceled, refunding now.")
  239.                 rednet.send(bankExtractor, "true")
  240.                 itemsInBankBox = true
  241.                 while itemsInBankBox do
  242.                     loop = 0
  243.                     totalQty = 0
  244.                     while loop < bankSize do
  245.                         loop = loop + 1
  246.                         num = bankBox.getStackInSlot(loop)
  247.                         if num ~= nil then
  248.                             if num.name == creditItem then
  249.                                 totalQty = totalQty + num.qty
  250.                             end
  251.                         end
  252.                         if totalQty == 0 then
  253.                             loop = 0
  254.                             while loop < bankSize do
  255.                                 loop = loop + 1
  256.                                 num = bankBox.getStackInSlot(loop)
  257.                                 if num ~= nil then
  258.                                     if num.name == creditItem then
  259.                                         totalQty = totalQty + num.qty
  260.                                     end
  261.                                 end
  262.                             end
  263.                             if totalQty == 0 then
  264.                                 itemsInBankBox = false
  265.                             end
  266.                         end
  267.                         os.sleep(0.1)
  268.                     end
  269.                     os.sleep(0.1)
  270.                 end
  271.                 os.sleep(5)
  272.                 rednet.send(bankExtractor, "false")
  273.                 print("Successfully refunded. We hope to see you again soon!")
  274.             end
  275.            
  276.         elseif option == "View Balance" then
  277.             shell.run("clear")
  278.             rednet.send(serverID, info, "balCheck")
  279.             id, servInfo, servProtocol = rednet.receive()
  280.             print("User: ".. info[2])
  281.             print("Bal : ยง".. servInfo[1])
  282.             os.sleep(5)
  283.         elseif option == "Transfer" then
  284.             shell.run("clear")
  285.             print("Please enter the name of the account you would like to send money to:")
  286.             sendAcc = read()
  287.             print("Please enter the amount of money you would like to send:")
  288.             sendAmount = read()
  289.             info[4] = sendAcc
  290.             info[5] = sendAmount
  291.             rednet.send(serverID, info, "transfer")
  292.             id, servInfo, servProtocol = rednet.receive()
  293.             if servProtocol == "failure" then
  294.                 print("Failed to send funds. Reason:")
  295.                 print(servInfo[1])
  296.             else
  297.                 print("Successfully transfered all funds.")
  298.             end
  299.         end
  300.         os.sleep(5)
  301.     end
  302. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement