Cockatrice 2026-10-19-Development-3.1.2-beta.2
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 <QPair>
23#include <QString>
24#include <QVector>
25#include <libcockatrice/protocol/pb/event_leave.pb.h>
26#include <qtmetamacros.h>
27
28// IWYU pragma: keep
29// GameEventContext, ServerInfo_Player and ServerInfo_User are passed by value
30// to signals and slots, so the moc-generated code needs the complete types.
31#include <libcockatrice/protocol/pb/game_event_context.pb.h>
32#include <libcockatrice/protocol/pb/serverinfo_player.pb.h>
33#include <libcockatrice/protocol/pb/serverinfo_user.pb.h>
34
35class AbstractClient;
36class AbstractGame;
39class PendingCommand;
40class PlayerLogic;
41class Response;
44class Event_Join;
49class Event_GameSay;
50class Event_Kicked;
52class Event_Ping;
54namespace google
55{
56namespace protobuf
57{
58class Message;
59} // namespace protobuf
60} // namespace google
61template <typename T> class QList;
62
63inline Q_LOGGING_CATEGORY(GameEventHandlerLog, "game_event_handler");
64
75class GameEventHandler : public QObject
76{
77 Q_OBJECT
78
79private:
82
83public:
88
97 explicit GameEventHandler(AbstractGame *_game);
98
100
108
110 void handleNextTurn();
111
113 void handleReverseTurn();
114
117
120
128 void handleActivePhaseChanged(int phase);
129
131 void handleGameLeft();
132
138 void handleChatMessageSent(const QString &chatMessage);
139
145 void handleArrowDeletion(int creatorId, int arrowId);
146 void handleArrowDeletionFinished(const Response &response, int creatorId, int arrowId);
147
149
154
166 void
167 processGameEventContainer(const GameEventContainer &cont, AbstractClient *client, EventProcessingOptions options);
168
170
175
182 PendingCommand *prepareGameCommand(const ::google::protobuf::Message &cmd);
183
193
195
200
204 void eventSpectatorSay(const Event_GameSay &event, int eventPlayerId, const GameEventContext &context);
205
209 void eventSpectatorLeave(const Event_Leave &event, int eventPlayerId, const GameEventContext &context);
210
212
217
223 void eventGameStateChanged(const Event_GameStateChanged &event, int eventPlayerId, const GameEventContext &context);
224
232
234 void eventGameHostChanged(const Event_GameHostChanged &event, int eventPlayerId, const GameEventContext &context);
235
237 void eventGameClosed(const Event_GameClosed &event, int eventPlayerId, const GameEventContext &context);
238
240 void eventSetActivePlayer(const Event_SetActivePlayer &event, int eventPlayerId, const GameEventContext &context);
241
243 void eventSetActivePhase(const Event_SetActivePhase &event, int eventPlayerId, const GameEventContext &context);
244
246 void eventReverseTurn(const Event_ReverseTurn &event, int eventPlayerId, const GameEventContext &context);
247
249 void eventPing(const Event_Ping &event, int eventPlayerId, const GameEventContext &context);
250
252
257
265 int eventPlayerId,
266 const GameEventContext &context);
267
269 void eventJoin(const Event_Join &event, int eventPlayerId, const GameEventContext &context);
270
272 void eventLeave(const Event_Leave &event, int eventPlayerId, const GameEventContext &context);
273
275 void eventKicked(const Event_Kicked &event, int eventPlayerId, const GameEventContext &context);
276
281
283
284public slots:
289
296 void sendGameCommand(PendingCommand *pend, int playerId = -1);
297
304 void sendGameCommand(const ::google::protobuf::Message &command, int playerId = -1);
305
311 void commandFinished(const Response &response);
312
314
315signals:
319
324 void setContextJudgeName(QString judgeName);
325
327
331
332 void addPlayerToAutoCompleteList(QString playerName);
333 void localPlayerDeckSelected(PlayerLogic *localPlayer, int playerId, ServerInfo_Player playerInfo);
334 void remotePlayerDeckSelected(QString deckList, int playerId, QString playerName);
335 void remotePlayersDecksSelected(QVector<QPair<int, QPair<QString, QString>>> opponentDecks);
336 void localPlayerSideboardLocked(int playerId, bool sideboardLocked);
337 void localPlayerReadyStateChanged(int playerId, bool ready);
338
340
344
349 void playerLeft(int leavingPlayerId);
352 void spectatorLeft(int leavingSpectatorId);
353 void arrowDeleted(int creatorId, int arrowId);
354
356
361
362 void logSpectatorSay(ServerInfo_User userInfo, QString message);
363 void logSpectatorLeave(QString name, QString reason);
367 void logDeckSelect(PlayerLogic *player, QString deckHash, int sideboardSize);
368 void logSideboardLockSet(PlayerLogic *player, bool sideboardLocked);
369 void logConnectionStateChanged(PlayerLogic *player, bool connected);
370 void logJoinSpectator(QString spectatorName);
372 void logLeave(PlayerLogic *player, QString reason);
373 void logKicked();
374 void logTurnReversed(PlayerLogic *player, bool reversed);
376 void logActivePlayer(PlayerLogic *activePlayer);
377 void logActivePhaseChanged(int activePhase);
378 void logConcede(int playerId);
379 void logUnconcede(int playerId);
380
382};
383
384#endif // COCKATRICE_GAME_EVENT_HANDLER_H
Definition abstract_client.h:73
Definition abstract_game.h:23
void handleNextTurn()
Request advancing the game to the next turn.
Definition game_event_handler.cpp:199
void processGameEventContainer(const GameEventContainer &cont, AbstractClient *client, EventProcessingOptions options)
Process a container of game events received from the server.
Definition game_event_handler.cpp:109
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:81
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:524
PendingCommand * prepareGameCommand(const ::google::protobuf::Message &cmd)
Wrap a single protobuf command in a PendingCommand.
Definition game_event_handler.cpp:88
void logLeave(PlayerLogic *player, QString reason)
GameEventHandler(AbstractGame *_game)
Construct a GameEventHandler.
Definition game_event_handler.cpp:54
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:543
void addPlayerToAutoCompleteList(QString playerName)
void handleActiveLocalPlayerConceded()
Concede the game for the currently active local player.
Definition game_event_handler.cpp:209
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:271
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:282
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:238
void eventLeave(const Event_Leave &event, int eventPlayerId, const GameEventContext &context)
Handle a player leaving the game.
Definition game_event_handler.cpp:489
void handleReverseTurn()
Request reversing the current turn order.
Definition game_event_handler.cpp:204
void eventSetActivePlayer(const Event_SetActivePlayer &event, int eventPlayerId, const GameEventContext &context)
Handle a change of the active player.
Definition game_event_handler.cpp:554
void handleActiveLocalPlayerUnconceded()
Undo a previous concede for the active local player.
Definition game_event_handler.cpp:214
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:514
void eventJoin(const Event_Join &event, int eventPlayerId, const GameEventContext &context)
Handle a player or spectator joining the game.
Definition game_event_handler.cpp:446
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:58
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:471
void eventGameHostChanged(const Event_GameHostChanged &event, int eventPlayerId, const GameEventContext &context)
Handle a change in game host.
Definition game_event_handler.cpp:536
void handleChatMessageSent(const QString &chatMessage)
Send a chat message to all players and spectators.
Definition game_event_handler.cpp:231
void eventSetActivePhase(const Event_SetActivePhase &event, int eventPlayerId, const GameEventContext &context)
Handle a change of the active phase.
Definition game_event_handler.cpp:567
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:352
void handleArrowDeletionFinished(const Response &response, int creatorId, int arrowId)
Definition game_event_handler.cpp:252
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:367
void logJoinSpectator(QString spectatorName)
void handleGameLeft()
Leave the current game session.
Definition game_event_handler.cpp:226
void playerJoined(const ServerInfo_PlayerProperties &playerInfo)
AbstractGame * game
Definition game_event_handler.h:81
void eventSpectatorSay(const Event_GameSay &event, int eventPlayerId, const GameEventContext &context)
Handle a spectator chat message.
Definition game_event_handler.cpp:263
void handleActivePhaseChanged(int phase)
Set the active phase of the game.
Definition game_event_handler.cpp:219
void logActivePlayer(PlayerLogic *activePlayer)
Definition pending_command.h:20
Definition player_logic.h:56
Definition remote_connection_controller.h:20
Q_LOGGING_CATEGORY(CrashReportLog, "crash_report")
Definition game_event_handler.h:57
Definition game_event_handler.h:55
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_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