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 af7126a commit 0a56230
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" } });

Check failure on line 118 in src/game/bank/bank.cpp

View workflow job for this annotation

GitHub Actions / windows-2022-windows-release

term does not evaluate to a function taking 0 arguments

Check failure on line 118 in src/game/bank/bank.cpp

View workflow job for this annotation

GitHub Actions / windows-2022-windows-release

'void metrics::Metrics::addCounter(std::string_view,double,std::map<std::string,std::string,std::less<std::string>,std::allocator<std::pair<const std::string,std::string>>>)': cannot convert argument 3 from 'initializer list' to 'std::map<std::string,std::string,std::less<std::string>,std::allocator<std::pair<const std::string,std::string>>>'

Check failure on line 118 in src/game/bank/bank.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-20.04-linux-release

no match for call to ‘(std::shared_ptr<Bankable>) ()’

Check failure on line 118 in src/game/bank/bank.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-20.04-linux-release

cannot convert ‘<brace-enclosed initializer list>’ to ‘std::map<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’

Check failure on line 118 in src/game/bank/bank.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-20.04-linux-debug

no match for call to ‘(std::shared_ptr<Bankable>) ()’

Check failure on line 118 in src/game/bank/bank.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-20.04-linux-debug

cannot convert ‘<brace-enclosed initializer list>’ to ‘std::map<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’

Check failure on line 118 in src/game/bank/bank.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-release

no match for call to ‘(std::shared_ptr<Bankable>) ()’

Check failure on line 118 in src/game/bank/bank.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-release

cannot convert ‘<brace-enclosed initializer list>’ to ‘std::map<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’

Check failure on line 118 in src/game/bank/bank.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-debug

no match for call to ‘(std::shared_ptr<Bankable>) ()’

Check failure on line 118 in src/game/bank/bank.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-debug

cannot convert ‘<brace-enclosed initializer list>’ to ‘std::map<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >’
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 0a56230

Please sign in to comment.