Advertisement
Guest User

startup

a guest
Nov 30th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.61 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. pri = peripheral.wrap("left")
  10.  
  11. function reqPin(req)
  12.   rednet.send(PINMachine, req)
  13.   id, ms = rednet.receive(60)
  14.   if ms == nil then
  15.     print("PIN Machine Offline After Trying For 60 Secodns")
  16.   end
  17.   return ms
  18. end
  19.  
  20. function Menu()
  21. printMenu()
  22. input = read()
  23. if input == "5" then
  24.   createAccount()
  25. elseif input == "4" then
  26.   accPin()
  27. elseif input == "7" then
  28.   printLogin()
  29. elseif input == "6" then
  30.   closeAccount()
  31. elseif input == "1" then
  32.   accDeposit()
  33. elseif input == "2" then
  34.   accWithdraw()
  35. elseif input == "3" then
  36.   checkBalance()
  37. else
  38.   Menu()
  39. end
  40. end
  41. function printMenu()
  42. clear()
  43. print("Logged In: "..User)
  44. print()
  45. print("[1] Account Deposit")
  46. print("[2] Account Withdrawal")
  47. print("[3] Check Balance")
  48. print("[4] Change PIN")
  49. print()
  50. print("[5] Open Account")
  51. print("[6] Close Account")
  52. print("[7] Log Out")
  53. print("-------------------------")
  54. print()
  55. write(">> ")
  56. end
  57.  
  58. function accPin()
  59.   print()
  60.   print("Please ask customer to insert card into reader")
  61.   local res = reqPin("CARD")
  62.   if res ~= nil then
  63.     print("Account: "..res)
  64.     accN = res
  65.   else
  66.     print("Please Input Manually")
  67.     write("Account: ")
  68.     accN = read()
  69.   end
  70.   print("Please ask customer to type old pin")
  71.   oPIN = reqPin("PIN")
  72.   rednet.send(ServerID, "PINCheck")
  73.   rednet.send(ServerID, accN)
  74.   rednet.send(ServerID, oPIN)
  75.   id, conf = rednet.receive(30)
  76.  
  77.   if conf == "true" then
  78.     conf = true
  79.   elseif conf == "false" then
  80.     conf = false
  81.   end
  82.  
  83.   if conf == nil then
  84.     printError("Server Offline")
  85.     printError("Logging Off..")
  86.     sleep(2)
  87.     shell.run("startup")
  88.   elseif conf then
  89.     print("Correct PIN Entered")
  90.   elseif not conf then
  91.     print("Incorrect PIN Entered")
  92.     sleep(1)
  93.     Menu()
  94.   else
  95.     Menu()
  96.   end
  97.  
  98.   while true do
  99.     print("Please tell customer to enter new PIN")
  100.  
  101.     nPIN = reqPin("PIN")
  102.  
  103.     print("Please tell customer to confirm PIN")
  104.  
  105.     ntPIN = reqPin("PIN")
  106.  
  107.     if nPIN == ntPIN then
  108.       break
  109.     else
  110.       print("PIN Numbers Don't Match")
  111.     end
  112.  
  113.   end
  114.  
  115.  
  116.   rednet.send(ServerID, "CPIN")
  117.   rednet.send(ServerID, accN)
  118.   rednet.send(ServerID, nPIN)
  119.  
  120.   print("PIN Changed")
  121.  
  122.   sleep(1)
  123.  
  124.   Menu()
  125. end
  126.  
  127. function checkBalance()
  128. print("[1] Type Manually")
  129. print("[2] Insert Card")
  130. print()
  131. print("[3] Cancel")
  132. print()
  133. write(">> ")
  134. input = read()
  135. if input == "1" then
  136.   write("Account: ")
  137.   Acc = read()
  138. elseif input == "2" then
  139.   while not disk.isPresent("bottom") do sleep(0.01) end
  140.   Acc = disk.getLabel("bottom")
  141.   disk.eject("bottom")
  142. elseif input == "3" then
  143.   Menu()
  144. else
  145.   checkBalance()
  146. end
  147. rednet.send(ServerID, "ChkBal")
  148. rednet.send(ServerID, Acc)
  149. id, Bal = rednet.receive()
  150. --tonumber(Bal)
  151. if Bal ~= "BalF" then
  152. print("Balance: D$"..Bal)
  153. sleep(3)
  154. Menu()
  155. elseif Bal == "BalF" then
  156. print("Invalid Acccount Number")
  157. sleep(2)
  158. Menu()
  159. end
  160. end
  161.  
  162. function accWithdraw()
  163.   print("[1] Type Manually")
  164.   print("[2] Insert Card")
  165.   print()
  166.   write(">> ")
  167.   input = read()
  168.   if input == "1" then
  169.   write("Account: ")
  170.   Ac = read()
  171.   elseif input == "2" then
  172.   while not disk.isPresent("bottom") do sleep(0.01) end
  173.   Ac = disk.getLabel("bottom")
  174.   print("Account: "..Ac)
  175.   end
  176.   rednet.send(PINMachine, "PIN")
  177.   id, PIN = rednet.receive()
  178.   write("Amount: D$")
  179.   Am = read()
  180.   rednet.send(ServerID, "AW")
  181.   rednet.send(ServerID, Ac)
  182.   rednet.send(ServerID, PIN)
  183.   rednet.send(ServerID, Am)
  184.   id, Co = rednet.receive()
  185.   if Co == "WiT" then
  186.     print("Withdrew D$"..Am)
  187.     sleep(2)
  188.     Menu()
  189.   elseif Co == "NB" then
  190.     print("Not Enough Funds")
  191.     sleep(2)
  192.     Menu()
  193.   elseif Co == "AcF" then
  194.     print("Account Does not Exist")
  195.     sleep(1)
  196.     Menu()
  197.   end
  198. end
  199.  
  200. function accDeposit()
  201.   print("[1] Type Manually")
  202.   print("[2] Insert Card")
  203.   print()
  204.   write(">> ")
  205.   input = read()
  206.   if input == "1" then
  207.     write("Account Number: ")
  208.     Card = read()
  209.   elseif input == "2" then
  210.     while not disk.isPresent("bottom") do sleep(0.01) end
  211.     Card = disk.getLabel("bottom")
  212.     disk.eject("bottom")
  213.     if Card ~= nil then
  214.     print("Account Number: "..Card)
  215.     else
  216.     print("Foreign Object Inserted")
  217.     sleep(3)
  218.     Menu()
  219.     end
  220.   end
  221.   write("Amount: ")
  222.   Am = read()
  223.   rednet.send(ServerID, "AD")
  224.   rednet.send(ServerID, Card)
  225.   rednet.send(ServerID, Am)
  226.   id, msg = rednet.receive()
  227.   if msg == "DT" then
  228.     print("Deposited D$"..Am.." to Account "..Card)
  229.     sleep(2)
  230.     Menu()
  231.   elseif msg == "DF" then
  232.     print("Invalid Account")
  233.     sleep(2)
  234.     Menu()
  235.   end
  236. end
  237.  
  238. function closeAccount()
  239.   print("Close Account")
  240.   print()
  241.   print("[1] Type Manually")
  242.   print("[2] Insert Card")
  243.   write(">> ")
  244.   input = read()
  245.   if input == "1" then
  246.   write("Account Number: ")
  247.   Card = read()
  248.   elseif input == "2" then
  249.     while not disk.isPresent("bottom") do sleep(0.01) end
  250.     Card = disk.getLabel("bottom")
  251.     print("Account Number: "..Card)
  252.     disk.eject("bottom")
  253.   else
  254.     closeAccount()
  255.   end
  256.   rednet.send(PINMachine, "PIN")
  257.   print("Tell the Customer to Enter their PIN")
  258.   id, PIN = rednet.receive()    
  259.   rednet.send(ServerID, "RA")
  260.   rednet.send(ServerID, Card)
  261.   rednet.send(ServerID, PIN)
  262.   id, msg = rednet.receive()
  263.   if msg == "RT" then
  264.     print("Successfuly Removed Account "..Card)
  265.     sleep(2)
  266.   elseif msg == "RF" then
  267.     print("Invalid PIN Entered")
  268.     sleep(2)
  269.     Menu()
  270.   elseif msg == "FA" then
  271.     print("Invalid Account Number")
  272.     sleep(2)
  273.     Menu()
  274.   end
  275.   print()
  276.   print("[1] Blank Card")
  277.   print("[2] Return")
  278.   input = read()
  279.   if input == "1" then
  280.     print("Insert Written Card")
  281.     while not disk.isPresent("bottom") do sleep(0.01) end
  282.     disk.setLabel("bottom")
  283.     disk.eject("bottom")
  284.     Menu()
  285.   elseif input == "2" then
  286.     Menu()
  287.   else
  288.     Menu()
  289.   end
  290. end
  291.  
  292. function createAccount()
  293.   write("Deposit Amount: ")
  294.   DA = read()
  295.   rednet.send(PINMachine, "PIN")
  296.   print("Tell the Customer to Enter PIN")
  297.   id, PIN = rednet.receive()
  298.   print()
  299.   print("PIN Received")
  300.   print()
  301.   write("First: ")
  302.   FN = read()
  303.   write("Last: ")
  304.   LN = read()
  305.   FuN = FN .. " " .. LN  
  306.   rednet.send(ServerID, "CA")
  307.   rednet.send(ServerID, DA)
  308.   rednet.send(ServerID, PIN)
  309.   rednet.send(ServerID, FuN)
  310.   id, CN = rednet.receive()
  311.   LFo = string.sub(CN, 13, 16)
  312.   print("Account Opened")
  313.   print("Please Insert Blank Card")
  314.   while not disk.isPresent("bottom") do sleep(0.01) end
  315.   disk.setLabel("bottom", tostring(CN))
  316.   disk.eject("bottom")
  317.   fp = fs.open("printerEx", "r")
  318.   pri.newPage()
  319.   for i = 1, 10 do
  320.     pri.setCursorPos(1, i)
  321.     L = fp.readLine()
  322.     if i == 1 then
  323.       pri.write(L)
  324.     elseif i == 2 then
  325.       pri.write(L..FN)
  326.     elseif i == 3 then
  327.       pri.write(L..LN)
  328.     elseif i == 4 then
  329.       pri.write(L)
  330.     elseif i == 5 then
  331.       pri.write(L..DA)
  332.     elseif i == 6 then
  333.       pri.write(L..LFo)
  334.     elseif i > 7 then
  335.       pri.write(L)
  336.     end
  337.   end
  338.   pri.endPage()
  339.   Menu()
  340. end
  341.  
  342. function checkLogin()
  343. print("Checking Login..")
  344. rednet.send(ServerID, "TrmChk")
  345. rednet.send(ServerID, User)
  346. rednet.send(ServerID, Pass)
  347. id, Msg = rednet.receive()
  348. if Msg == "True" then
  349.   print("Welcome "..User)
  350.   sleep(1)
  351.   Menu()
  352. elseif Msg == "False" then
  353.   print("Invalid User/Password")
  354.   sleep(2)
  355.   printLogin()
  356. end
  357. end
  358.  
  359. function printLogin()
  360. clear()
  361. print("Super's Bank Terminal")
  362. write("Username: ")
  363. User = read()
  364. write("Password: ")
  365. Pass = read("*")
  366. checkLogin()
  367. end
  368.  
  369.  
  370. printLogin()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement