Muzze77

BankSystem1_12_2

Nov 6th, 2024 (edited)
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.58 KB | None | 0 0
  1. dbcol = colors.white
  2. dtcol = colors.blue
  3. adminpassword = "ioshield"
  4. function cbut(cx,cy,text,bcol,tcol)
  5.     if bcol == nil then
  6.         bcol = dbcol
  7.     end
  8.     if tcol == nil then
  9.         tcol = dtcol
  10.     end
  11.     term.setCursorPos(cx,cy)
  12.     term.setBackgroundColor(bcol)
  13.     term.setTextColor(tcol)
  14.     term.write(text)
  15.     term.setBackgroundColor(dbcol)
  16.     term.setTextColor(dtcol)
  17. end
  18.  
  19. function mainscreen()
  20. term.clear()
  21. cbut(2,2,"Banksystem by Muzze77")
  22.  
  23. end
  24.  
  25. function mainscreen_default()
  26. term.setBackgroundColor(dbcol)
  27. term.clear()
  28. cbut(2,5,"Options:")
  29. cbut(2,7,"[+] Create Account",colors.green,colors.black)
  30. cbut(2,8,"[-] Delete Account",colors.red,colors.white)
  31. cbut(2,9,"[L] Login",colors.blue,colors.white)
  32.  
  33. end
  34.  
  35.  
  36. users = {}
  37. accounts = {}
  38. holdings = {}
  39.  
  40. function getAccounts()
  41.     link = "bank/accounts/list.lua"
  42.     if fs.exists(link) then
  43.         fileR = fs.open(link,"r")
  44.         accounts = textutils.unserialize(fileR.readAll())
  45.         fileR.close()
  46.     else
  47.         fileW = fs.open(link,"w")
  48.         fileW.write(textutils.serialize(accounts))
  49.         fileW.close()
  50.         accounts = {}
  51.     end
  52.  
  53. return accounts
  54. end
  55.  
  56. function setAccounts(accountnumber)
  57.     link = "bank/accounts/list.lua"
  58.     if fs.exists(link) then
  59.         fileR = fs.open(link,"r")
  60.         accounts = textutils.unserialize(fileR.readAll())
  61.         fileR.close()
  62.         table.insert(accounts, accountnumber)
  63.         fileW = fs.open(link,"w")
  64.         fileW.write(textutils.serialize(accounts))
  65.         fileW.close()
  66.        
  67.     else
  68.         fileW = fs.open(link,"w")
  69.         accounts = {}
  70.         fileW.write(textutils.serialize(accounts))
  71.         fileW.close()
  72.        
  73.     end
  74.  
  75. return accounts
  76. end
  77.  
  78.  
  79. ids = 0
  80. id = 0
  81.  
  82.  
  83. function createUser()
  84.     accounts = getAccounts()
  85.     index = true
  86.        n = 0
  87.     if #accounts == 0 then
  88.         accountnumber = math.random(9) .. math.random(9) .. math.random(9) .. math.random(9) .. math.random(9) .. math.random(9) .. math.random(9) .. math.random(9)
  89.         print(Acountnumber)
  90.         setAccounts(accountnumber)
  91.     else
  92.      
  93.         while index do
  94.             random = math.random(9) .. math.random(9) .. math.random(9) .. math.random(9) .. math.random(9) .. math.random(9) .. math.random(9) .. math.random(9)
  95.  
  96.             for v, k in pairs(accounts) do
  97.                 if k == random then
  98.                     n = n + 1
  99.                 end
  100.             end
  101.             if n > 0 then
  102.             index = true
  103.             else
  104.             index = false
  105.  
  106.             end
  107.            
  108.         accountnumber = random
  109.         setAccounts(accountnumber)
  110.     end
  111.    
  112.    
  113.  end
  114.    
  115.     cbut(2,5,"Your Name:")
  116.     cbut(2,6,"__________")
  117.     term.setCursorPos(2,6)
  118.     username = io.read()
  119.     if fs.exists("bank/users/" .. username) then
  120.         cbut(2,10,"This user already exitsts -> Going to Homescreen")
  121.        
  122.     else
  123.         fileC = fs.open("bank/users/" .. username,"w")
  124.         fileC.writeLine(username)
  125.         fileC.close()
  126.        
  127.         cbut(2,10,"User created")
  128.        
  129.     end
  130.     sleep(2)
  131. end
  132.  
  133.  
  134. function readUser()
  135.  
  136.  
  137.  
  138. end
  139.  
  140. function saveUser()
  141.  
  142.  
  143. end
  144.  
  145. function delUser()
  146.     cbut(2,5,"Delete User with Accountname:")
  147.     cbut(2,6,"__________")
  148.     term.setCursorPos(2,6)
  149.     username = io.read()
  150.    
  151.     cbut(2,8,"Masterpassword:")
  152.     cbut(2,9,"__________")
  153.     term.setCursorPos(2,9)
  154.     iopass = io.read()
  155.     if iopass == adminpassword then
  156.         if fs.exists("bank/users/"..username) then
  157.  
  158.             term.clear()
  159.             mainscreen()
  160.             shell.run("delete bank/users/" .. username)
  161.             cbut(2,10,"User " .. username .. " deleted")
  162.            
  163.         else
  164.             term.clear()
  165.             mainscreen()
  166.             cbut(2,10,"User " .. username .. " not found")
  167.     end
  168.     else
  169.         term.clear()
  170.         mainscreen()
  171.         cbut(2,10,"Permission denied. Wrong Password")
  172.     end
  173.  
  174.     sleep(2)
  175. end
  176.  
  177.  
  178.  
  179.  
  180. shell.run("clear")
  181. term.setBackgroundColor(dbcol)
  182. term.setTextColor(dtcol)
  183. term.clear()
  184.  
  185.  
  186. gx,gy = term.getSize()
  187.  
  188. while true do
  189.     gx,gy = term.getSize()
  190.     mainscreen_default()
  191.     evt = {os.pullEvent()}
  192.    
  193.     if evt[1] == "mouse_click" then
  194.         mx = evt[3]
  195.         my = evt[4]
  196.         cbut(2,gy,"X: " .. mx .. " / Y: " .. my,colors.white,colors.blue)
  197.         if mx == 3 and my == 7 then
  198.             mainscreen()
  199.  
  200.             createUser()
  201.         end
  202.         if mx == 3 and my == 8 then
  203.             mainscreen()
  204.             delUser()
  205.  
  206.         end
  207.     end
  208.    
  209. end
Advertisement
Add Comment
Please, Sign In to add comment