From d21b49cdb6315590192c0e96563307bf7e07e5cc Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Sun, 17 Mar 2024 10:29:59 -0700 Subject: [PATCH] fix: check if bankable is valid player before emitting metric --- src/game/bank/bank.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/game/bank/bank.cpp b/src/game/bank/bank.cpp index 713ee645733..a9681164a7f 100644 --- a/src/game/bank/bank.cpp +++ b/src/game/bank/bank.cpp @@ -114,8 +114,10 @@ bool Bank::transferTo(const std::shared_ptr 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; } @@ -151,6 +153,8 @@ bool Bank::deposit(const std::shared_ptr 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); }