From f05629ffa34ba66d040ec21f4448c42c9e65b398 Mon Sep 17 00:00:00 2001 From: Luan Luciano Date: Tue, 10 Sep 2024 23:31:48 -0300 Subject: [PATCH] update --- config.lua.dist | 4 +-- src/config/config_enums.hpp | 2 +- src/config/configmanager.cpp | 2 +- src/game/bank/bank.cpp | 29 +++++++++++++------ src/game/bank/bank.hpp | 2 +- .../functions/core/game/bank_functions.cpp | 12 ++++---- 6 files changed, 31 insertions(+), 20 deletions(-) diff --git a/config.lua.dist b/config.lua.dist index 4d676eed2bb..113c6b2a4c9 100644 --- a/config.lua.dist +++ b/config.lua.dist @@ -254,7 +254,7 @@ onlyPremiumAccount = false -- NOTE: enablePlayerPutItemInAmmoSlot = true, will enable players to put any items on ammo slot, more used in custom shopping system -- NOTE: startStreakLevel will make a reward streak level for new players who never logged in -- NOTE: if showLootsInBestiary is true, will cause all loots to be shown in the bestiary even if the player has not reached the required number of kills --- NOTE: minTownIdToBankTransfer blocks towns less than defined from receiving money transfers +-- NOTE: minTownIdToBankTransferFromMain blocks towns less than defined from receiving money transfers -- NOTE: enableSupportOutfit enable GODS and GMS to select support outfit (gamemaster, customer support or community manager) stashMoving = false stashItemCount = 5000 @@ -275,7 +275,7 @@ storeInboxMaxLimit = 2000 enablePlayerPutItemInAmmoSlot = false startStreakLevel = 0 showLootsInBestiary = false -minTownIdToBankTransfer = 4 +minTownIdToBankTransferFromMain = 4 enableSupportOutfit = true -- Teleport summon diff --git a/src/config/config_enums.hpp b/src/config/config_enums.hpp index bf480505014..1dfa71ce7dd 100644 --- a/src/config/config_enums.hpp +++ b/src/config/config_enums.hpp @@ -157,7 +157,7 @@ enum ConfigKey_t : uint16_t { METRICS_PROMETHEUS_ADDRESS, MIN_DELAY_BETWEEN_CONDITIONS, MIN_ELEMENTAL_RESISTANCE, - MIN_TOWN_ID_TO_BANK_TRANSFER, + MIN_TOWN_ID_TO_BANK_TRANSFER_FROM_MAIN, MOMENTUM_CHANCE_FORMULA_A, MOMENTUM_CHANCE_FORMULA_B, MOMENTUM_CHANCE_FORMULA_C, diff --git a/src/config/configmanager.cpp b/src/config/configmanager.cpp index e3757e44f56..45a0e795965 100644 --- a/src/config/configmanager.cpp +++ b/src/config/configmanager.cpp @@ -283,7 +283,7 @@ bool ConfigManager::load() { loadIntConfig(L, METRICS_OSTREAM_INTERVAL, "metricsOstreamInterval", 1000); loadIntConfig(L, MIN_DELAY_BETWEEN_CONDITIONS, "minDelayBetweenConditions", 0); loadIntConfig(L, MIN_ELEMENTAL_RESISTANCE, "minElementalResistance", -200); - loadIntConfig(L, MIN_TOWN_ID_TO_BANK_TRANSFER, "minTownIdToBankTransfer", 4); + loadIntConfig(L, MIN_TOWN_ID_TO_BANK_TRANSFER_FROM_MAIN, "minTownIdToBankTransferFromMain", 4); loadIntConfig(L, MONTH_KILLS_TO_RED, "monthKillsToRedSkull", 10); loadIntConfig(L, MULTIPLIER_ATTACKONFIST, "multiplierSpeedOnFist", 5); loadIntConfig(L, ORANGE_SKULL_DURATION, "orangeSkullDuration", 7); diff --git a/src/game/bank/bank.cpp b/src/game/bank/bank.cpp index d9a056396ce..60633e7346b 100644 --- a/src/game/bank/bank.cpp +++ b/src/game/bank/bank.cpp @@ -80,26 +80,28 @@ const std::set deniedNames = { "paladinsample" }; -bool Bank::transferTo(const std::shared_ptr destination, uint64_t amount) { +bool Bank::transferTo(const std::shared_ptr &destination, const uint64_t amount) { if (!destination) { g_logger().error("Bank::transferTo: destination is nullptr"); return false; } - auto bankable = getBankable(); + const auto bankable = getBankable(); if (!bankable) { g_logger().error("Bank::transferTo: bankable is nullptr"); return false; } - auto destinationBankable = destination->getBankable(); + const auto destinationBankable = destination->getBankable(); if (!destinationBankable) { g_logger().error("Bank::transferTo: destinationBankable is nullptr"); return false; } - auto destinationPlayer = destinationBankable->getPlayer(); - if (destinationPlayer != nullptr) { + const auto &destinationPlayer = destinationBankable->getPlayer(); + const auto &bankablePlayer = bankable->getPlayer(); + + if (destinationPlayer && bankablePlayer) { auto name = asLowerCaseString(destinationPlayer->getName()); replaceString(name, " ", ""); @@ -108,8 +110,17 @@ bool Bank::transferTo(const std::shared_ptr destination, uint64_t amount) return false; } - if (destinationPlayer->getTown()->getID() < g_configManager().getNumber(MIN_TOWN_ID_TO_BANK_TRANSFER, __FUNCTION__)) { - g_logger().warn("Bank::transferTo: denied town: {}", destinationPlayer->getTown()->getID()); + const auto destinationTownId = destinationPlayer->getTown()->getID(); + const auto bankableTownId = bankablePlayer->getTown()->getID(); + const auto minTownIdToTransferFromMain = g_configManager().getNumber(MIN_TOWN_ID_TO_BANK_TRANSFER_FROM_MAIN, __FUNCTION__); + + if (destinationTownId < minTownIdToTransferFromMain && bankableTownId >= minTownIdToTransferFromMain) { + g_logger().warn("Bank::transferTo: denied town: {}", destinationTownId); + return false; + } + + if (bankableTownId < minTownIdToTransferFromMain && destinationTownId >= minTownIdToTransferFromMain) { + g_logger().warn("Bank::transferTo: denied town: {}", destinationTownId); return false; } } @@ -122,8 +133,8 @@ bool Bank::transferTo(const std::shared_ptr destination, uint64_t amount) g_metrics().addCounter("balance_increase", amount, { { "player", destinationPlayer->getName() }, { "context", "bank_transfer" } }); } - if (bankable->getPlayer()) { - g_metrics().addCounter("balance_decrease", amount, { { "player", bankable->getPlayer()->getName() }, { "context", "bank_transfer" } }); + if (bankablePlayer) { + g_metrics().addCounter("balance_decrease", amount, { { "player", bankablePlayer->getName() }, { "context", "bank_transfer" } }); } return true; diff --git a/src/game/bank/bank.hpp b/src/game/bank/bank.hpp index 9e65a55aeb9..7fdb740a022 100644 --- a/src/game/bank/bank.hpp +++ b/src/game/bank/bank.hpp @@ -42,7 +42,7 @@ class Bank : public SharedObject { bool balance(uint64_t amount) const; uint64_t balance(); bool hasBalance(uint64_t amount); - bool transferTo(const std::shared_ptr destination, uint64_t amount); + bool transferTo(const std::shared_ptr &destination, const uint64_t amount); bool withdraw(std::shared_ptr player, uint64_t amount); bool deposit(const std::shared_ptr destination); bool deposit(const std::shared_ptr destination, uint64_t amount); diff --git a/src/lua/functions/core/game/bank_functions.cpp b/src/lua/functions/core/game/bank_functions.cpp index f6732b8bf70..efa8ca2a5dc 100644 --- a/src/lua/functions/core/game/bank_functions.cpp +++ b/src/lua/functions/core/game/bank_functions.cpp @@ -57,36 +57,36 @@ int BankFunctions::luaBankHasBalance(lua_State* L) { int BankFunctions::luaBankTransfer(lua_State* L) { // Bank.transfer(fromPlayerOrGuild, toPlayerOrGuild, amount) - auto source = getBank(L, 1); + const auto &source = getBank(L, 1); if (source == nullptr) { g_logger().debug("BankFunctions::luaBankTransfer: source is null"); reportErrorFunc("Bank is nullptr"); return 1; } - std::shared_ptr destination = getBank(L, 2); + const auto &destination = getBank(L, 2); if (destination == nullptr) { g_logger().debug("BankFunctions::luaBankTransfer: destination is null"); reportErrorFunc("Bank is nullptr"); return 1; } - uint64_t amount = getNumber(L, 3); + const uint64_t amount = getNumber(L, 3); pushBoolean(L, source->transferTo(destination, amount)); return 1; } int BankFunctions::luaBankTransferToGuild(lua_State* L) { // Bank.transfer(fromPlayerOrGuild, toGuild, amount) - auto source = getBank(L, 1); + const auto &source = getBank(L, 1); if (source == nullptr) { reportErrorFunc("Source is nullptr"); return 1; } - std::shared_ptr destination = getBank(L, 2, true /* isGuild */); + const auto & destination = getBank(L, 2, true /* isGuild */); if (destination == nullptr) { reportErrorFunc("Destination is nullptr"); return 1; } - uint64_t amount = getNumber(L, 3); + const uint64_t amount = getNumber(L, 3); pushBoolean(L, source->transferTo(destination, amount)); return 1; }