Cockatrice 2025-11-30-Development-2.11.0-beta.38
A cross-platform virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
server_room.h
Go to the documentation of this file.
1#ifndef SERVER_ROOM_H
2#define SERVER_ROOM_H
3
5
6#include <QMap>
7#include <QMutex>
8#include <QObject>
9#include <QReadWriteLock>
10#include <libcockatrice/protocol/pb/response.pb.h>
11#include <libcockatrice/protocol/pb/serverinfo_chat_message.pb.h>
12
15class RoomEvent;
16class ServerInfo_User;
17class ServerInfo_Room;
18class ServerInfo_Game;
19class Server_Game;
20class Server;
21
22class Command_JoinGame;
25
26class Server_Room : public QObject
27{
28 Q_OBJECT
29signals:
30 void roomInfoChanged(const ServerInfo_Room &roomInfo);
31 void gameListChanged(const ServerInfo_Game &gameInfo);
32
33private:
34 int id;
36 QString name;
37 QString description;
41 QString joinMessage;
42 QStringList gameTypes;
43 QMap<int, Server_Game *> games;
44 QMap<int, ServerInfo_Game> externalGames;
45 QMap<QString, Server_ProtocolHandler *> users;
46 QMap<QString, ServerInfo_User_Container> externalUsers;
47 QList<ServerInfo_ChatMessage> chatHistory;
48private slots:
49 void broadcastGameListUpdate(const ServerInfo_Game &gameInfo, bool sendToIsl = true);
50
51public:
52 mutable QReadWriteLock usersLock;
53 mutable QReadWriteLock gamesLock;
54 mutable QReadWriteLock historyLock;
55 Server_Room(int _id,
56 int _chatHistorySize,
57 const QString &_name,
58 const QString &_description,
59 const QString &_permissionLevel,
60 const QString &_privilegeLevel,
61 bool _autoJoin,
62 const QString &_joinMessage,
63 const QStringList &_gameTypes,
64 Server *parent);
65 ~Server_Room() override;
66 int getId() const
67 {
68 return id;
69 }
70 QString getName() const
71 {
72 return name;
73 }
74 QString getDescription() const
75 {
76 return description;
77 }
78 QString getRoomPermission() const
79 {
80 return permissionLevel;
81 }
82 QString getRoomPrivilege() const
83 {
84 return privilegeLevel;
85 }
86 bool getAutoJoin() const
87 {
88 return autoJoin;
89 }
90 bool userMayJoin(const ServerInfo_User &userInfo);
91 QString getJoinMessage() const
92 {
93 return joinMessage;
94 }
95 const QStringList &getGameTypes() const
96 {
97 return gameTypes;
98 }
99 const QMap<int, Server_Game *> &getGames() const
100 {
101 return games;
102 }
103 const QMap<int, ServerInfo_Game> &getExternalGames() const
104 {
105 return externalGames;
106 }
107 Server *getServer() const;
108 const ServerInfo_Room &
109 getInfo(ServerInfo_Room &result, bool complete, bool showGameTypes = false, bool includeExternalData = true) const;
110 int getGamesCreatedByUser(const QString &name) const;
111 QList<ServerInfo_Game> getGamesOfUser(const QString &name) const;
112 QList<ServerInfo_ChatMessage> &getChatHistory()
113 {
114 return chatHistory;
115 }
116
117 void addClient(Server_ProtocolHandler *client);
119
120 void addExternalUser(const ServerInfo_User &userInfo);
121 void removeExternalUser(const QString &_name);
122 const QMap<QString, ServerInfo_User_Container> &getExternalUsers() const
123 {
124 return externalUsers;
125 }
126 void updateExternalGameList(const ServerInfo_Game &gameInfo);
127
128 Response::ResponseCode processJoinGameCommand(const Command_JoinGame &cmd,
130 Server_AbstractUserInterface *userInterface);
131
132 void say(const QString &userName, const QString &s, bool sendToIsl = true);
133 void removeSaidMessages(const QString &userName, int amount, bool sendToIsl = true);
134
135 void addGame(Server_Game *game);
136 void removeGame(Server_Game *game);
137
138 void sendRoomEvent(RoomEvent *event, bool sendToIsl = true);
139 RoomEvent *prepareRoomEvent(const ::google::protobuf::Message &roomEvent);
140};
141
142#endif
Definition server_response_containers.h:89
Definition server_abstractuserinterface.h:20
Definition server_database_interface.h:9
Definition server_game.h:47
Definition server_protocolhandler.h:46
QList< ServerInfo_ChatMessage > chatHistory
Definition server_room.h:47
QReadWriteLock gamesLock
Definition server_room.h:53
void removeGame(Server_Game *game)
Definition server_room.cpp:376
QString getJoinMessage() const
Definition server_room.h:91
void addExternalUser(const ServerInfo_User &userInfo)
Definition server_room.cpp:185
QReadWriteLock usersLock
Definition server_room.h:52
QList< ServerInfo_Game > getGamesOfUser(const QString &name) const
Definition server_room.cpp:414
int id
Definition server_room.h:34
QString description
Definition server_room.h:37
QString getRoomPrivilege() const
Definition server_room.h:82
Server_Room(int _id, int _chatHistorySize, const QString &_name, const QString &_description, const QString &_permissionLevel, const QString &_privilegeLevel, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent)
Definition server_room.cpp:20
Response::ResponseCode processJoinGameCommand(const Command_JoinGame &cmd, ResponseContainer &rc, Server_AbstractUserInterface *userInterface)
Definition server_room.cpp:241
void addClient(Server_ProtocolHandler *client)
Definition server_room.cpp:139
void addGame(Server_Game *game)
Definition server_room.cpp:350
const QMap< int, Server_Game * > & getGames() const
Definition server_room.h:99
const ServerInfo_Room & getInfo(ServerInfo_Room &result, bool complete, bool showGameTypes=false, bool includeExternalData=true) const
Definition server_room.cpp:82
QMap< QString, Server_ProtocolHandler * > users
Definition server_room.h:45
Server * getServer() const
Definition server_room.cpp:76
QString getName() const
Definition server_room.h:70
QMap< int, ServerInfo_Game > externalGames
Definition server_room.h:44
void broadcastGameListUpdate(const ServerInfo_Game &gameInfo, bool sendToIsl=true)
Definition server_room.cpp:343
void say(const QString &userName, const QString &s, bool sendToIsl=true)
Definition server_room.cpp:280
QMap< int, Server_Game * > games
Definition server_room.h:43
void gameListChanged(const ServerInfo_Game &gameInfo)
QString getRoomPermission() const
Definition server_room.h:78
void removeSaidMessages(const QString &userName, int amount, bool sendToIsl=true)
Definition server_room.cpp:305
QString permissionLevel
Definition server_room.h:38
bool userMayJoin(const ServerInfo_User &userInfo)
Definition server_room.cpp:55
~Server_Room() override
Definition server_room.cpp:39
void roomInfoChanged(const ServerInfo_Room &roomInfo)
QString name
Definition server_room.h:36
QMap< QString, ServerInfo_User_Container > externalUsers
Definition server_room.h:46
int chatHistorySize
Definition server_room.h:35
const QMap< int, ServerInfo_Game > & getExternalGames() const
Definition server_room.h:103
RoomEvent * prepareRoomEvent(const ::google::protobuf::Message &roomEvent)
Definition server_room.cpp:129
void removeClient(Server_ProtocolHandler *client)
Definition server_room.cpp:162
QString joinMessage
Definition server_room.h:41
const QMap< QString, ServerInfo_User_Container > & getExternalUsers() const
Definition server_room.h:122
bool autoJoin
Definition server_room.h:40
QStringList gameTypes
Definition server_room.h:42
int getId() const
Definition server_room.h:66
const QStringList & getGameTypes() const
Definition server_room.h:95
QString getDescription() const
Definition server_room.h:74
QString privilegeLevel
Definition server_room.h:39
QReadWriteLock historyLock
Definition server_room.h:54
QList< ServerInfo_ChatMessage > & getChatHistory()
Definition server_room.h:112
bool getAutoJoin() const
Definition server_room.h:86
void sendRoomEvent(RoomEvent *event, bool sendToIsl=true)
Definition server_room.cpp:327
void removeExternalUser(const QString &_name)
Definition server_room.cpp:204
void updateExternalGameList(const ServerInfo_Game &gameInfo)
Definition server_room.cpp:223
int getGamesCreatedByUser(const QString &name) const
Definition server_room.cpp:402
Definition server.h:45