Cockatrice 2026-10-19-Development-3.1.2-beta.2
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
server_game.h
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2008 by Max-Wilhelm Bruker *
3 * brukie@laptop *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20#ifndef SERVERGAME_H
21#define SERVERGAME_H
22
24#include "libcockatrice/protocol/pb/game_event_context.pb.h"
25
26// IWYU pragma: keep
27// ServerInfo_Game is passed by value to the gameInfoChanged() signal, so the
28// moc-generated code needs the complete type.
29#include <QDateTime>
30#include <QList>
31#include <QMap>
32#include <QObject>
33#include <QRecursiveMutex>
34#include <QScopedPointer>
35#include <QSet>
36#include <QString>
37#include <QtGlobal>
38#include <atomic>
39#include <libcockatrice/protocol/pb/event_leave.pb.h>
40#include <libcockatrice/protocol/pb/response.pb.h>
41#include <libcockatrice/protocol/pb/serverinfo_game.pb.h>
42#include <qtmetamacros.h>
43
44class QTimer;
46class GameReplay;
47class Server_Room;
50class ServerInfo_User;
51class ServerInfo_Game;
57namespace google
58{
59namespace protobuf
60{
61class Message;
62} // namespace protobuf
63} // namespace google
64struct GameConfig;
65
66class Server_Game : public QObject
67{
68 Q_OBJECT
69private:
72 std::atomic<qint64> nextArrowId = 1;
73 int hostId;
79 int gameId;
80 QString description;
81 QString password;
96 QDateTime startTime;
97 QTimer *pingClock;
100
101 QScopedPointer<Server_DeckValidationStrategy> deckValidationStrategy;
102
103 QScopedPointer<Server_GameLifecycleStrategy> lifecycleStrategy;
104
105 QScopedPointer<Server_MatchResultStrategy> matchResultStrategy;
106
109 bool omniscient,
110 bool withUserInfo);
112signals:
113 void sigStartGameIfReady(bool override);
115private slots:
116 void pingClockTimeout();
117 void doStartGameIfReady(bool forceStartGame = false);
118
119public:
120 mutable QRecursiveMutex gameMutex;
121 Server_Game(const GameConfig &config, Server_Room *parent);
122 ~Server_Game() override;
124 {
125 return room;
126 }
127 void getInfo(ServerInfo_Game &result) const;
128 int getHostId() const
129 {
130 return hostId;
131 }
133 {
134 return creatorInfo;
135 }
136 bool getGameStarted() const
137 {
138 return gameStarted;
139 }
140 int getPlayerCount() const;
142 int getCardsInGame() const;
143 int getSpectatorCount() const;
145 Server_AbstractPlayer *getPlayer(int id) const;
150 int getGameId() const
151 {
152 return gameId;
153 }
154 QString getDescription() const
155 {
156 return description;
157 }
158 QString getPassword() const
159 {
160 return password;
161 }
162 int getMaxPlayers() const
163 {
164 return maxPlayers;
165 }
167 {
168 return spectatorsAllowed;
169 }
171 {
173 }
175 {
176 return spectatorsCanTalk;
177 }
179 {
181 }
183 {
184 return startingLifeTotal;
185 }
187 {
189 }
191 checkJoin(ServerInfo_User *user, const QString &_password, bool spectator, bool overrideRestrictions, bool asJudge);
192 bool containsUser(const QString &userName) const;
193 void addPlayer(Server_AbstractUserInterface *userInterface,
195 bool spectator,
196 bool judge,
197 bool broadcastUpdate = true);
201 bool kickParticipant(int playerId);
202 void startGameIfReady(bool forceStartGame);
203 void stopGameIfFinished();
204 int getActivePlayer() const
205 {
206 return activePlayer;
207 }
208 int getActivePhase() const
209 {
210 return activePhase;
211 }
212 void setActivePlayer(int newPlayer);
213 void setActivePhase(int newPhase);
214 qint64 generateArrowId();
215 void removeArrows(int newPhase, bool force = false);
216 void nextTurn();
218 {
219 return secondsElapsed;
220 }
222 {
224 }
225
226 void createGameJoinedEvent(Server_AbstractParticipant *participant, ResponseContainer &rc, bool resuming);
227
229 prepareGameEvent(const ::google::protobuf::Message &gameEvent, int playerId, GameEventContext *context = 0);
230 GameEventContext prepareGameEventContext(const ::google::protobuf::Message &gameEventContext);
231
234 GameEventStorageItem::EventRecipients recipients = GameEventStorageItem::SendToPrivate |
236 int privatePlayerId = -1);
238
244
246
252};
253
254#endif
@ SendToPrivate
Definition server_response_containers.h:26
@ SendToOthers
Definition server_response_containers.h:27
Definition server_response_containers.h:50
Definition remote_connection_controller.h:20
Definition game.h:18
Definition dlg_manage_sets.h:29
Definition server_response_containers.h:93
Definition server_abstract_participant.h:57
Definition server_abstract_player.h:25
Definition server_abstractuserinterface.h:28
Strategy for validating a player's deck before it is loaded into a game.
Definition server_deck_validation_strategy.h:18
Strategy hook invoked around a game's lifecycle transitions.
Definition server_game_lifecycle_strategy.h:13
int getActivePlayer() const
Definition server_game.h:204
QList< int > gameTypes
Definition server_game.h:83
void sendGameStateToPlayers()
Definition server_game.cpp:313
void stopGameIfFinished()
Definition server_game.cpp:435
int startTimeOfThisGame
Definition server_game.h:93
bool gameClosed
Definition server_game.h:78
void removeArrows(int newPhase, bool force=false)
Definition server_game.cpp:748
void gameInfoChanged(ServerInfo_Game gameInfo)
bool getSpectatorsNeedPassword() const
Definition server_game.h:170
QTimer * pingClock
Definition server_game.h:97
void storeGameInformation()
Definition server_game.cpp:153
ServerInfo_User * creatorInfo
Definition server_game.h:74
bool firstGameStarted
Definition server_game.h:94
int maxPlayers
Definition server_game.h:82
bool gameStarted
Definition server_game.h:77
bool onlyRegistered
Definition server_game.h:85
void startGameIfReady(bool forceStartGame)
Definition server_game.cpp:430
std::atomic< qint64 > nextArrowId
Definition server_game.h:72
void sendGameEventContainer(GameEventContainer *cont, GameEventStorageItem::EventRecipients recipients=GameEventStorageItem::SendToPrivate|GameEventStorageItem::SendToOthers, int privatePlayerId=-1)
Definition server_game.cpp:874
GameEventContainer * prepareGameEvent(const ::google::protobuf::Message &gameEvent, int playerId, GameEventContext *context=0)
Definition server_game.cpp:899
int getSpectatorCount() const
Definition server_game.cpp:281
bool containsUser(const QString &userName) const
Definition server_game.cpp:526
bool getSpectatorsSeeEverything() const
Definition server_game.h:178
void setActivePhase(int newPhase)
Definition server_game.cpp:731
QMap< int, Server_AbstractParticipant * > participants
Definition server_game.h:75
void nextTurn()
Definition server_game.cpp:765
QDateTime startTime
Definition server_game.h:96
QList< GameReplay * > replayList
Definition server_game.h:98
bool turnOrderReversed
Definition server_game.h:95
bool getShareDecklistsOnLoad() const
Definition server_game.h:186
const QMap< int, Server_AbstractParticipant * > & getParticipants() const
Definition server_game.h:146
QMap< int, Server_AbstractPlayer * > getPlayers() const
Definition server_game.cpp:242
bool spectatorsSeeEverything
Definition server_game.h:89
int startingLifeTotal
Definition server_game.h:90
Response::ResponseCode checkJoin(ServerInfo_User *user, const QString &_password, bool spectator, bool overrideRestrictions, bool asJudge)
Definition server_game.cpp:480
void getInfo(ServerInfo_Game &result) const
Definition server_game.cpp:916
Server_GameLifecycleStrategy * getLifecycleStrategy() const
Get the current game lifecycle strategy (non-owning).
Definition server_game.h:248
void removeArrowsRelatedToPlayer(GameEventStorage &ges, Server_AbstractPlayer *player)
Definition server_game.cpp:641
QScopedPointer< Server_GameLifecycleStrategy > lifecycleStrategy
Definition server_game.h:103
bool onlyBuddies
Definition server_game.h:85
Server_Room * room
Definition server_game.h:70
bool getSpectatorsCanTalk() const
Definition server_game.h:174
QString description
Definition server_game.h:80
int secondsElapsed
Definition server_game.h:93
QSet< QString > allSpectatorsEver
Definition server_game.h:76
bool shareDecklistsOnLoad
Definition server_game.h:91
bool kickParticipant(int playerId)
Definition server_game.cpp:698
bool getSpectatorsAllowed() const
Definition server_game.h:166
bool spectatorsAllowed
Definition server_game.h:86
void removeParticipant(Server_AbstractParticipant *participant, Event_Leave::LeaveReason reason)
Definition server_game.cpp:591
bool spectatorsNeedPassword
Definition server_game.h:87
QRecursiveMutex gameMutex
Definition server_game.h:120
void sigStartGameIfReady(bool override)
Server_AbstractPlayer * getPlayer(int id) const
Definition server_game.cpp:255
QString password
Definition server_game.h:81
int getSecondsElapsed() const
Definition server_game.h:217
int getCardsInGame() const
Total cards across all players' zones. Takes gameMutex itself.
Definition server_game.cpp:270
ServerInfo_User * getCreatorInfo() const
Definition server_game.h:132
int activePhase
Definition server_game.h:84
Server_Room * getRoom() const
Definition server_game.h:123
int getPlayerCount() const
Definition server_game.cpp:265
int getStartingLifeTotal() const
Definition server_game.h:182
void setActivePlayer(int newPlayer)
Definition server_game.cpp:716
void doStartGameIfReady(bool forceStartGame=false)
Definition server_game.cpp:351
int getActivePhase() const
Definition server_game.h:208
bool spectatorsCanTalk
Definition server_game.h:88
GameEventContext prepareGameEventContext(const ::google::protobuf::Message &gameEventContext)
bool getGameStarted() const
Definition server_game.h:136
Server_Game(const GameConfig &config, Server_Room *parent)
Definition server_game.cpp:85
Server_DeckValidationStrategy * getDeckValidationStrategy() const
Get the current deck validation strategy (non-owning).
Definition server_game.h:240
void returnCardsFromPlayer(GameEventStorage &ges, Server_AbstractPlayer *player)
Definition server_game.cpp:953
int nextPlayerId
Definition server_game.h:71
qint64 generateArrowId()
Definition server_game.cpp:743
void createGameJoinedEvent(Server_AbstractParticipant *participant, ResponseContainer &rc, bool resuming)
Definition server_game.cpp:797
QScopedPointer< Server_DeckValidationStrategy > deckValidationStrategy
Definition server_game.h:101
QScopedPointer< Server_MatchResultStrategy > matchResultStrategy
Definition server_game.h:105
int hostId
Definition server_game.h:73
QString getDescription() const
Definition server_game.h:154
int gameId
Definition server_game.h:79
void addPlayer(Server_AbstractUserInterface *userInterface, ResponseContainer &rc, bool spectator, bool judge, bool broadcastUpdate=true)
Definition server_game.cpp:538
QSet< QString > allPlayersEver
Definition server_game.h:76
int getGameId() const
Definition server_game.h:150
void pingClockTimeout()
Definition server_game.cpp:200
int activePlayer
Definition server_game.h:84
void createGameStateChangedEvent(Event_GameStateChanged *event, Server_AbstractParticipant *recipient, bool omniscient, bool withUserInfo)
Definition server_game.cpp:294
bool reverseTurnOrder()
Definition server_game.h:221
GameReplay * currentReplay
Definition server_game.h:99
int inactivityCounter
Definition server_game.h:92
int getMaxPlayers() const
Definition server_game.h:162
int getHostId() const
Definition server_game.h:128
void unattachCards(GameEventStorage &ges, Server_AbstractPlayer *player)
Definition server_game.cpp:676
QString getPassword() const
Definition server_game.h:158
void setDeckValidationStrategy(Server_DeckValidationStrategy *strategy)
Replace the deck validation strategy; takes ownership of strategy.
Definition server_game.cpp:996
Strategy hook invoked when a game has finished to decide the match result.
Definition server_match_result_strategy.h:15
Definition server_room.h:35
Definition game_event_handler.h:57
Definition game_event_handler.h:55
Definition event_game_state_changed.proto:8
LeaveReason
Definition event_leave.proto:7
Definition game_config.h:9
Definition game_event_container.proto:4
Definition game_event_context.proto:2
Definition game_replay.proto:4
ResponseCode
Definition response.proto:14
Definition serverinfo_game.proto:5
Definition serverinfo_user.proto:2