Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.99 KB | None | 0 0
  1. -----------------------Params
  2. local bankServerID = 15
  3. local modemSide = "top"
  4. local diskSide = "right"
  5. local adminPassword = "2048"
  6.  
  7. local text_error_noconnection = "Can't connect to server"
  8. --------------------------
  9. rednet.open(modemSide)
  10.  
  11. os.loadAPI("bankapi.lua")
  12. bankapi.setBankServerID(bankServerID)
  13.  
  14. local function colorFromName(c)
  15. if (c == "white") then return colors.white
  16. elseif (c == "orange") then return colors.orange
  17. elseif (c == "magenta") then return colors.magenta
  18. elseif (c == "lightBlue") then return colors.lightBlue
  19. elseif (c == "yellow") then return colors.yellow
  20. elseif (c == "lime") then return colors.lime
  21. elseif (c == "pink") then return colors.pink
  22. elseif (c == "gray") then return colors.gray
  23. elseif (c == "lightGray") then return colors.lightGray
  24. elseif (c == "cyan") then return colors.cyan
  25. elseif (c == "purple") then return colors.purple
  26. elseif (c == "blue") then return colors.blue
  27. elseif (c == "brown") then return colors.brown
  28. elseif (c == "green") then return colors.green
  29. elseif (c == "red") then return colors.red
  30. elseif (c == "black") then return colors.black
  31. else return nil end
  32. end
  33.  
  34. --------------------------
  35.  
  36. -- Password protection
  37. local pass = ""
  38. repeat
  39. term.setBackgroundColor(colors.black)
  40. term.setTextColor(colors.yellow)
  41. term.clear()
  42. local scrW, scrH = term.getSize()
  43. local title = "Mermegold"
  44. term.setCursorPos(scrW/2-string.len(title)/2, scrH/2)
  45. term.write(title)
  46. term.setCursorPos(scrW/2-string.len(title)/2, scrH/2+1)
  47. pass = read("*")
  48. until (pass == adminPassword)
  49.  
  50. while true do -- Second while to allow the use of breaks as continues
  51. while true do
  52.  
  53. local command = bankapi.optionMenu("Mermegold", {
  54. [1] = {
  55. ["option"] = "new",
  56. ["text"] = "Crear nueva cuenta"},
  57. [2] = {
  58. ["option"] = "transaction",
  59. ["text"] = "Realizar transacción"},
  60. [3] = {
  61. ["option"] = "balance",
  62. ["text"] = "Consultar balance"},
  63. [4] = {
  64. ["option"] = "delete",
  65. ["text"] = "Borrar cuenta"},
  66. [5] = {
  67. ["option"] = "log",
  68. ["text"] = "Historial de transacciones"},
  69. [6] = {
  70. ["option"] = "assigncard",
  71. ["text"] = "Asignar tarjeta"},
  72. [7] = {
  73. ["option"] = "logout",
  74. ["text"] = "Salir"},
  75. })
  76.  
  77. if (command == "new") then
  78.  
  79. local steps = {"Nombre del usuario", "Color representativo"}
  80. local name = bankapi.inputTextScreen(steps, 1, 25)
  81. if (name == nil) then break end
  82. local color = bankapi.selectColorScreen(steps, 2)
  83. if (color == nil) then break end
  84.  
  85. local success, message = bankapi.newAccount(name, 0, color)
  86. bankapi.responseScreen(message.success, message.response)
  87.  
  88. elseif (command == "transaction") then
  89. local tempClientData = bankapi.getClientData()
  90. local steps = {"Cuenta a proveer los fondos", "Cuenta a recibir los fondos", "Monto a enviar", "Descripción de la transacción"}
  91. local from = bankapi.selectAccountScreen(steps, 1, 0, true)
  92. if (from == nil) then break end
  93. local to = bankapi.selectAccountScreen(steps, 2, from, true)
  94. if (to == nil) then break end
  95. local amount = bankapi.inputNumberScreen(steps, 3, tempClientData[from].balance)
  96. if (amount == nil) then break end
  97. local description = bankapi.inputTextScreen(steps, 4, 100)
  98. if (description == nil) then break end
  99.  
  100. local success, message = bankapi.transaction(from, to, amount, description)
  101. bankapi.responseScreen(message.success, message.response)
  102.  
  103. elseif (command == "delete") then
  104. local steps = {"Cuenta a eliminar"}
  105. local deletion = bankapi.selectAccountScreen(steps, 1, 0)
  106. if (deletion == nil) then break end
  107.  
  108. local tempClientData = bankapi.getClientData()
  109. local accept = bankapi.confirmScreen({"¿Estas seguro que quieres borrar esta cuenta?"}, {
  110. ["Nombre"] = tempClientData[deletion].name,
  111. ["Clave"] = deletion,
  112. ["Balance"] = tempClientData[deletion].balance
  113. })
  114. if (not accept) then break end
  115.  
  116. local success, message = bankapi.deleteAccount(deletion)
  117. bankapi.responseScreen(message.success, message.response)
  118.  
  119. elseif (command == "log") then
  120. local tempClientData = bankapi.getClientData()
  121. local steps = {"Cuenta a consultar"}
  122. local account = bankapi.selectAccountScreen(steps, 1, 0)
  123. if (account == nil) then break end
  124. bankapi.transactionLogScreen(account)
  125.  
  126. elseif (command == "balance") then
  127.  
  128. local account = bankapi.selectAccountScreen({"Cuenta a consultar"}, 1, 0)
  129. if (account == nil) then break end
  130. bankapi.showBalance(account)
  131.  
  132. elseif (command == "assigncard") then
  133. if (disk.isPresent(diskSide)) then
  134. local account = bankapi.selectAccountScreen({"Cuenta a asignar"}, 1, 0)
  135. if (account == nil) then break end
  136. local tempClientData = bankapi.getClientData()
  137. local name = tempClientData[account].name
  138. local f = fs.open("disk/mermegold.txt", "w")
  139. f.write(account)
  140. f.close()
  141. disk.setLabel(diskSide, "Mermegold | "..name)
  142. bankapi.successScreen("Tarjeta asignada a "..name)
  143. else
  144. bankapi.errorScreen("No hay disco")
  145. end
  146.  
  147. elseif (command == "logout") then
  148. os.reboot()
  149. end
  150. end
  151. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement