mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 09:05:10 -07:00
[Server] Replay tournament state to late joiners
The bracket, phase and standings live in Event_TournamentState, which only flows on mutation. Without a copy a player or spectator joining after round one would sit on an empty bracket until the next advance, so the current state is now enqueued as part of the join snapshot. Extracts Event_TournamentState building into buildStateEvent() so both the broadcast path and the join path share one source of truth.
This commit is contained in:
parent
99a409de09
commit
80703adbbb
3 changed files with 18 additions and 2 deletions
|
|
@ -812,6 +812,15 @@ void Server_Game::createGameJoinedEvent(Server_AbstractParticipant *joiningParti
|
|||
}
|
||||
|
||||
rc.enqueuePostResponseItem(ServerMessage::GAME_EVENT_CONTAINER, prepareGameEvent(event2, -1));
|
||||
|
||||
// A tournament's bracket/phase/standings live in Event_TournamentState, which
|
||||
// normally only flows on mutation. Without a copy here a late joiner would sit
|
||||
// on an empty bracket until the next round advances, so replay the current
|
||||
// state as part of the join snapshot.
|
||||
if (tournament) {
|
||||
rc.enqueuePostResponseItem(ServerMessage::GAME_EVENT_CONTAINER,
|
||||
prepareGameEvent(tournament->buildStateEvent(), -1));
|
||||
}
|
||||
}
|
||||
|
||||
void Server_Game::sendGameEventContainer(GameEventContainer *cont,
|
||||
|
|
|
|||
|
|
@ -635,7 +635,7 @@ void Server_Tournament::checkAndAdvanceRound(GameEventStorage &ges)
|
|||
}
|
||||
}
|
||||
|
||||
void Server_Tournament::broadcastTournamentState(GameEventStorage &ges)
|
||||
Event_TournamentState Server_Tournament::buildStateEvent() const
|
||||
{
|
||||
QMutexLocker locker(&tournamentMutex);
|
||||
|
||||
|
|
@ -682,5 +682,10 @@ void Server_Tournament::broadcastTournamentState(GameEventStorage &ges)
|
|||
p->set_player2_match_wins(pairing.player2MatchWins);
|
||||
}
|
||||
|
||||
ges.enqueueGameEvent(state, -1);
|
||||
return state;
|
||||
}
|
||||
|
||||
void Server_Tournament::broadcastTournamentState(GameEventStorage &ges)
|
||||
{
|
||||
ges.enqueueGameEvent(buildStateEvent(), -1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ public:
|
|||
void recordMatchResult(int playerId1, int playerId2, int winnerId, GameEventStorage &ges);
|
||||
bool recordMatchResultByGameId(int gameId, int winnerId, GameEventStorage &ges);
|
||||
void broadcastTournamentState(GameEventStorage &ges);
|
||||
// Current tournament state message, for replaying to a participant joining late.
|
||||
Event_TournamentState buildStateEvent() const;
|
||||
|
||||
bool isStarted() const
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue