Skip to content

Commit

Permalink
fix: check if bankable is valid player before emitting metric
Browse files Browse the repository at this point in the history
  • Loading branch information
luan committed Mar 17, 2024
1 parent 0cca850 commit d21b49c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/game/bank/bank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ bool Bank::transferTo(const std::shared_ptr<Bank> destination, uint64_t amount)
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 (destinationBankable->getPlayer() != nullptr) {
g_metrics().addCounter("balance_increase", amount, { { "player", destinationBankable()->getPlayer()->getName() }, { "context", "bank_transfer" } });
g_metrics().addCounter("balance_decrease", amount, { { "player", getBankable()->getPlayer()->getName() }, { "context", "bank_transfer" } });
}
return true;
}

Expand Down Expand Up @@ -151,6 +153,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 d21b49c

Please sign in to comment.