Guest User

bankClient1

a guest
May 5th, 2014
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.86 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2. rednet.open("left") --Modem side
  3. sId = 13 -- ServerId, Run id on your server computer to access
  4. os.loadAPI("crypt")
  5. local cbl = peripheral.wrap("top") --Command Block side
  6.  
  7. while true do
  8.   shell.run("clear")
  9.   if disk.hasData("bottom") == false then
  10.     while true do    
  11.       print("Please insert bank card")
  12.       if os.pullEvent("disk") then
  13.         break
  14.       end
  15.     end
  16.   elseif disk.hasData("bottom") == true then  
  17.     local acc = disk.getLabel("bottom")
  18.     shell.run("clear")
  19.     print("Welcome "..acc)    
  20.     print("Please enter your P.I.N.:")
  21.     pwd = read("*")
  22.     rednet.send(sId, textutils.serialize({"login", acc, crypt.hashPassword(pwd)}))
  23.     print("pwd sent")
  24.     id,msg = rednet.receive()
  25.     print("reply received")
  26.     local data = textutils.unserialize(msg)
  27.     local cmd = data[1]
  28.     local acc = data[name]
  29.     local bal = data[bal]
  30.     if cmd == "confirm" then
  31.       shell.run("clear")
  32.       print("Password accepted")
  33.       sleep(2)
  34.       while true do
  35.         shell.run("clear")
  36.         local opts = {}
  37.         local opts1 = "Balance Enquiry"
  38.         local opts2 = "Withdraw"
  39.         local opts3 = "Deposit"
  40.         local opts4 = "Transfer"
  41.         print("What would you like to do")
  42.         print("")
  43.         for a,b in ipairs(opts) do
  44.           print(tostring(a)..") "..tostring(b))
  45.         end      
  46.         local cmd = read()
  47.         if cmd == 1 or "Balance" or "balance" then
  48.           shell.run("clear")
  49.           print("Balance:")
  50.           print("$"..bal)
  51.         elseif cmd == 2 or "Withdraw" or "withdraw" then
  52.           shell.run("clear")
  53.           write("How much do you want to withdraw: $")
  54.           local amt = read()
  55.           print("Processing")
  56.           sleep(5)
  57.           if amt == bal or amt < bal then
  58.             shell.run("clear")
  59.             print("Confirm withdrawal of $"..amt.." from Acc: "..acc..": $"..bal.."?")
  60.             print("Y/N")
  61.             local cmd = read()        
  62.             if cmd == "Y" or "y" then
  63.               rednet.send(sId, textutils.serialize({"withdraw", acc, crypt.hashPassword(pwd), amt}))
  64.               local id, msg = rednet.receive()
  65.               local data = textutils.unserialize(msg)
  66.               if cmd == "confirm" then
  67.                 cbl.setCommand("eco give @p amt")
  68.                 cbl.runCommand()
  69.                 shell.run("clear")
  70.                 print("New balance:")
  71.                 print("$"..bal)
  72.                 sleep(5)
  73.               else
  74.                 shell.run("clear")
  75.                 print("We were unable to process this transaction please try again")
  76.                 sleep(3)
  77.               end
  78.             else
  79.               shell.run("clear")
  80.               print("Withdrawal cancelled")
  81.               sleep(3)
  82.             end
  83.           else
  84.             print("You do not have enough funds to complete this transaction")
  85.             sleep(3)
  86.           end
  87.         elseif cmd == 3 or "Deposit" or "deposit" then
  88.           shell.run("clear")        
  89.           write("How much do you want to deposit: $")
  90.           local amt = read()
  91.           print("Processing")
  92.           sleep(5)
  93.           shell.run("clear")
  94.           print("Confirm withdrawal of $"..amt.." from Acc: "..acc..": $"..bal.."?")
  95.           print("Y/N")
  96.           local cmd = read()        
  97.           if cmd == "Y" or "y" then
  98.             rednet.send(sId, textutils.serialize({"deposit", acc, crypt.hashPassword(pwd), amt}))
  99.             local id, msg = rednet.receive()
  100.             local data = textutils.unserialize(msg)
  101.             if cmd == "confirm" then
  102.               shell.run("clear")
  103.               print("Deposited $"..amt.." into "..acc.."'s account")
  104.               cbl.setCommand("eco take @p amt")
  105.               cbl.runCommand()
  106.               sleep(3)
  107.             else
  108.               shell.run("clear")
  109.               print("We were unable to process this transaction please try again")
  110.               sleep(3)
  111.             end
  112.           else
  113.             shell.run("clear")
  114.             print("Transaction cancelled")
  115.             sleep(3)
  116.           end
  117.         elseif cmd == 4 or "Transfer" or "transfer" then
  118.           shell.run("clear")
  119.           write("Type the account name you would like to transfer funds to: ")
  120.           local toAcc = read()
  121.           shell.run("clear")
  122.           write("Please enter the amount you wish to transfer: $")
  123.           local amt = read()
  124.           shell.run("clear")
  125.           print("Please confirm, you wish to transfer $"..amt.." from "..acc.." to "..toA.." Y/N")
  126.           local cmd = read()
  127.           shell.run("clear")
  128.           print("Processing")
  129.           sleep(3)
  130.           if cmd == "Y" or "y" then
  131.             if amt == bal or amt < bal then
  132.               rednet.send(sId, textutils.serialize({"transfer", acc, crypt.hashPassword(pwd), amt, toA}))
  133.               local id,msg = rednet.receive()
  134.               local data = textutils.unserialize(msg)
  135.               if cmd == "confirm" then
  136.                 shell.run("clear")
  137.                 print("$"..amt.." transferred to "..toA)
  138.                 sleep(3)
  139.               else
  140.                 shell.run("clear")
  141.                 print("We were unable to process this transaction please try again")
  142.                 sleep(3)
  143.               end
  144.             else
  145.               shell.run("clear")
  146.               print("You do not have enough funds to complete this transaction")
  147.               sleep(3)
  148.             end
  149.           else
  150.             shell.run("clear")
  151.             print("Transaction cancelled")
  152.             sleep(3)
  153.           end
  154.         else
  155.           sleep(10)
  156.           print("Took too long to make a selection, cancelling transaction")
  157.           sleep(3)
  158.           disk.eject("bottom")
  159.           break
  160.         end
  161.       end
  162.     else
  163.       print("Incorrect Password, Try Again")
  164.       sleep(5)
  165.     end
  166.   end
  167. end
Advertisement
Add Comment
Please, Sign In to add comment