Cockatrice 2026-09-01-Development-3.1.0-beta.10
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
GameEventHandler Class Reference

Central dispatcher for game-wide commands and events. More...

#include <game_event_handler.h>

Inheritance diagram for GameEventHandler:
[legend]
Collaboration diagram for GameEventHandler:
[legend]

Public Slots

Command dispatch slots

Low-level command transmission.

void sendGameCommand (PendingCommand *pend, int playerId=-1)
 Send a prepared PendingCommand.
void sendGameCommand (const ::google::protobuf::Message &command, int playerId=-1)
 Send a single protobuf command.
void commandFinished (const Response &response)
 Called when a PendingCommand finishes execution.

Signals

Core state signals
void emitUserEvent ()
void containerProcessingStarted (GameEventContext context)
void containerProcessingDone ()
void gameFlooded ()
void setContextJudgeName (QString judgeName)
Player and spectator signals
void addPlayerToAutoCompleteList (QString playerName)
void localPlayerDeckSelected (PlayerLogic *localPlayer, int playerId, ServerInfo_Player playerInfo)
void remotePlayerDeckSelected (QString deckList, int playerId, QString playerName)
void remotePlayersDecksSelected (QVector< QPair< int, QPair< QString, QString > > > opponentDecks)
void localPlayerSideboardLocked (int playerId, bool sideboardLocked)
void localPlayerReadyStateChanged (int playerId, bool ready)
Game flow signals
void gameStopped ()
void gameClosed ()
void playerPropertiesChanged (const ServerInfo_PlayerProperties &prop, int playerId)
void playerJoined (const ServerInfo_PlayerProperties &playerInfo)
void playerLeft (int leavingPlayerId)
void playerKicked ()
void spectatorJoined (const ServerInfo_PlayerProperties &spectatorInfo)
void spectatorLeft (int leavingSpectatorId)
void arrowDeleted (int creatorId, int arrowId)
Logging signals

Signals consumed by MessageLogWidget.

void logSpectatorSay (ServerInfo_User userInfo, QString message)
void logSpectatorLeave (QString name, QString reason)
void logGameStart ()
void logReadyStart (PlayerLogic *player)
void logNotReadyStart (PlayerLogic *player)
void logDeckSelect (PlayerLogic *player, QString deckHash, int sideboardSize)
void logSideboardLockSet (PlayerLogic *player, bool sideboardLocked)
void logConnectionStateChanged (PlayerLogic *player, bool connected)
void logJoinSpectator (QString spectatorName)
void logJoinPlayer (PlayerLogic *player)
void logLeave (PlayerLogic *player, QString reason)
void logKicked ()
void logTurnReversed (PlayerLogic *player, bool reversed)
void logGameClosed ()
void logActivePlayer (PlayerLogic *activePlayer)
void logActivePhaseChanged (int activePhase)
void logConcede (int playerId)
void logUnconcede (int playerId)

Public Member Functions

Construction

Lifecycle and ownership.

 GameEventHandler (AbstractGame *_game)
 Construct a GameEventHandler.
Outgoing game commands

Commands initiated locally and sent to the server.

These methods construct and send protobuf commands corresponding to user actions in the UI.

void handleNextTurn ()
 Request advancing the game to the next turn.
void handleReverseTurn ()
 Request reversing the current turn order.
void handleActiveLocalPlayerConceded ()
 Concede the game for the currently active local player.
void handleActiveLocalPlayerUnconceded ()
 Undo a previous concede for the active local player.
void handleActivePhaseChanged (int phase)
 Set the active phase of the game.
void handleGameLeft ()
 Leave the current game session.
void handleChatMessageSent (const QString &chatMessage)
 Send a chat message to all players and spectators.
void handleArrowDeletion (int creatorId, int arrowId)
 Delete an existing arrow.
void handleArrowDeletionFinished (const Response &response, int creatorId, int arrowId)
Incoming event processing

Entry points for server-sent events.

void processGameEventContainer (const GameEventContainer &cont, AbstractClient *client, EventProcessingOptions options)
 Process a container of game events received from the server.
Command preparation helpers

Internal helpers for building command containers.

PendingCommandprepareGameCommand (const ::google::protobuf::Message &cmd)
 Wrap a single protobuf command in a PendingCommand.
PendingCommandprepareGameCommand (const QList< const ::google::protobuf::Message * > &cmdList)
 Wrap multiple protobuf commands in a single PendingCommand.
Spectator event handlers

Events originating from spectators.

void eventSpectatorSay (const Event_GameSay &event, int eventPlayerId, const GameEventContext &context)
 Handle a spectator chat message.
void eventSpectatorLeave (const Event_Leave &event, int eventPlayerId, const GameEventContext &context)
 Handle a spectator leaving the game.
Game state event handlers

Events that affect global game state.

void eventGameStateChanged (const Event_GameStateChanged &event, int eventPlayerId, const GameEventContext &context)
 Handle a full game state update from the server.
void processCardAttachmentsForPlayers (const Event_GameStateChanged &event)
 Update card attachment relationships for all players.
void eventGameHostChanged (const Event_GameHostChanged &event, int eventPlayerId, const GameEventContext &context)
 Handle a change in game host.
void eventGameClosed (const Event_GameClosed &event, int eventPlayerId, const GameEventContext &context)
 Handle the game being closed by the server.
void eventSetActivePlayer (const Event_SetActivePlayer &event, int eventPlayerId, const GameEventContext &context)
 Handle a change of the active player.
void eventSetActivePhase (const Event_SetActivePhase &event, int eventPlayerId, const GameEventContext &context)
 Handle a change of the active phase.
void eventReverseTurn (const Event_ReverseTurn &event, int eventPlayerId, const GameEventContext &context)
 Handle a turn reversal event.
void eventPing (const Event_Ping &event, int eventPlayerId, const GameEventContext &context)
 Handle ping / latency updates.
Player lifecycle and property handlers

Events related to players joining, leaving, or changing state.

void eventPlayerPropertiesChanged (const Event_PlayerPropertiesChanged &event, int eventPlayerId, const GameEventContext &context)
 Handle updates to a player's properties.
void eventJoin (const Event_Join &event, int eventPlayerId, const GameEventContext &context)
 Handle a player or spectator joining the game.
void eventLeave (const Event_Leave &event, int eventPlayerId, const GameEventContext &context)
 Handle a player leaving the game.
void eventKicked (const Event_Kicked &event, int eventPlayerId, const GameEventContext &context)
 Handle the local player being kicked from the game.
QString getLeaveReason (Event_Leave::LeaveReason reason)
 Convert a leave reason enum to a human-readable string.

Private Attributes

AbstractGamegame

Detailed Description

Central dispatcher for game-wide commands and events.

This class owns no game state itself. Instead, it:

  • Sends commands to the server on behalf of local players
  • Receives and dispatches server-side game events
  • Updates the game model indirectly via Player, GameState, and PlayerManager
  • Emits high-level signals for UI updates and logging

Constructor & Destructor Documentation

◆ GameEventHandler()

GameEventHandler::GameEventHandler ( AbstractGame * _game)
explicit

Construct a GameEventHandler.

The handler is owned by the AbstractGame instance and uses it to access the game state, players, and network clients.

Parameters
_gameOwning game instance (also used as QObject parent).

Member Function Documentation

◆ addPlayerToAutoCompleteList

void GameEventHandler::addPlayerToAutoCompleteList ( QString playerName)
signal
Here is the caller graph for this function:

◆ arrowDeleted

void GameEventHandler::arrowDeleted ( int creatorId,
int arrowId )
signal
Here is the caller graph for this function:

◆ commandFinished

void GameEventHandler::commandFinished ( const Response & response)
slot

Called when a PendingCommand finishes execution.

Used to detect server-side errors such as chat flood protection.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ containerProcessingDone

void GameEventHandler::containerProcessingDone ( )
signal
Here is the caller graph for this function:

◆ containerProcessingStarted

void GameEventHandler::containerProcessingStarted ( GameEventContext context)
signal
Here is the caller graph for this function:

◆ emitUserEvent

void GameEventHandler::emitUserEvent ( )
signal
Here is the caller graph for this function:

◆ eventGameClosed()

void GameEventHandler::eventGameClosed ( const Event_GameClosed & event,
int eventPlayerId,
const GameEventContext & context )

Handle the game being closed by the server.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eventGameHostChanged()

void GameEventHandler::eventGameHostChanged ( const Event_GameHostChanged & event,
int eventPlayerId,
const GameEventContext & context )

Handle a change in game host.

Here is the caller graph for this function:

◆ eventGameStateChanged()

void GameEventHandler::eventGameStateChanged ( const Event_GameStateChanged & event,
int eventPlayerId,
const GameEventContext & context )

Handle a full game state update from the server.

Used during game startup, reconnection, and resynchronization.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eventJoin()

void GameEventHandler::eventJoin ( const Event_Join & event,
int eventPlayerId,
const GameEventContext & context )

Handle a player or spectator joining the game.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eventKicked()

void GameEventHandler::eventKicked ( const Event_Kicked & event,
int eventPlayerId,
const GameEventContext & context )

Handle the local player being kicked from the game.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eventLeave()

void GameEventHandler::eventLeave ( const Event_Leave & event,
int eventPlayerId,
const GameEventContext & context )

Handle a player leaving the game.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eventPing()

void GameEventHandler::eventPing ( const Event_Ping & event,
int eventPlayerId,
const GameEventContext & context )

Handle ping / latency updates.

◆ eventPlayerPropertiesChanged()

void GameEventHandler::eventPlayerPropertiesChanged ( const Event_PlayerPropertiesChanged & event,
int eventPlayerId,
const GameEventContext & context )

Handle updates to a player's properties.

Includes readiness, concede state, deck selection, sideboard lock, and connection state changes.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eventReverseTurn()

void GameEventHandler::eventReverseTurn ( const Event_ReverseTurn & event,
int eventPlayerId,
const GameEventContext & context )

Handle a turn reversal event.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eventSetActivePhase()

void GameEventHandler::eventSetActivePhase ( const Event_SetActivePhase & event,
int eventPlayerId,
const GameEventContext & context )

Handle a change of the active phase.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eventSetActivePlayer()

void GameEventHandler::eventSetActivePlayer ( const Event_SetActivePlayer & event,
int eventPlayerId,
const GameEventContext & context )

Handle a change of the active player.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eventSpectatorLeave()

void GameEventHandler::eventSpectatorLeave ( const Event_Leave & event,
int eventPlayerId,
const GameEventContext & context )

Handle a spectator leaving the game.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eventSpectatorSay()

void GameEventHandler::eventSpectatorSay ( const Event_GameSay & event,
int eventPlayerId,
const GameEventContext & context )

Handle a spectator chat message.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gameClosed

void GameEventHandler::gameClosed ( )
signal
Here is the caller graph for this function:

◆ gameFlooded

void GameEventHandler::gameFlooded ( )
signal
Here is the caller graph for this function:

◆ gameStopped

void GameEventHandler::gameStopped ( )
signal
Here is the caller graph for this function:

◆ getLeaveReason()

QString GameEventHandler::getLeaveReason ( Event_Leave::LeaveReason reason)

Convert a leave reason enum to a human-readable string.

Here is the caller graph for this function:

◆ handleActiveLocalPlayerConceded()

void GameEventHandler::handleActiveLocalPlayerConceded ( )

Concede the game for the currently active local player.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleActiveLocalPlayerUnconceded()

void GameEventHandler::handleActiveLocalPlayerUnconceded ( )

Undo a previous concede for the active local player.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleActivePhaseChanged()

void GameEventHandler::handleActivePhaseChanged ( int phase)

Set the active phase of the game.

Typically triggered by the active player selecting a new phase.

Parameters
phasePhase identifier.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleArrowDeletion()

void GameEventHandler::handleArrowDeletion ( int creatorId,
int arrowId )

Delete an existing arrow.

Parameters
arrowIdUnique identifier of the arrow to delete.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleArrowDeletionFinished()

void GameEventHandler::handleArrowDeletionFinished ( const Response & response,
int creatorId,
int arrowId )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleChatMessageSent()

void GameEventHandler::handleChatMessageSent ( const QString & chatMessage)

Send a chat message to all players and spectators.

Parameters
chatMessageMessage text.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleGameLeft()

void GameEventHandler::handleGameLeft ( )

Leave the current game session.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleNextTurn()

void GameEventHandler::handleNextTurn ( )

Request advancing the game to the next turn.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleReverseTurn()

void GameEventHandler::handleReverseTurn ( )

Request reversing the current turn order.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ localPlayerDeckSelected

void GameEventHandler::localPlayerDeckSelected ( PlayerLogic * localPlayer,
int playerId,
ServerInfo_Player playerInfo )
signal
Here is the caller graph for this function:

◆ localPlayerReadyStateChanged

void GameEventHandler::localPlayerReadyStateChanged ( int playerId,
bool ready )
signal
Here is the caller graph for this function:

◆ localPlayerSideboardLocked

void GameEventHandler::localPlayerSideboardLocked ( int playerId,
bool sideboardLocked )
signal
Here is the caller graph for this function:

◆ logActivePhaseChanged

void GameEventHandler::logActivePhaseChanged ( int activePhase)
signal
Here is the caller graph for this function:

◆ logActivePlayer

void GameEventHandler::logActivePlayer ( PlayerLogic * activePlayer)
signal
Here is the caller graph for this function:

◆ logConcede

void GameEventHandler::logConcede ( int playerId)
signal
Here is the caller graph for this function:

◆ logConnectionStateChanged

void GameEventHandler::logConnectionStateChanged ( PlayerLogic * player,
bool connected )
signal
Here is the caller graph for this function:

◆ logDeckSelect

void GameEventHandler::logDeckSelect ( PlayerLogic * player,
QString deckHash,
int sideboardSize )
signal
Here is the caller graph for this function:

◆ logGameClosed

void GameEventHandler::logGameClosed ( )
signal
Here is the caller graph for this function:

◆ logGameStart

void GameEventHandler::logGameStart ( )
signal
Here is the caller graph for this function:

◆ logJoinPlayer

void GameEventHandler::logJoinPlayer ( PlayerLogic * player)
signal
Here is the caller graph for this function:

◆ logJoinSpectator

void GameEventHandler::logJoinSpectator ( QString spectatorName)
signal
Here is the caller graph for this function:

◆ logKicked

void GameEventHandler::logKicked ( )
signal
Here is the caller graph for this function:

◆ logLeave

void GameEventHandler::logLeave ( PlayerLogic * player,
QString reason )
signal
Here is the caller graph for this function:

◆ logNotReadyStart

void GameEventHandler::logNotReadyStart ( PlayerLogic * player)
signal
Here is the caller graph for this function:

◆ logReadyStart

void GameEventHandler::logReadyStart ( PlayerLogic * player)
signal
Here is the caller graph for this function:

◆ logSideboardLockSet

void GameEventHandler::logSideboardLockSet ( PlayerLogic * player,
bool sideboardLocked )
signal
Here is the caller graph for this function:

◆ logSpectatorLeave

void GameEventHandler::logSpectatorLeave ( QString name,
QString reason )
signal
Here is the caller graph for this function:

◆ logSpectatorSay

void GameEventHandler::logSpectatorSay ( ServerInfo_User userInfo,
QString message )
signal
Here is the caller graph for this function:

◆ logTurnReversed

void GameEventHandler::logTurnReversed ( PlayerLogic * player,
bool reversed )
signal
Here is the caller graph for this function:

◆ logUnconcede

void GameEventHandler::logUnconcede ( int playerId)
signal
Here is the caller graph for this function:

◆ playerJoined

void GameEventHandler::playerJoined ( const ServerInfo_PlayerProperties & playerInfo)
signal
Here is the caller graph for this function:

◆ playerKicked

void GameEventHandler::playerKicked ( )
signal
Here is the caller graph for this function:

◆ playerLeft

void GameEventHandler::playerLeft ( int leavingPlayerId)
signal
Here is the caller graph for this function:

◆ playerPropertiesChanged

void GameEventHandler::playerPropertiesChanged ( const ServerInfo_PlayerProperties & prop,
int playerId )
signal
Here is the caller graph for this function:

◆ prepareGameCommand() [1/2]

PendingCommand * GameEventHandler::prepareGameCommand ( const ::google::protobuf::Message & cmd)

Wrap a single protobuf command in a PendingCommand.

Parameters
cmdProtobuf command message.
Returns
Newly allocated PendingCommand (caller takes ownership).
Here is the caller graph for this function:

◆ prepareGameCommand() [2/2]

PendingCommand * GameEventHandler::prepareGameCommand ( const QList< const ::google::protobuf::Message * > & cmdList)

Wrap multiple protobuf commands in a single PendingCommand.

Ownership of the messages in cmdList is transferred to the handler.

Parameters
cmdListList of protobuf command messages.
Returns
Newly allocated PendingCommand.

◆ processCardAttachmentsForPlayers()

void GameEventHandler::processCardAttachmentsForPlayers ( const Event_GameStateChanged & event)

Update card attachment relationships for all players.

Called after a game state update to ensure attachments are resolved consistently across all zones.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ processGameEventContainer()

void GameEventHandler::processGameEventContainer ( const GameEventContainer & cont,
AbstractClient * client,
EventProcessingOptions options )

Process a container of game events received from the server.

This is the main dispatch function for incoming game events. Events are routed to spectator handlers, game-level handlers, or forwarded to PlayerEventHandler instances as appropriate.

Parameters
contGame event container from the server.
clientClient that received the container.
optionsProcessing flags (e.g. silent, replay).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ remotePlayerDeckSelected

void GameEventHandler::remotePlayerDeckSelected ( QString deckList,
int playerId,
QString playerName )
signal
Here is the caller graph for this function:

◆ remotePlayersDecksSelected

void GameEventHandler::remotePlayersDecksSelected ( QVector< QPair< int, QPair< QString, QString > > > opponentDecks)
signal
Here is the caller graph for this function:

◆ sendGameCommand [1/2]

void GameEventHandler::sendGameCommand ( const ::google::protobuf::Message & command,
int playerId = -1 )
slot

Send a single protobuf command.

Parameters
commandProtobuf command message.
playerIdPlayer whose client should send the command.

◆ sendGameCommand [2/2]

void GameEventHandler::sendGameCommand ( PendingCommand * pend,
int playerId = -1 )
slot

Send a prepared PendingCommand.

Parameters
pendPending command to send.
playerIdPlayer whose client should send the command.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setContextJudgeName

void GameEventHandler::setContextJudgeName ( QString judgeName)
signal
Here is the caller graph for this function:

◆ spectatorJoined

void GameEventHandler::spectatorJoined ( const ServerInfo_PlayerProperties & spectatorInfo)
signal
Here is the caller graph for this function:

◆ spectatorLeft

void GameEventHandler::spectatorLeft ( int leavingSpectatorId)
signal
Here is the caller graph for this function:

Member Data Documentation

◆ game

AbstractGame* GameEventHandler::game
private

Pointer to the owning game instance.


The documentation for this class was generated from the following files: