From aff775f488c5eda79cb6299d03237043e7268980 Mon Sep 17 00:00:00 2001 From: BruebachL <44814898+BruebachL@users.noreply.github.com> Date: Mon, 15 Sep 2025 01:09:30 +0200 Subject: [PATCH] Don't get local ID from playerInfo on concession (#6143) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Don't get local ID from playerInfo. Took 39 minutes Took 39 seconds * Introduce isLocalPlayer convenience method. Took 21 minutes --------- Co-authored-by: Lukas BrĂ¼bach --- cockatrice/src/game/player/player_manager.cpp | 7 ++++++- cockatrice/src/game/player/player_manager.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cockatrice/src/game/player/player_manager.cpp b/cockatrice/src/game/player/player_manager.cpp index 461747562..bbe128bf8 100644 --- a/cockatrice/src/game/player/player_manager.cpp +++ b/cockatrice/src/game/player/player_manager.cpp @@ -35,6 +35,11 @@ Player *PlayerManager::getActiveLocalPlayer(int activePlayer) const return nullptr; } +bool PlayerManager::isLocalPlayer(int playerId) +{ + return game->getGameState()->getIsLocalGame() || playerId == localPlayerId; +} + Player *PlayerManager::addPlayer(int playerId, const ServerInfo_User &info) { auto *newPlayer = new Player(info, playerId, isLocalPlayer(playerId) || game->getGameState()->getIsLocalGame(), @@ -68,7 +73,7 @@ Player *PlayerManager::getPlayer(int playerId) const void PlayerManager::onPlayerConceded(int playerId, bool conceded) { // GameEventHandler cares about this for sending the concede/unconcede commands - if (playerId == getActiveLocalPlayer(playerId)->getPlayerInfo()->getId()) { + if (isLocalPlayer(playerId)) { if (conceded) { emit activeLocalPlayerConceded(); } else { diff --git a/cockatrice/src/game/player/player_manager.h b/cockatrice/src/game/player/player_manager.h index 92e492510..32f4a5753 100644 --- a/cockatrice/src/game/player/player_manager.h +++ b/cockatrice/src/game/player/player_manager.h @@ -48,6 +48,7 @@ public: } Player *getActiveLocalPlayer(int activePlayer) const; + bool isLocalPlayer(int playerId); Player *addPlayer(int playerId, const ServerInfo_User &info);