Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -----------------------Params
- local bankServerID = 15
- local modemSide = "top"
- local diskSide = "right"
- local adminPassword = "2048"
- local text_error_noconnection = "Can't connect to server"
- --------------------------
- rednet.open(modemSide)
- os.loadAPI("bankapi.lua")
- bankapi.setBankServerID(bankServerID)
- local function colorFromName(c)
- if (c == "white") then return colors.white
- elseif (c == "orange") then return colors.orange
- elseif (c == "magenta") then return colors.magenta
- elseif (c == "lightBlue") then return colors.lightBlue
- elseif (c == "yellow") then return colors.yellow
- elseif (c == "lime") then return colors.lime
- elseif (c == "pink") then return colors.pink
- elseif (c == "gray") then return colors.gray
- elseif (c == "lightGray") then return colors.lightGray
- elseif (c == "cyan") then return colors.cyan
- elseif (c == "purple") then return colors.purple
- elseif (c == "blue") then return colors.blue
- elseif (c == "brown") then return colors.brown
- elseif (c == "green") then return colors.green
- elseif (c == "red") then return colors.red
- elseif (c == "black") then return colors.black
- else return nil end
- end
- --------------------------
- -- Password protection
- local pass = ""
- repeat
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.yellow)
- term.clear()
- local scrW, scrH = term.getSize()
- local title = "Mermegold"
- term.setCursorPos(scrW/2-string.len(title)/2, scrH/2)
- term.write(title)
- term.setCursorPos(scrW/2-string.len(title)/2, scrH/2+1)
- pass = read("*")
- until (pass == adminPassword)
- while true do -- Second while to allow the use of breaks as continues
- while true do
- local command = bankapi.optionMenu("Mermegold", {
- [1] = {
- ["option"] = "new",
- ["text"] = "Crear nueva cuenta"},
- [2] = {
- ["option"] = "transaction",
- ["text"] = "Realizar transacción"},
- [3] = {
- ["option"] = "balance",
- ["text"] = "Consultar balance"},
- [4] = {
- ["option"] = "delete",
- ["text"] = "Borrar cuenta"},
- [5] = {
- ["option"] = "log",
- ["text"] = "Historial de transacciones"},
- [6] = {
- ["option"] = "assigncard",
- ["text"] = "Asignar tarjeta"},
- [7] = {
- ["option"] = "logout",
- ["text"] = "Salir"},
- })
- if (command == "new") then
- local steps = {"Nombre del usuario", "Color representativo"}
- local name = bankapi.inputTextScreen(steps, 1, 25)
- if (name == nil) then break end
- local color = bankapi.selectColorScreen(steps, 2)
- if (color == nil) then break end
- local success, message = bankapi.newAccount(name, 0, color)
- bankapi.responseScreen(message.success, message.response)
- elseif (command == "transaction") then
- local tempClientData = bankapi.getClientData()
- local steps = {"Cuenta a proveer los fondos", "Cuenta a recibir los fondos", "Monto a enviar", "Descripción de la transacción"}
- local from = bankapi.selectAccountScreen(steps, 1, 0, true)
- if (from == nil) then break end
- local to = bankapi.selectAccountScreen(steps, 2, from, true)
- if (to == nil) then break end
- local amount = bankapi.inputNumberScreen(steps, 3, tempClientData[from].balance)
- if (amount == nil) then break end
- local description = bankapi.inputTextScreen(steps, 4, 100)
- if (description == nil) then break end
- local success, message = bankapi.transaction(from, to, amount, description)
- bankapi.responseScreen(message.success, message.response)
- elseif (command == "delete") then
- local steps = {"Cuenta a eliminar"}
- local deletion = bankapi.selectAccountScreen(steps, 1, 0)
- if (deletion == nil) then break end
- local tempClientData = bankapi.getClientData()
- local accept = bankapi.confirmScreen({"¿Estas seguro que quieres borrar esta cuenta?"}, {
- ["Nombre"] = tempClientData[deletion].name,
- ["Clave"] = deletion,
- ["Balance"] = tempClientData[deletion].balance
- })
- if (not accept) then break end
- local success, message = bankapi.deleteAccount(deletion)
- bankapi.responseScreen(message.success, message.response)
- elseif (command == "log") then
- local tempClientData = bankapi.getClientData()
- local steps = {"Cuenta a consultar"}
- local account = bankapi.selectAccountScreen(steps, 1, 0)
- if (account == nil) then break end
- bankapi.transactionLogScreen(account)
- elseif (command == "balance") then
- local account = bankapi.selectAccountScreen({"Cuenta a consultar"}, 1, 0)
- if (account == nil) then break end
- bankapi.showBalance(account)
- elseif (command == "assigncard") then
- if (disk.isPresent(diskSide)) then
- local account = bankapi.selectAccountScreen({"Cuenta a asignar"}, 1, 0)
- if (account == nil) then break end
- local tempClientData = bankapi.getClientData()
- local name = tempClientData[account].name
- local f = fs.open("disk/mermegold.txt", "w")
- f.write(account)
- f.close()
- disk.setLabel(diskSide, "Mermegold | "..name)
- bankapi.successScreen("Tarjeta asignada a "..name)
- else
- bankapi.errorScreen("No hay disco")
- end
- elseif (command == "logout") then
- os.reboot()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement