Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/elsongabriel/canary into fi…
Browse files Browse the repository at this point in the history
…x/global-ss
  • Loading branch information
elsongabriel committed Mar 18, 2024
2 parents 02065ed + d643fba commit 261cc8b
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/game/bank/bank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,33 @@ bool Bank::transferTo(const std::shared_ptr<Bank> destination, uint64_t amount)
g_logger().error("Bank::transferTo: destinationBankable is nullptr");
return false;
}
if (destinationBankable->getPlayer() != nullptr) {
auto player = destinationBankable->getPlayer();
auto name = asLowerCaseString(player->getName());

auto destinationPlayer = destinationBankable->getPlayer();
if (destinationPlayer != nullptr) {
auto name = asLowerCaseString(destinationPlayer->getName());
replaceString(name, " ", "");
if (deniedNames.contains(name)) {
g_logger().warn("Bank::transferTo: denied name: {}", name);
return false;
}
if (player->getTown()->getID() < minTownId) {
g_logger().warn("Bank::transferTo: denied town: {}", player->getTown()->getID());
if (destinationPlayer->getTown()->getID() < minTownId) {
g_logger().warn("Bank::transferTo: denied town: {}", destinationPlayer->getTown()->getID());
return false;
}
}

if (!(debit(amount) && destination->credit(amount))) {
return false;
}
g_metrics().addCounter("balance_increase", amount, { { "player", destination->getBankable()->getPlayer()->getName() }, { "context", "bank_transfer" } });
g_metrics().addCounter("balance_decrease", amount, { { "player", getBankable()->getPlayer()->getName() }, { "context", "bank_transfer" } });

if (destinationPlayer) {
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" } });
}

return true;
}

Expand Down Expand Up @@ -151,6 +159,8 @@ bool Bank::deposit(const std::shared_ptr<Bank> destination, uint64_t amount) {
if (!g_game().removeMoney(bankable->getPlayer(), amount)) {
return false;
}
g_metrics().addCounter("balance_increase", amount, { { "player", bankable->getPlayer()->getName() }, { "context", "bank_deposit" } });
if (bankable->getPlayer() != nullptr) {
g_metrics().addCounter("balance_decrease", amount, { { "player", bankable->getPlayer()->getName() }, { "context", "bank_deposit" } });
}
return destination->credit(amount);
}

0 comments on commit 261cc8b

Please sign in to comment.