Advertisement
Marum

Mermegold V4 Server

Mar 25th, 2025 (edited)
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.57 KB | None | 0 0
  1. -- Bank Server
  2.  
  3. os.loadAPI("bankapi.lua")
  4.  
  5. -------------------- Params
  6. local currency = {
  7. diamond = {
  8. [1] = {
  9. id="minecraft:diamond",
  10. value=1,
  11. name={en="Diamond",es="Diamante",de="Diamant",},
  12. plural={en="Diamonds",es="Diamantes",de="Diamanten",},
  13. short={en="D",es="D",de="D"},
  14. uprecipe={need=9,yield=1,result="minecraft:diamond_block"}
  15. },
  16. [2] = {
  17. id="minecraft:diamond_block",
  18. value=9,
  19. name={en="Diamond Block",es="Bloque de Diamante",de="Diamantblock",},
  20. plural={en="Diamond Blocks",es="Bloques de Diamante",de="Diamantbloecke",},
  21. short={en="Bl",es="Bl",de="Bl"},
  22. downrecipe={need=1,yield=9,result="minecraft:diamond_block"}
  23. }
  24. },
  25. gold = {
  26. [1] = {
  27. id="minecraft:gold_nugget",
  28. value=1,
  29. name={en="Gold Nugget",es="Pepita de Oro",de="Goldnugget",},
  30. plural={en="Gold Nuggets",es="Pepitas de Oro",de="Goldnuggets",},
  31. short={en="N",es="P",de="N"},
  32. uprecipe={need=9,yield=1,result="minecraft:gold_ingot"}
  33. },
  34. [2] = {
  35. id="minecraft:gold_ingot",
  36. value=9,
  37. name={en="Gold Ingot",es="Lingote de Oro",de="Goldbarren",},
  38. plural={en="Gold Ingots",es="Lingotes de Oro",de="Goldbarren",},
  39. short={en="I",es="L",de="B"},
  40. downrecipe={need=1,yield=9,result="minecraft:gold_nugget"},
  41. uprecipe={need=9,yield=1,result="minecraft:gold_block"}
  42. },
  43. [3] = {
  44. id="minecraft:gold_block",
  45. value=81,
  46. name={en="Gold Block",es="Bloque de Oro",de="Goldblock",},
  47. plural={en="Gold Blocks",es="Bloques de Oro",de="Goldbloecke",},
  48. short={en="B",es="B",de="B"},
  49. downrecipe={need=1,yield=9,result="minecraft:gold_ingot"}
  50. }
  51. },
  52. emerald = {
  53. [1] = {
  54. id="minecraft:emerald",
  55. value=1,
  56. name={en="Emerald",es="Esmeralda",de="Smaragd",},
  57. plural={en="Emeralds",es="Esmeraldas",de="Smaragde",},
  58. short={en="E",es="E",de="S"},
  59. uprecipe={need=9,yield=1,result="minecraft:emerald_block"}
  60. },
  61. [2] = {
  62. id="minecraft:emerald_block",
  63. value=9,
  64. name={en="Emerald Block",es="Bloque de Esmeralda",de="Smaragdblock",},
  65. plural={en="Emerald Blocks",es="Bloques de Esmeralda",de="Smaragdbloecke",},
  66. short={en="Bl",es="Bl",de="Bl"},
  67. downrecipe={need=1,yield=9,result="minecraft:emerald_block"}
  68. }
  69. },
  70. -- Simple coin is an unpublished coin mod made by me.
  71. -- It is compatible with this bank, but the option is hidden.
  72. simplecoin = {
  73. [1] = {
  74. id="simple_coins:copper_coin",
  75. value=1,
  76. name={en="Copper piece",es="Pieza de cobre"},
  77. short={en="cp",es="cp"},
  78. uprecipe={need=5,yield=1,result="simple_coins:copper_coin_pile"}
  79. },
  80. [2] = {
  81. id="simple_coins:copper_coin_pile",
  82. value=5,
  83. name={en="Copper piece pile",es="Pila de piezas de cobre"},
  84. short={en="cpp",es="cpp"},
  85. downrecipe={need=1,yield=5,result="simple_coins:copper_coin"},
  86. uprecipe={need=2,yield=1,result="simple_coins:silver_coin"},
  87. ingredient=true
  88. },
  89. [3] = {
  90. id="simple_coins:silver_coin",
  91. value=10,
  92. name={en="Silver piece",es="Pieza de plata"},
  93. short={en="sp",es="sp"},
  94. downrecipe={need=1,yield=2,result="simple_coins:copper_coin_pile"},
  95. uprecipe={need=5,yield=1,result="simple_coins:silver_coin_pile"}
  96. },
  97. [4] = {
  98. id="simple_coins:silver_coin_pile",
  99. value=50,
  100. name={en="Silver piece pile",es="Pila de piezas de plata"},
  101. short={en="spp",es="spp"},
  102. downrecipe={need=1,yield=5,result="simple_coins:silver_coin"},
  103. uprecipe={need=2,yield=1,result="simple_coins:gold_coin"},
  104. ingredient=true
  105. },
  106. [5] = {
  107. id="simple_coins:gold_coin",
  108. value=100,
  109. name={en="Gold Piece",es="Pieza de oro"},
  110. short={en="gp",es="gp"},
  111. downrecipe={need=1,yield=2,result="simple_coins:silver_coin"}
  112. }
  113. }
  114. }
  115. -----------------------------
  116.  
  117. local cumulativeLimit = 10000 -- Every x money moved, you get charged
  118. local cumulativePrice = 100 -- How much you pay
  119. local lang = "en"
  120. local currencyType = "diamond"
  121. local terminalPassword = "1234"
  122. local valueMultiplier = 100
  123. local bankOwnerKey = 0
  124.  
  125. local localization = {
  126. en={
  127. title = "Hosting Bank Server, do not turn off",
  128. account_start_description = "Welcome to Mermegold!",
  129. error_invalidamount = "Invalid amount",
  130. error_from = "Invalid origin account",
  131. error_to = "Invalid target account",
  132. error_account = "Non-existent account",
  133. error_same = "Can't use the same account as origin and target",
  134. error_notenoughbalance = "Insufficient balance",
  135. success_transaction = "Transaction successful",
  136. success_update = "Update successful",
  137. success_account = "Account created successfully",
  138. account_deleted = "Account deleted successfully",
  139. withdraw_description = "Withdrawal",
  140. deposit_description = "Deposit",
  141. expenses = "Mermegold expenses",
  142. language = "Language",
  143. currency_type = "Currency item",
  144. value_multiplier = "Item value",
  145. value_multiplier_explanation = "How much $ is a single Currency Item worth",
  146. password = "Admin terminal password",
  147. password_explanation = "Password for the admin terminals",
  148. cumulative_limit = "Cumulative limit",
  149. cumulative_limit_explanation = "How much a user can exchange before paying expenses",
  150. limit_reach_cost = "Expenses",
  151. limit_reach_cost_explanation = "How much to charge a user when they reach the cumulative limit",
  152. set_owner = "Set owner",
  153. set_owner_explanation = "Set the account that will collect the bank expenses",
  154. en="English",
  155. es="Spanish",
  156. not_assigned="- not asigned -",
  157. deleted_account="- deleted -"
  158. },
  159. es={
  160. title = "Hospedando servidor del banco, no apagar",
  161. account_start_description = "Bienvenido a Mermegold!",
  162. error_invalidamount = "Monto invalido",
  163. error_from = "Cuenta origen invalida",
  164. error_to = "Cuenta destino invalida",
  165. error_account = "Cuenta inexistente",
  166. error_same = "No se puede usar la misma cuenta como destino y origen a la vez",
  167. error_notenoughbalance = "Balance insuficiente",
  168. success_transaction = "Transaccion exitosa",
  169. success_update = "Actualizacion exitosa",
  170. success_account = "Cuenta creada con exito",
  171. account_deleted = "Cuenta borrada con exito",
  172. withdraw_description = "Retiro",
  173. deposit_description = "Deposito",
  174. expenses = "Expensas de mermegold",
  175. language = "Lenguaje",
  176. currency_type = "Objeto Moneda",
  177. value_multiplier = "Valor del objeto",
  178. value_multiplier_explanation = "Cuanto $ vale un Objeto Moneda",
  179. password = "Contrasena de administrador",
  180. password_explanation = "Contrasena de las terminales de administrador",
  181. cumulative_limit = "Limite de acumulacion",
  182. cumulative_limit_explanation = "Cuanto puede mover un usuario antes de pagar expensas",
  183. limit_reach_cost = "Expensas",
  184. limit_reach_cost_explanation = "Cuanto debe pagar un usuario al llegar al limite de acumulacion",
  185. set_owner = "Asignar propietario",
  186. set_owner_explanation = "Elige la cuenta que cobrara las expensas del banco",
  187. en="Ingles",
  188. es="Espanol",
  189. not_assigned="- no asignado -",
  190. deleted_account="- borrado -"
  191. },
  192. de = {
  193. title = "Hosting Bank Server, nicht abschalten",
  194. account_start_description = "Willkommen bei Mermegold!",
  195. error_invalidamount = "Ungueltige Anzahl",
  196. error_from = "Ungueltiger Ursprungs Account",
  197. error_to = "Ungueltiger Empfaenger Account",
  198. error_account = "Konto existiert nicht",
  199. error_same = "Sender und Empfaenger koennen nicht gleich sein",
  200. error_notenoughbalance = "Unzureichender Kontostandt",
  201. success_transaction = "Transaktion erfolgreich",
  202. success_update = "Update erfolgreich",
  203. success_account = "Konto wurde erfolgreich erstellt",
  204. account_deleted = "Konto wurde erfolgreich geloescht",
  205. withdraw_description = "Auszahlung",
  206. deposit_description = "Einzahlung",
  207. expenses = "Mermegold Zinsen",
  208. language = "Sprache",
  209. currency_type = "Waehrungs Item",
  210. value_multiplier = "Item wert",
  211. value_multiplier_explanation = "Wie viel $ ein einziges Item wert ist",
  212. password = "Admin Terminal passwort",
  213. password_explanation = "Passwort für die Admin-Terminals",
  214. cumulative_limit = "Kumulatives Limit",
  215. cumulative_limit_explanation = "Wie viel ein Benutzer vor der Zahlung von Zinsen austauschen kann",
  216. limit_reach_cost = "Zinsen",
  217. limit_reach_cost_explanation = "Wie viel Zinsen ein Benutzer bezahlt wenn er das Kumulatives Limit erreicht",
  218. set_owner ="Besitzer festlegen",
  219. set_owner_explanation = "Legen Sie das Konto fest, das die Zinsen einsammelt",
  220. en = "English",
  221. es = "Spanish",
  222. de = "Deutsch",
  223. not_assigned = "- nicht vergeben -",
  224. deleted_account = "- geloescht -"
  225. },
  226. }
  227. --------------------
  228.  
  229. -------------------- Variables
  230. local clientData = {}
  231. local filePath = "bank/"
  232. --------------------
  233.  
  234. -------------------- Functions
  235. local function updateSettingsFile()
  236. local f = fs.open(filePath.."settings.txt", "w")
  237. f.writeLine("Language:") -- Language label
  238. f.writeLine(lang)
  239. f.writeLine("Currency type:") -- Currency label
  240. f.writeLine(currencyType)
  241. f.writeLine("Currency value multiplier:") -- Value multiplier label
  242. f.writeLine(valueMultiplier)
  243. f.writeLine("Admin password:") -- Password label
  244. f.writeLine(terminalPassword)
  245. f.writeLine("Cumulative limit:") -- Cumulative limit label
  246. f.writeLine(cumulativeLimit)
  247. f.writeLine("Limit reach cost:") -- Cumulative price label
  248. f.writeLine(cumulativePrice)
  249. f.writeLine("Bank owner ID:") -- Bank owner label
  250. f.writeLine(bankOwnerKey)
  251. f.close()
  252. end
  253.  
  254. local function serverSettings()
  255. if (fs.exists(filePath.."settings.txt")) then
  256. local f = fs.open(filePath.."settings.txt", "r")
  257. f.readLine() -- Language label
  258. local line = f.readLine()
  259. if (line == "es") then
  260. lang = "es"
  261. else
  262. lang = "en"
  263. end
  264. f.readLine() -- Currency type label
  265. currencyType = f.readLine()
  266. f.readLine() -- Value multiplier label
  267. valueMultiplier = f.readLine()
  268. f.readLine() -- Password label
  269. terminalPassword = f.readLine()
  270. f.readLine() -- Cumulative limit label
  271. cumulativeLimit = f.readLine()
  272. f.readLine() -- Cumulative price label
  273. cumulativePrice = f.readLine()
  274. f.readLine() -- Bank Owner label
  275. bankOwnerKey = f.readLine()
  276. f.close()
  277. else
  278. -- Create file with default values
  279. updateSettingsFile()
  280. end
  281. end
  282.  
  283. local function loadClients()
  284. local f = fs.open(filePath.."clientList.txt", "r")
  285. if (f ~= nil) then
  286. local line = f.readLine()
  287. clientData = {}
  288. repeat
  289. local key = line
  290. clientData[key] = {}
  291. local cf = fs.open(filePath.."clientData/"..key.."/info.txt", "r")
  292. local cline = cf.readLine()
  293. repeat
  294. if (cline == "name") then
  295. cline = cf.readLine()
  296. clientData[key].name = cline
  297. elseif (cline == "balance") then
  298. cline = cf.readLine()
  299. clientData[key].balance = tonumber(cline)
  300. elseif (cline == "color") then
  301. cline = cf.readLine()
  302. clientData[key].color = tonumber(cline)
  303. elseif (cline == "cumulative") then
  304. cline = cf.readLine()
  305. clientData[key].cumulative = tonumber(cline)
  306. end
  307. cline = cf.readLine()
  308. until cline == nil or cline == ""
  309. cf.close()
  310.  
  311. line = f.readLine()
  312. until line == nil or line == ""
  313. f.close()
  314. end
  315. end
  316.  
  317. local function getClientData(data)
  318. loadClients()
  319. return true, clientData
  320. end
  321.  
  322. local function getServerData(data)
  323. return true, {lang = lang, currency = currency[currencyType], valueMultiplier = valueMultiplier, terminalPassword = terminalPassword, cumulativeLimit = cumulativeLimit, cumulativePrice = cumulativePrice}
  324. end
  325.  
  326. local function updateClientFile(key)
  327. local f = fs.open(filePath.."clientData/"..key.."/info.txt", "w")
  328. if (f == nil) then return false, localization[lang].error_account end
  329.  
  330. f.writeLine("name")
  331. f.writeLine(clientData[key].name)
  332. f.writeLine("balance")
  333. f.writeLine(tostring(clientData[key].balance))
  334. f.writeLine("color")
  335. f.writeLine(tostring(clientData[key].color))
  336. f.writeLine("cumulative")
  337. f.writeLine(tostring(clientData[key].cumulative))
  338. f.close()
  339.  
  340. return true, localization[lang].success_update
  341. end
  342.  
  343. local function appendTransactionToLog(from, to, amount, balance, time, description)
  344. local f = fs.open(filePath.."clientData/"..from.."/log.txt", "a")
  345. f.writeLine("other")
  346. f.writeLine(to)
  347. f.writeLine("amount")
  348. f.writeLine(tostring(-amount))
  349. f.writeLine("balance")
  350. f.writeLine(tostring(balance))
  351. f.writeLine("time")
  352. f.writeLine(time)
  353. f.writeLine("description")
  354. f.writeLine(description)
  355. f.writeLine("")
  356. f.close()
  357. end
  358.  
  359. local function getCurrentTime()
  360. return os.date("%d/%m/%Y %H:%M")
  361. end
  362.  
  363. local function addCumulative(key, amount)
  364. if (cumulativeLimit == 0) then return nil end
  365. if (cumulativePrice == 0) then return nil end
  366. clientData[key].cumulative = clientData[key].cumulative+amount
  367. if (bankOwnerKey ~= 0) then
  368. if (key ~= bankOwnerKey) then
  369. if (clientData[bankOwnerKey] ~= nil) then
  370. local tax = 0
  371. local cumulative = clientData[key].cumulative
  372. while cumulative >= cumulativeLimit do
  373. tax = tax+cumulativePrice
  374. cumulative = cumulative-cumulativeLimit
  375. end
  376. if (tax > 0) then
  377. if clientData[key].balance >= tax then
  378. transaction({
  379. from = key,
  380. to = bankOwnerKey,
  381. amount = tax,
  382. description = localization[lang].expenses
  383. }, false)
  384. clientData[key].cumulative = cumulative
  385. end
  386. end
  387. end
  388. end
  389. end
  390. end
  391.  
  392. -- Move money from one account to another
  393. function transaction(data, addToCumulative) --from, to, amount, description
  394. if (addToCumulative == nil) then addToCumulative = true end
  395. local from = tostring(data.from)
  396. local to = tostring(data.to)
  397. local amount = tonumber(data.amount)
  398. local description = data.description
  399.  
  400. amount = math.ceil(amount*100)/100
  401.  
  402. if (amount == 0 or amount == nil) then
  403. return false, localization[lang].error_invalidamount
  404. end
  405.  
  406. loadClients()
  407.  
  408. if (from == to) then
  409. return false, localization[lang].error_same
  410. end
  411. if (clientData[from] == nil) then
  412. return false, localization[lang].error_from.." ("..from..")"
  413. end
  414. if (clientData[to] == nil) then
  415. return false, localization[lang].error_to.." ("..to..")"
  416. end
  417.  
  418. local previousFromBalance = clientData[from].balance
  419. local newFromBalance = previousFromBalance-amount
  420.  
  421. if (newFromBalance < 0 and not addToCumulative) then
  422. return false, localization[lang].error_notenoughbalance
  423. end
  424.  
  425. local previousToBalance = clientData[to].balance
  426. local newToBalance = previousToBalance+amount
  427. local time = getCurrentTime()
  428.  
  429. clientData[from].balance = newFromBalance
  430. clientData[to].balance = newToBalance
  431.  
  432. updateClientFile(from)
  433. updateClientFile(to)
  434.  
  435. appendTransactionToLog(from, to, amount, newFromBalance, time,description)
  436. appendTransactionToLog(to, from, -amount, newToBalance, time, description)
  437.  
  438. if (addToCumulative) then
  439. loadClients()
  440. addCumulative(from, amount)
  441. addCumulative(to, amount)
  442. updateClientFile(from)
  443. updateClientFile(to)
  444. end
  445.  
  446. return true, localization[lang].success_transaction
  447. end
  448.  
  449. local function deposit(data) --key, amount
  450. local key = data.key
  451. local amount = tonumber(data.amount)
  452. local description = localization[lang].deposit_description
  453.  
  454. --print(textutils.serialise(data))
  455. if (amount == 0 or amount == nil) then
  456. return false, localization[lang].error_invalidamount
  457. end
  458.  
  459. loadClients()
  460.  
  461. if (clientData[key] == nil) then
  462. return false, localization[lang].error_from.." ("..key..")"
  463. end
  464.  
  465. local previousBalance = clientData[key].balance
  466. local newBalance = previousBalance+amount
  467.  
  468. local time = getCurrentTime()
  469.  
  470. clientData[key].balance = newBalance
  471. updateClientFile(key)
  472.  
  473. appendTransactionToLog(key, key, -amount, newBalance, time, description)
  474.  
  475. return true, localization[lang].success_transaction
  476. end
  477.  
  478. local function withdraw(data) --key, amount
  479. local key = data.key
  480. local amount = tonumber(data.amount)
  481. local description = localization[lang].withdraw_description
  482.  
  483. if (amount == 0 or amount == nil) then
  484. return false, localization[lang].error_invalidamount
  485. end
  486.  
  487. loadClients()
  488.  
  489. if (key == nil or clientData[key] == nil) then
  490. return false, localization[lang].error_from.." ("..tostring(key)..")"
  491. end
  492.  
  493. local previousBalance = clientData[key].balance
  494. local newBalance = previousBalance-amount
  495.  
  496. if (newBalance < 0) then
  497. return false, localization[lang].error_notenoughbalance
  498. end
  499.  
  500. local time = getCurrentTime()
  501. clientData[key].balance = newBalance
  502. updateClientFile(key)
  503.  
  504. appendTransactionToLog(key, key, amount, newBalance, time, description)
  505.  
  506. return true, localization[lang].success_transaction
  507. end
  508.  
  509. local function getTransactionLog(data) --key
  510. local key = data.key
  511.  
  512. local log = {}
  513. local logCounter = 1
  514. local f = fs.open(filePath.."clientData/"..key.."/log.txt", "r")
  515. local line = f.readLine()
  516. while line ~= nil do
  517. local lline = line
  518. local other = ""
  519. local amount = 0
  520. local balance = 0
  521. local time = ""
  522. local description = ""
  523.  
  524. while lline ~= "" and lline ~= nil do
  525. if (lline == "other") then
  526. other = f.readLine()
  527. elseif (lline == "amount") then
  528. amount = f.readLine()
  529. elseif (lline == "balance") then
  530. balance = f.readLine()
  531. elseif (lline == "time") then
  532. time = f.readLine()
  533. elseif (lline == "description") then
  534. description = f.readLine()
  535. end
  536. lline = f.readLine()
  537. end
  538.  
  539. log[logCounter] = {
  540. other = other,
  541. amount = amount,
  542. balance = balance,
  543. time = time,
  544. description = description
  545. }
  546.  
  547. logCounter = logCounter+1
  548.  
  549. line = f.readLine()
  550. end
  551.  
  552. return true, log
  553. end
  554.  
  555. -- Create a new client, with its files and folders, given a name, a starting balance and a color
  556. local function newClient(data) --name, balance, color
  557. local name = data.name
  558. local color = data.color
  559.  
  560. local bankKey = "1000"
  561.  
  562. local firstFreeClientNumber = 0
  563. while firstFreeClientNumber < 9999 do
  564. firstFreeClientNumber = firstFreeClientNumber+1
  565. local free = true
  566. for k, v in pairs(clientData) do
  567. local clientNumber = tonumber(string.sub(k, 5, 8))
  568. if (clientNumber == firstFreeClientNumber) then
  569. free = false
  570. break
  571. end
  572. end
  573. if (free) then
  574. break
  575. end
  576. end
  577.  
  578. local clientNumber = tostring(firstFreeClientNumber)
  579. clientNumber = string.rep("0", 4-string.len(clientNumber))..clientNumber
  580. local randomKey = ""
  581. for i=1, 8 do
  582. randomKey = randomKey..tostring(math.random(10)-1)
  583. end
  584. local key = bankKey..clientNumber..randomKey
  585.  
  586. local f = fs.open(filePath.."clientList.txt", "a")
  587. f.writeLine(key)
  588. f.close()
  589.  
  590. fs.makeDir(filePath.."clientData")
  591. fs.makeDir(filePath.."clientData/"..key)
  592.  
  593. -- Create basic info
  594. clientData[key] = {
  595. name = name,
  596. balance = 0,
  597. color = color,
  598. cumulative = 0
  599. }
  600. updateClientFile(key)
  601.  
  602. -- Create transaction log
  603. local f = fs.open(filePath.."clientData/"..key.."/log.txt", "w")
  604. f.close()
  605.  
  606. return true, localization[lang].success_account
  607. end
  608.  
  609. local function deleteAccount(data) --key
  610. local key = data.key
  611.  
  612. clientData[key] = nil
  613. local f = fs.open(filePath.."clientList.txt", "w")
  614. for k, v in pairs(clientData) do
  615. f.writeLine(k)
  616. end
  617. f.close()
  618. fs.delete(filePath.."clientData/"..key)
  619. return true, localization[lang].account_deleted
  620. end
  621.  
  622. local function processRequest(func, sender, data)
  623. local success, response = func(data)
  624. local message = {
  625. success = success,
  626. response = response
  627. }
  628. --print("Responding.")
  629. rednet.send(sender, message, "mermegold")
  630. end
  631.  
  632. ---------------- Start
  633. serverSettings()
  634. loadClients()
  635.  
  636. local modem = peripheral.find("modem")
  637. while (modem == nil) do
  638. modem = peripheral.find("modem")
  639. if (modem == nil) then
  640. term.setBackgroundColor(colors.red)
  641. term.setTextColor(colors.white)
  642. term.clear()
  643. term.setCursorPos(1,1)
  644. print("Ender modem required. Please connect a modem to continue...")
  645. os.pullEvent("peripheral")
  646. end
  647. end
  648. peripheral.find("modem", rednet.open)
  649.  
  650. function listen()
  651. while true do
  652. local sender, message = rednet.receive("mermegold")
  653. --print("#"..sender.." requested "..message.action)
  654.  
  655. if (message.action == "getClientData") then --------------- Get Client Data
  656. processRequest(getClientData, sender, message)
  657.  
  658. elseif (message.action == "getServerData") then --------------- Get Client Data
  659. processRequest(getServerData, sender, message)
  660.  
  661. elseif (message.action == "getTransactionLog") then ------- Get Transaction Log
  662. processRequest(getTransactionLog, sender, message)
  663.  
  664. elseif (message.action == "transaction") then ------------- Make a transaction
  665. processRequest(transaction, sender, message)
  666.  
  667. elseif (message.action == "deposit") then ----------------- Make a deposit
  668. processRequest(deposit, sender, message)
  669.  
  670. elseif (message.action == "withdraw") then ------------- Make a withdrawal
  671. processRequest(withdraw, sender, message)
  672.  
  673. elseif (message.action == "new") then --------------------- Create an account
  674. processRequest(newClient, sender, message)
  675.  
  676. elseif (message.action == "delete") then ------------------ Delete an account
  677. processRequest(deleteAccount, sender, message)
  678.  
  679. else ------------------------------------------------------ Not a valid message
  680. local message = {
  681. success = false,
  682. response = "Invalid request"
  683. }
  684. rednet.send(sender, message, "mermegold")
  685. end
  686. end
  687. end
  688.  
  689. function main()
  690. while true do
  691. while true do
  692. local ownerName = localization[lang].not_assigned
  693. if (tonumber(bankOwnerKey) > 0) then
  694. if (clientData[bankOwnerKey] == nil) then
  695. ownerName = localization[lang].deleted_account
  696. else
  697. ownerName = clientData[bankOwnerKey].name
  698. end
  699. end
  700. local command = bankapi.optionMenu(localization[lang].title, {
  701. {option = "language",
  702. text = localization[lang].language..": "..localization[lang][lang]},
  703. {option = "currency_type",
  704. text = localization[lang].currency_type..": "..currency[currencyType][1].name[lang]},
  705. {option = "value_multiplier",
  706. text = localization[lang].value_multiplier..": "..valueMultiplier.."$"},
  707. {option = "cumulative_limit",
  708. text = localization[lang].cumulative_limit..": "..cumulativeLimit.."$"},
  709. {option = "limit_reach_cost",
  710. text = localization[lang].limit_reach_cost..": "..cumulativePrice.."$"},
  711. {option = "password",
  712. text = localization[lang].password..": "..terminalPassword},
  713. {option = "set_owner",
  714. text = localization[lang].set_owner..": "..ownerName},
  715. }, 2, 40)
  716.  
  717. if (command == "language") then
  718. local subcommand = bankapi.optionMenu(localization[lang].language, {
  719. {option = "en",
  720. text = "English"},
  721. {option = "es",
  722. text = "Espanol"},
  723. {option = "de",
  724. text = "Deutsch"},
  725. }, 2)
  726. lang = subcommand
  727. updateSettingsFile()
  728. break
  729. elseif (command == "currency_type") then
  730. local subcommand = bankapi.optionMenu(localization[lang].currency_type, {
  731. {option = "diamond",
  732. text = currency.diamond[1].name[lang]},
  733. {option = "gold",
  734. text = currency.gold[1].name[lang]},
  735. {option = "emerald",
  736. text = currency.emerald[1].name[lang]}
  737. }, 2)
  738. currencyType = subcommand
  739. updateSettingsFile()
  740. break
  741. elseif (command == "value_multiplier") then
  742. local amount = bankapi.inputNumberScreen({localization[lang].value_multiplier_explanation}, 1)
  743. amount = tonumber(amount)
  744. if (amount == nil) then break end
  745. if (amount <= 0) then bankapi.errorScreen(localization[lang].error_invalidamount) end
  746. valueMultiplier = amount
  747. updateSettingsFile()
  748. break
  749. elseif (command == "password") then
  750. local newPassword = bankapi.inputTextScreen({localization[lang].password_explanation}, 1, 10)
  751. if (newPassword == "" or newPassword == nil) then break end
  752. terminalPassword = newPassword
  753. updateSettingsFile()
  754. break
  755. elseif (command == "cumulative_limit") then
  756. local amount = bankapi.inputNumberScreen({localization[lang].cumulative_limit_explanation}, 1)
  757. amount = tonumber(amount)
  758. if (amount == nil) then break end
  759. if (amount <= 0) then bankapi.errorScreen(localization[lang].error_invalidamount) end
  760. cumulativeLimit = amount
  761. updateSettingsFile()
  762. break
  763. elseif (command == "limit_reach_cost") then
  764. local amount = bankapi.inputNumberScreen({localization[lang].limit_reach_cost_explanation}, 1)
  765. amount = tonumber(amount)
  766. if (amount == nil) then break end
  767. if (amount <= 0) then bankapi.errorScreen(localization[lang].error_invalidamount) end
  768. cumulativePrice = amount
  769. updateSettingsFile()
  770. break
  771. elseif (command == "set_owner") then
  772. local account = bankapi.selectAccountScreen({localization[lang].set_owner_explanation}, 1, 0, clientData)
  773. if (account == nil) then break end
  774. if (tonumber(account) > 0) then
  775. bankOwnerKey = account
  776. updateSettingsFile()
  777. end
  778. end
  779. end
  780. end
  781. end
  782.  
  783. parallel.waitForAll(listen, main)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement