Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dbcol = colors.white
- dtcol = colors.blue
- adminpassword = "ioshield"
- function cbut(cx,cy,text,bcol,tcol)
- if bcol == nil then
- bcol = dbcol
- end
- if tcol == nil then
- tcol = dtcol
- end
- term.setCursorPos(cx,cy)
- term.setBackgroundColor(bcol)
- term.setTextColor(tcol)
- term.write(text)
- term.setBackgroundColor(dbcol)
- term.setTextColor(dtcol)
- end
- function mainscreen()
- term.clear()
- cbut(2,2,"Banksystem by Muzze77")
- end
- function mainscreen_default()
- term.setBackgroundColor(dbcol)
- term.clear()
- cbut(2,5,"Options:")
- cbut(2,7,"[+] Create Account",colors.green,colors.black)
- cbut(2,8,"[-] Delete Account",colors.red,colors.white)
- cbut(2,9,"[L] Login",colors.blue,colors.white)
- end
- users = {}
- accounts = {}
- holdings = {}
- function getAccounts()
- link = "bank/accounts/list.lua"
- if fs.exists(link) then
- fileR = fs.open(link,"r")
- accounts = textutils.unserialize(fileR.readAll())
- fileR.close()
- else
- fileW = fs.open(link,"w")
- fileW.write(textutils.serialize(accounts))
- fileW.close()
- accounts = {}
- end
- return accounts
- end
- function setAccounts(accountnumber)
- link = "bank/accounts/list.lua"
- if fs.exists(link) then
- fileR = fs.open(link,"r")
- accounts = textutils.unserialize(fileR.readAll())
- fileR.close()
- table.insert(accounts, accountnumber)
- fileW = fs.open(link,"w")
- fileW.write(textutils.serialize(accounts))
- fileW.close()
- else
- fileW = fs.open(link,"w")
- accounts = {}
- fileW.write(textutils.serialize(accounts))
- fileW.close()
- end
- return accounts
- end
- ids = 0
- id = 0
- function createUser()
- accounts = getAccounts()
- index = true
- n = 0
- if #accounts == 0 then
- 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)
- print(Acountnumber)
- setAccounts(accountnumber)
- else
- while index do
- 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)
- for v, k in pairs(accounts) do
- if k == random then
- n = n + 1
- end
- end
- if n > 0 then
- index = true
- else
- index = false
- end
- accountnumber = random
- setAccounts(accountnumber)
- end
- end
- cbut(2,5,"Your Name:")
- cbut(2,6,"__________")
- term.setCursorPos(2,6)
- username = io.read()
- if fs.exists("bank/users/" .. username) then
- cbut(2,10,"This user already exitsts -> Going to Homescreen")
- else
- fileC = fs.open("bank/users/" .. username,"w")
- fileC.writeLine(username)
- fileC.close()
- cbut(2,10,"User created")
- end
- sleep(2)
- end
- function readUser()
- end
- function saveUser()
- end
- function delUser()
- cbut(2,5,"Delete User with Accountname:")
- cbut(2,6,"__________")
- term.setCursorPos(2,6)
- username = io.read()
- cbut(2,8,"Masterpassword:")
- cbut(2,9,"__________")
- term.setCursorPos(2,9)
- iopass = io.read()
- if iopass == adminpassword then
- if fs.exists("bank/users/"..username) then
- term.clear()
- mainscreen()
- shell.run("delete bank/users/" .. username)
- cbut(2,10,"User " .. username .. " deleted")
- else
- term.clear()
- mainscreen()
- cbut(2,10,"User " .. username .. " not found")
- end
- else
- term.clear()
- mainscreen()
- cbut(2,10,"Permission denied. Wrong Password")
- end
- sleep(2)
- end
- shell.run("clear")
- term.setBackgroundColor(dbcol)
- term.setTextColor(dtcol)
- term.clear()
- gx,gy = term.getSize()
- while true do
- gx,gy = term.getSize()
- mainscreen_default()
- evt = {os.pullEvent()}
- if evt[1] == "mouse_click" then
- mx = evt[3]
- my = evt[4]
- cbut(2,gy,"X: " .. mx .. " / Y: " .. my,colors.white,colors.blue)
- if mx == 3 and my == 7 then
- mainscreen()
- createUser()
- end
- if mx == 3 and my == 8 then
- mainscreen()
- delUser()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment