Advertisement
Guest User

startup

a guest
Mar 23rd, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.24 KB | None | 0 0
  1. function clear()
  2. term.clear()
  3. term.setCursorPos(1,1)
  4. end
  5. User = " "
  6. ServerID = 13
  7. rednet.open("top")
  8. PINMachine = 33
  9.  
  10. function Menu()
  11. printMenu()
  12. input = read()
  13. if input == "4" then
  14.   createAccount()
  15. elseif input == "6" then
  16.   printLogin()
  17. elseif input == "5" then
  18.   closeAccount()
  19. elseif input == "1" then
  20.   accDeposit()
  21. elseif input == "2" then
  22.   accWithdraw()
  23. elseif input == "3" then
  24.   checkBalance()
  25. else
  26.   Menu()
  27. end
  28. end
  29. function printMenu()
  30. clear()
  31. print("Logged In: "..User)
  32. print()
  33. print("[1] Account Deposit")
  34. print("[2] Account Withdrawal")
  35. print("[3] Check Balance")
  36. print()
  37. print("[4] Open Account")
  38. print("[5] Close Account")
  39. print("[6] Log Out")
  40. print("-------------------------")
  41. print()
  42. write(">> ")
  43. end
  44.  
  45. function checkBalance()
  46. print("[1] Type Manually")
  47. print("[2] Insert Card")
  48. print()
  49. write(">> ")
  50. input = read()
  51. if input == "1" then
  52.   write("Account: ")
  53.   Acc = read()
  54. elseif input == "2" then
  55.   while not disk.isPresent("bottom") do sleep(0.01) end
  56.   Acc = disk.getLabel("bottom")
  57.   disk.eject("bottom")
  58. end
  59. rednet.send(ServerID, "ChkBal")
  60. rednet.send(ServerID, Acc)
  61. id, Bal = rednet.receive()
  62. tonumber(Bal)
  63. if Bal ~= "BalF" then
  64. print("Balance: D$"..Bal)
  65. sleep(3)
  66. Menu()
  67. elseif Bal == "BalF" then
  68. print("Invalid Acccount Number")
  69. sleep(2)
  70. Menu()
  71. end
  72. end
  73.  
  74. function accWithdraw()
  75.   print("[1] Type Manually")
  76.   print("[2] Insert Card")
  77.   print()
  78.   write(">> ")
  79.   input = read()
  80.   if input == "1" then
  81.   write("Account: ")
  82.   Ac = read()
  83.   elseif input == "2" then
  84.   while not disk.isPresent("bottom") do sleep(0.01) end
  85.   Ac = disk.getLabel("bottom")
  86.   print("Account: "..Ac)
  87.   end
  88.   rednet.send(PINMachine, "PIN")
  89.   id, PIN = rednet.receive()
  90.   write("Amount: D$")
  91.   Am = read()
  92.   rednet.send(ServerID, "AW")
  93.   rednet.send(ServerID, Ac)
  94.   rednet.send(ServerID, PIN)
  95.   rednet.send(ServerID, Am)
  96.   id, Co = rednet.receive()
  97.   if Co == "WiT" then
  98.     print("Withdrew D$"..Am)
  99.     sleep(2)
  100.     Menu()
  101.   elseif Co == "NB" then
  102.     print("Not Enough Funds")
  103.     sleep(2)
  104.     Menu()
  105.   elseif Co == "AcF" then
  106.     print("Account Does not Exist")
  107.     sleep(1)
  108.     Menu()
  109.   end
  110. end
  111.  
  112. function accDeposit()
  113.   print("[1] Type Manually")
  114.   print("[2] Insert Card")
  115.   print()
  116.   write(">> ")
  117.   input = read()
  118.   if input == "1" then
  119.     write("Account Number: ")
  120.     Card = read()
  121.   elseif input == "2" then
  122.     while not disk.isPresent("bottom") do sleep(0.01) end
  123.     Card = disk.getLabel("bottom")
  124.     disk.eject("bottom")
  125.     if Card ~= nil then
  126.     print("Account Number: "..Card)
  127.     else
  128.     print("Foreign Object Inserted")
  129.     sleep(3)
  130.     Menu()
  131.     end
  132.   end
  133.   write("Amount: ")
  134.   Am = read()
  135.   rednet.send(ServerID, "AD")
  136.   rednet.send(ServerID, Card)
  137.   rednet.send(ServerID, Am)
  138.   id, msg = rednet.receive()
  139.   if msg == "DT" then
  140.     print("Deposited D$"..Am.." to Account "..Card)
  141.     sleep(2)
  142.     Menu()
  143.   elseif msg == "DF" then
  144.     print("Invalid Account")
  145.     sleep(2)
  146.     Menu()
  147.   end
  148. end
  149.  
  150. function closeAccount()
  151.   print("Close Account")
  152.   print()
  153.   print("[1] Type Manually")
  154.   print("[2] Insert Card")
  155.   write(">> ")
  156.   input = read()
  157.   if input == "1" then
  158.   write("Account Number: ")
  159.   Card = read()
  160.   elseif input == "2" then
  161.     while not disk.isPresent("bottom") do sleep(0.01) end
  162.     Card = disk.getLabel("bottom")
  163.     print("Account Number: "..Card)
  164.     disk.eject("bottom")
  165.   else
  166.     closeAccount()
  167.   end
  168.   rednet.send(PINMachine, "PIN")
  169.   print("Tell the Customer to Enter their PIN")
  170.   id, PIN = rednet.receive()    
  171.   rednet.send(ServerID, "RA")
  172.   rednet.send(ServerID, Card)
  173.   rednet.send(ServerID, PIN)
  174.   id, msg = rednet.receive()
  175.   if msg == "RT" then
  176.     print("Successfuly Removed Account "..Card)
  177.     sleep(2)
  178.   elseif msg == "RF" then
  179.     print("Invalid PIN Entered")
  180.     sleep(2)
  181.     Menu()
  182.   elseif msg == "FA" then
  183.     print("Invalid Account Number")
  184.     sleep(2)
  185.     Menu()
  186.   end
  187.   print()
  188.   print("[1] Blank Card")
  189.   print("[2] Return")
  190.   input = read()
  191.   if input == "1" then
  192.     print("Insert Written Card")
  193.     while not disk.isPresent("bottom") do sleep(0.01) end
  194.     disk.setLabel("bottom")
  195.     disk.eject("bottom")
  196.     Menu()
  197.   elseif input == "2" then
  198.     Menu()
  199.   else
  200.     Menu()
  201.   end
  202. end
  203.  
  204. function createAccount()
  205.   write("Deposit Amount: ")
  206.   DA = read()
  207.   rednet.send(PINMachine, "PIN")
  208.   print("Tell the Customer to Enter PIN")
  209.   id, PIN = rednet.receive()
  210.   rednet.send(ServerID, "CA")
  211.   rednet.send(ServerID, DA)
  212.   rednet.send(ServerID, PIN)
  213.   id, CN = rednet.receive()
  214.   print("Account Opened")
  215.   print("Please Insert Blank Card")
  216.   while not disk.isPresent("bottom") do sleep(0.01) end
  217.   disk.setLabel("bottom", tostring(CN))
  218.   disk.eject("bottom")
  219.   Menu()
  220. end
  221.  
  222. function checkLogin()
  223. print("Checking Login..")
  224. rednet.send(ServerID, "TrmChk")
  225. rednet.send(ServerID, User)
  226. rednet.send(ServerID, Pass)
  227. id, Msg = rednet.receive()
  228. if Msg == "True" then
  229.   print("Welcome "..User)
  230.   sleep(1)
  231.   Menu()
  232. elseif Msg == "False" then
  233.   print("Invalid User/Password")
  234.   sleep(2)
  235.   printLogin()
  236. end
  237. end
  238.  
  239. function printLogin()
  240. clear()
  241. print("Super's Bank Terminal")
  242. write("Username: ")
  243. User = read()
  244. write("Password: ")
  245. Pass = read("*")
  246. checkLogin()
  247. end
  248.  
  249.  
  250. printLogin()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement