Cockatrice 2026-09-01-Development-3.1.0-beta.10
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
game_event_handler.h
Go to the documentation of this file.
1
14
15#ifndef COCKATRICE_GAME_EVENT_HANDLER_H
16#define COCKATRICE_GAME_EVENT_HANDLER_H
17
19
20#include <QLoggingCategory>
21#include <QObject>
22#include <libcockatrice/protocol/pb/event_leave.pb.h>
23#include <libcockatrice/protocol/pb/serverinfo_player.pb.h>
24
25class AbstractClient;
26class AbstractGame;
28class GameCommand;
31class PendingCommand;
32class PlayerLogic;
33class Response;
34
37class Event_Join;
38class Event_Leave;
43class Event_GameSay;
44class Event_Kicked;
46class Event_Ping;
47
48inline Q_LOGGING_CATEGORY(GameEventHandlerLog, "game_event_handler");
49
60class GameEventHandler : public QObject
61{
62 Q_OBJECT
63
64private:
67
68public:
73
82 explicit GameEventHandler(AbstractGame *_game);
83
85
93
95 void handleNextTurn();
96
98 void handleReverseTurn();
99
102
105
113 void handleActivePhaseChanged(int phase);
114
116 void handleGameLeft();
117
123 void handleChatMessageSent(const QString &chatMessage);
124
130 void handleArrowDeletion(int creatorId, int arrowId);
131 void handleArrowDeletionFinished(const Response &response, int creatorId, int arrowId);
132
134
139
151 void
152 processGameEventContainer(const GameEventContainer &cont, AbstractClient *client, EventProcessingOptions options);
153
155
160
167 PendingCommand *prepareGameCommand(const ::google::protobuf::Message &cmd);
168
177 PendingCommand *prepareGameCommand(const QList<const ::google::protobuf::Message *> &cmdList);
178
180
185
189 void eventSpectatorSay(const Event_GameSay &event, int eventPlayerId, const GameEventContext &context);
190
194 void eventSpectatorLeave(const Event_Leave &event, int eventPlayerId, const GameEventContext &context);
195
197
202
208 void eventGameStateChanged(const Event_GameStateChanged &event, int eventPlayerId, const GameEventContext &context);
209
217
219 void eventGameHostChanged(const Event_GameHostChanged &event, int eventPlayerId, const GameEventContext &context);
220
222 void eventGameClosed(const Event_GameClosed &event, int eventPlayerId, const GameEventContext &context);
223
225 void eventSetActivePlayer(const Event_SetActivePlayer &event, int eventPlayerId, const GameEventContext &context);
226
228 void eventSetActivePhase(const Event_SetActivePhase &event, int eventPlayerId, const GameEventContext &context);
229
231 void eventReverseTurn(const Event_ReverseTurn &event, int eventPlayerId, const GameEventContext &context);
232
234 void eventPing(const Event_Ping &event, int eventPlayerId, const GameEventContext &context);
235
237
242
250 int eventPlayerId,
251 const GameEventContext &context);
252
254 void eventJoin(const Event_Join &event, int eventPlayerId, const GameEventContext &context);
255
257 void eventLeave(const Event_Leave &event, int eventPlayerId, const GameEventContext &context);
258
260 void eventKicked(const Event_Kicked &event, int eventPlayerId, const GameEventContext &context);
261
266
268
269public slots:
274
281 void sendGameCommand(PendingCommand *pend, int playerId = -1);
282
289 void sendGameCommand(const ::google::protobuf::Message &command, int playerId = -1);
290
296 void commandFinished(const Response &response);
297
299
300signals:
304
309 void setContextJudgeName(QString judgeName);
310
312
316
317 void addPlayerToAutoCompleteList(QString playerName);
318 void localPlayerDeckSelected(PlayerLogic *localPlayer, int playerId, ServerInfo_Player playerInfo);
319 void remotePlayerDeckSelected(QString deckList, int playerId, QString playerName);
320 void remotePlayersDecksSelected(QVector<QPair<int, QPair<QString, QString>>> opponentDecks);
321 void localPlayerSideboardLocked(int playerId, bool sideboardLocked);
322 void localPlayerReadyStateChanged(int playerId, bool ready);
323
325
329
334 void playerLeft(int leavingPlayerId);
337 void spectatorLeft(int leavingSpectatorId);
338 void arrowDeleted(int creatorId, int arrowId);
339
341
346
347 void logSpectatorSay(ServerInfo_User userInfo, QString message);
348 void logSpectatorLeave(QString name, QString reason);
352 void logDeckSelect(PlayerLogic *player, QString deckHash, int sideboardSize);
353 void logSideboardLockSet(PlayerLogic *player, bool sideboardLocked);
354 void logConnectionStateChanged(PlayerLogic *player, bool connected);
355 void logJoinSpectator(QString spectatorName);
357 void logLeave(PlayerLogic *player, QString reason);
358 void logKicked();
359 void logTurnReversed(PlayerLogic *player, bool reversed);
361 void logActivePlayer(PlayerLogic *activePlayer);
362 void logActivePhaseChanged(int activePhase);
363 void logConcede(int playerId);
364 void logUnconcede(int playerId);
365
367};
368
369#endif // COCKATRICE_GAME_EVENT_HANDLER_H
Definition abstract_client.h:57
Definition abstract_game.h:20
void handleNextTurn()
Request advancing the game to the next turn.
Definition game_event_handler.cpp:177
void processGameEventContainer(const GameEventContainer &cont, AbstractClient *client, EventProcessingOptions options)
Process a container of game events received from the server.
Definition game_event_handler.cpp:87
void sendGameCommand(const ::google::protobuf::Message &command, int playerId=-1)
Send a single protobuf command.
void remotePlayersDecksSelected(QVector< QPair< int, QPair< QString, QString > > > opponentDecks)
void localPlayerReadyStateChanged(int playerId, bool ready)
void logSpectatorLeave(QString name, QString reason)
void commandFinished(const Response &response)
Called when a PendingCommand finishes execution.
Definition game_event_handler.cpp:59
void containerProcessingDone()
void logUnconcede(int playerId)
void logTurnReversed(PlayerLogic *player, bool reversed)
void eventReverseTurn(const Event_ReverseTurn &event, int eventPlayerId, const GameEventContext &context)
Handle a turn reversal event.
Definition game_event_handler.cpp:503
PendingCommand * prepareGameCommand(const ::google::protobuf::Message &cmd)
Wrap a single protobuf command in a PendingCommand.
Definition game_event_handler.cpp:66
void logLeave(PlayerLogic *player, QString reason)
GameEventHandler(AbstractGame *_game)
Construct a GameEventHandler.
Definition game_event_handler.cpp:32
void logNotReadyStart(PlayerLogic *player)
void eventGameClosed(const Event_GameClosed &event, int eventPlayerId, const GameEventContext &context)
Handle the game being closed by the server.
Definition game_event_handler.cpp:522
void addPlayerToAutoCompleteList(QString playerName)
void handleActiveLocalPlayerConceded()
Concede the game for the currently active local player.
Definition game_event_handler.cpp:187
void eventPing(const Event_Ping &event, int eventPlayerId, const GameEventContext &context)
Handle ping / latency updates.
void eventSpectatorLeave(const Event_Leave &event, int eventPlayerId, const GameEventContext &context)
Handle a spectator leaving the game.
Definition game_event_handler.cpp:249
void setContextJudgeName(QString judgeName)
void logReadyStart(PlayerLogic *player)
void remotePlayerDeckSelected(QString deckList, int playerId, QString playerName)
void playerPropertiesChanged(const ServerInfo_PlayerProperties &prop, int playerId)
void logConcede(int playerId)
void arrowDeleted(int creatorId, int arrowId)
void playerLeft(int leavingPlayerId)
void logSpectatorSay(ServerInfo_User userInfo, QString message)
void logActivePhaseChanged(int activePhase)
void logConnectionStateChanged(PlayerLogic *player, bool connected)
void eventGameStateChanged(const Event_GameStateChanged &event, int eventPlayerId, const GameEventContext &context)
Handle a full game state update from the server.
Definition game_event_handler.cpp:262
void containerProcessingStarted(GameEventContext context)
void logDeckSelect(PlayerLogic *player, QString deckHash, int sideboardSize)
void handleArrowDeletion(int creatorId, int arrowId)
Delete an existing arrow.
Definition game_event_handler.cpp:216
void eventLeave(const Event_Leave &event, int eventPlayerId, const GameEventContext &context)
Handle a player leaving the game.
Definition game_event_handler.cpp:468
void handleReverseTurn()
Request reversing the current turn order.
Definition game_event_handler.cpp:182
void eventSetActivePlayer(const Event_SetActivePlayer &event, int eventPlayerId, const GameEventContext &context)
Handle a change of the active player.
Definition game_event_handler.cpp:533
void handleActiveLocalPlayerUnconceded()
Undo a previous concede for the active local player.
Definition game_event_handler.cpp:192
void eventKicked(const Event_Kicked &event, int eventPlayerId, const GameEventContext &context)
Handle the local player being kicked from the game.
Definition game_event_handler.cpp:493
void eventJoin(const Event_Join &event, int eventPlayerId, const GameEventContext &context)
Handle a player or spectator joining the game.
Definition game_event_handler.cpp:426
void localPlayerDeckSelected(PlayerLogic *localPlayer, int playerId, ServerInfo_Player playerInfo)
void spectatorJoined(const ServerInfo_PlayerProperties &spectatorInfo)
void sendGameCommand(PendingCommand *pend, int playerId=-1)
Send a prepared PendingCommand.
Definition game_event_handler.cpp:36
void logSideboardLockSet(PlayerLogic *player, bool sideboardLocked)
QString getLeaveReason(Event_Leave::LeaveReason reason)
Convert a leave reason enum to a human-readable string.
Definition game_event_handler.cpp:450
void eventGameHostChanged(const Event_GameHostChanged &event, int eventPlayerId, const GameEventContext &context)
Handle a change in game host.
Definition game_event_handler.cpp:515
void handleChatMessageSent(const QString &chatMessage)
Send a chat message to all players and spectators.
Definition game_event_handler.cpp:209
void eventSetActivePhase(const Event_SetActivePhase &event, int eventPlayerId, const GameEventContext &context)
Handle a change of the active phase.
Definition game_event_handler.cpp:546
void localPlayerSideboardLocked(int playerId, bool sideboardLocked)
void spectatorLeft(int leavingSpectatorId)
void processCardAttachmentsForPlayers(const Event_GameStateChanged &event)
Update card attachment relationships for all players.
Definition game_event_handler.cpp:332
void handleArrowDeletionFinished(const Response &response, int creatorId, int arrowId)
Definition game_event_handler.cpp:230
void logJoinPlayer(PlayerLogic *player)
void eventPlayerPropertiesChanged(const Event_PlayerPropertiesChanged &event, int eventPlayerId, const GameEventContext &context)
Handle updates to a player's properties.
Definition game_event_handler.cpp:347
void logJoinSpectator(QString spectatorName)
void handleGameLeft()
Leave the current game session.
Definition game_event_handler.cpp:204
void playerJoined(const ServerInfo_PlayerProperties &playerInfo)
AbstractGame * game
Definition game_event_handler.h:66
void eventSpectatorSay(const Event_GameSay &event, int eventPlayerId, const GameEventContext &context)
Handle a spectator chat message.
Definition game_event_handler.cpp:241
void handleActivePhaseChanged(int phase)
Set the active phase of the game.
Definition game_event_handler.cpp:197
void logActivePlayer(PlayerLogic *activePlayer)
Definition pending_command.h:16
Definition player_logic.h:65
Q_LOGGING_CATEGORY(GameEventHandlerLog, "game_event_handler")
Definition commands.proto:7
Definition event_game_closed.proto:3
Definition event_game_host_changed.proto:3
Definition event_game_say.proto:3
Definition event_game_state_changed.proto:8
Definition event_join.proto:4
Definition event_kicked.proto:3
Definition event_leave.proto:3
LeaveReason
Definition event_leave.proto:7
Definition event_player_properties_changed.proto:4
Definition event_reverse_turn.proto:3
Definition event_set_active_phase.proto:3
Definition event_set_active_player.proto:3
Definition game_commands.proto:4
Definition game_event_container.proto:4
Definition game_event_context.proto:2
Definition response.proto:11
Definition serverinfo_playerproperties.proto:3
Definition serverinfo_player.proto:6
Definition serverinfo_user.proto:2