From 793cfe816b545b1e841122bcb77cb5184d4cc914 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= Date: Mon, 2 Nov 2026 21:48:21 +0100 Subject: [PATCH] [Server] Send game-joined player list in seat order --- .../server/remote/game/server_game.cpp | 43 +++++++++++-------- .../network/server/remote/game/server_game.h | 1 + 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/libcockatrice_network/libcockatrice/network/server/remote/game/server_game.cpp b/libcockatrice_network/libcockatrice/network/server/remote/game/server_game.cpp index 96a8b61d6..e2724523e 100644 --- a/libcockatrice_network/libcockatrice/network/server/remote/game/server_game.cpp +++ b/libcockatrice_network/libcockatrice/network/server/remote/game/server_game.cpp @@ -294,23 +294,11 @@ int Server_Game::getSpectatorCount() const return result; } -void Server_Game::createGameStateChangedEvent(Event_GameStateChanged *event, - Server_AbstractParticipant *recipient, - bool omniscient, - bool withUserInfo) +QList Server_Game::getParticipantsInSeatOrder() const { - event->set_seconds_elapsed(secondsElapsed); - if (gameStarted) { - event->set_game_started(true); - event->set_active_player_id(0); - event->set_active_phase(0); - } else { - event->set_game_started(false); - } - - // Emit the player list in seat order so every client (including old ones - // that ignore Event_PlayerOrderChanged) sees the current seating. Player - // ids are stable; only this ordering changes on shuffle/reorder. + // Players in seat order first (fall back to id order for seats predating + // seatOrder), then spectators. Player ids are stable; only the ordering + // changes on shuffle/reorder. QList ordered; ordered.reserve(participants.size()); for (int id : seatOrder) { @@ -329,6 +317,27 @@ void Server_Game::createGameStateChangedEvent(Event_GameStateChanged *event, ordered.append(participant); } } + return ordered; +} + +void Server_Game::createGameStateChangedEvent(Event_GameStateChanged *event, + Server_AbstractParticipant *recipient, + bool omniscient, + bool withUserInfo) +{ + event->set_seconds_elapsed(secondsElapsed); + if (gameStarted) { + event->set_game_started(true); + event->set_active_player_id(0); + event->set_active_phase(0); + } else { + event->set_game_started(false); + } + + // Emit the player list in seat order so every client (including old ones + // that ignore Event_PlayerOrderChanged) sees the current seating. Player + // ids are stable; only this ordering changes on shuffle/reorder. + QList ordered = getParticipantsInSeatOrder(); for (Server_AbstractParticipant *participant : ordered) { participant->getInfo(event->add_player_list(), recipient, omniscient, withUserInfo); } @@ -988,7 +997,7 @@ void Server_Game::createGameJoinedEvent(Server_AbstractParticipant *joiningParti event2.set_active_phase(activePhase); bool omniscient = (joiningParticipant->isSpectator() && spectatorsSeeEverything) || joiningParticipant->isJudge(); - for (auto *participant : participants.values()) { + for (auto *participant : getParticipantsInSeatOrder()) { participant->getInfo(event2.add_player_list(), joiningParticipant, omniscient, true); } diff --git a/libcockatrice_network/libcockatrice/network/server/remote/game/server_game.h b/libcockatrice_network/libcockatrice/network/server/remote/game/server_game.h index 769180a6d..23ba96598 100644 --- a/libcockatrice_network/libcockatrice/network/server/remote/game/server_game.h +++ b/libcockatrice_network/libcockatrice/network/server/remote/game/server_game.h @@ -115,6 +115,7 @@ private: Server_AbstractParticipant *recipient, bool omniscient, bool withUserInfo); + QList getParticipantsInSeatOrder() const; void reseatPlayers(const QList &orderedParticipants, bool randomized); void storeGameInformation(); bool canSeePrivateEventsFor(const Server_AbstractParticipant *participant, int privatePlayerId) const;