Cockatrice 2026-10-19-Development-3.1.2-beta.2
A 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
4#include <QList>
5#include <QMap>
6#include <QObject>
7#include <QReadWriteLock>
8#include <QString>
9#include <QStringList>
10#include <libcockatrice/protocol/pb/response.pb.h>
11#include <libcockatrice/protocol/pb/serverinfo_chat_message.pb.h>
12#include <libcockatrice/protocol/pb/serverinfo_room_channel.pb.h>
13#include <qtmetamacros.h>
14
16class RoomEvent;
17class ServerInfo_User;
18class ServerInfo_Room;
19class ServerInfo_Game;
20class Server_Game;
21class Server;
26namespace google
27{
28namespace protobuf
29{
30class Message;
31} // namespace protobuf
32} // namespace google
33
34class Server_Room : public QObject
35{
36 Q_OBJECT
37signals:
38 void roomInfoChanged(const ServerInfo_Room &roomInfo);
39 void gameListChanged(const ServerInfo_Game &gameInfo);
40
41private:
42 int id;
44 QString name;
45 QString description;
49 QString joinMessage;
50 QStringList gameTypes;
57private slots:
58 void broadcastGameListUpdate(const ServerInfo_Game &gameInfo, bool sendToIsl = true);
59
60public:
61 static const QString MAIN_CHANNEL_KEY;
62
63 mutable QReadWriteLock usersLock;
64 mutable QReadWriteLock gamesLock;
65 mutable QReadWriteLock historyLock;
66 Server_Room(int _id,
67 int _chatHistorySize,
68 const QString &_name,
69 const QString &_description,
70 const QString &_permissionLevel,
71 const QString &_privilegeLevel,
72 bool _autoJoin,
73 const QString &_joinMessage,
74 const QStringList &_gameTypes,
75 Server *parent,
76 const QList<ServerInfo_RoomChannel> &_channels = {});
77 ~Server_Room() override;
78 int getId() const
79 {
80 return id;
81 }
82 QString getName() const
83 {
84 return name;
85 }
86 QString getDescription() const
87 {
88 return description;
89 }
90 QString getRoomPermission() const
91 {
92 return permissionLevel;
93 }
94 QString getRoomPrivilege() const
95 {
96 return privilegeLevel;
97 }
98 bool getAutoJoin() const
99 {
100 return autoJoin;
101 }
102 bool userMayJoin(const ServerInfo_User &userInfo);
103 QString getJoinMessage() const
104 {
105 return joinMessage;
106 }
107 const QStringList &getGameTypes() const
108 {
109 return gameTypes;
110 }
112 {
113 return channels;
114 }
115
119 const ServerInfo_RoomChannel *findChannel(const QString &channelId) const;
121 static bool isMainChannel(const QString &channelId);
130 static bool hasChannelPrivilege(const ServerInfo_User &userInfo, ServerInfo_RoomChannel::AccessLevel requiredLevel);
132 static bool mayReadChannel(const ServerInfo_User &userInfo, const ServerInfo_RoomChannel &channel);
139 static bool mayWriteChannel(const ServerInfo_User &userInfo, const ServerInfo_RoomChannel &channel);
141 {
142 return games;
143 }
145 {
146 return externalGames;
147 }
148 Server *getServer() const;
150 bool complete,
151 bool showGameTypes = false,
152 bool includeExternalData = true,
153 const ServerInfo_User *forUser = nullptr) const;
154 int getGamesCreatedByUser(const QString &name) const;
155 QList<ServerInfo_Game> getGamesOfUser(const QString &name) const;
156 QList<ServerInfo_ChatMessage> getChatHistory(const QString &channelId) const;
157
158 void addClient(Server_ProtocolHandler *client);
160
161 void addExternalUser(const ServerInfo_User &userInfo);
162 void removeExternalUser(const QString &_name);
167 void updateExternalGameList(const ServerInfo_Game &gameInfo);
168
171 Server_AbstractUserInterface *userInterface);
172
173 void say(const QString &userName, const QString &s, const QString &channelId = QString(), bool sendToIsl = true);
174 void removeSaidMessages(const QString &userName, int amount, bool sendToIsl = true);
175
176 void addGame(Server_Game *game);
177 void removeGame(Server_Game *game);
178
179 void sendRoomEvent(RoomEvent *event,
180 bool sendToIsl = true,
182 RoomEvent *prepareRoomEvent(const ::google::protobuf::Message &roomEvent);
183};
184
185#endif
Definition remote_connection_controller.h:20
Definition game.h:18
Definition server_response_containers.h:93
Definition serverinfo_user_container.h:7
Definition server_abstractuserinterface.h:28
Definition server_game.h:67
Definition server_protocolhandler.h:40
Definition server_room.h:35
static const QString MAIN_CHANNEL_KEY
Definition server_room.h:61
QReadWriteLock gamesLock
Definition server_room.h:64
void removeGame(Server_Game *game)
Definition server_room.cpp:519
QString getJoinMessage() const
Definition server_room.h:103
void addExternalUser(const ServerInfo_User &userInfo)
Definition server_room.cpp:286
QReadWriteLock usersLock
Definition server_room.h:63
QList< ServerInfo_Game > getGamesOfUser(const QString &name) const
Definition server_room.cpp:559
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, const QList< ServerInfo_RoomChannel > &_channels={})
Definition server_room.cpp:43
int id
Definition server_room.h:42
const ServerInfo_Room & getInfo(ServerInfo_Room &result, bool complete, bool showGameTypes=false, bool includeExternalData=true, const ServerInfo_User *forUser=nullptr) const
Definition server_room.cpp:110
QString description
Definition server_room.h:45
static bool hasChannelPrivilege(const ServerInfo_User &userInfo, ServerInfo_RoomChannel::AccessLevel requiredLevel)
True when the flags in userInfo satisfy requiredLevel.
Definition server_room.cpp:188
static bool mayWriteChannel(const ServerInfo_User &userInfo, const ServerInfo_RoomChannel &channel)
True when userInfo may write to channel.
Definition server_room.cpp:219
QString getRoomPrivilege() const
Definition server_room.h:94
Response::ResponseCode processJoinGameCommand(const Command_JoinGame &cmd, ResponseContainer &rc, Server_AbstractUserInterface *userInterface)
Definition server_room.cpp:344
QMap< QString, QList< ServerInfo_ChatMessage > > channelChatHistory
Definition server_room.h:56
void addClient(Server_ProtocolHandler *client)
Definition server_room.cpp:240
void sendRoomEvent(RoomEvent *event, bool sendToIsl=true, ServerInfo_RoomChannel::AccessLevel accessLevel=ServerInfo_RoomChannel::Public)
Definition server_room.cpp:464
void addGame(Server_Game *game)
Definition server_room.cpp:493
const QMap< int, Server_Game * > & getGames() const
Definition server_room.h:140
const ServerInfo_RoomChannel * findChannel(const QString &channelId) const
Looks up a catalog channel by its stable id.
Definition server_room.cpp:178
QList< ServerInfo_ChatMessage > getChatHistory(const QString &channelId) const
Definition server_room.cpp:225
static bool isMainChannel(const QString &channelId)
True when channelId refers to the implicit Main channel.
Definition server_room.cpp:173
QMap< QString, Server_ProtocolHandler * > users
Definition server_room.h:54
Server * getServer() const
Definition server_room.cpp:105
QString getName() const
Definition server_room.h:82
QMap< int, ServerInfo_Game > externalGames
Definition server_room.h:53
void broadcastGameListUpdate(const ServerInfo_Game &gameInfo, bool sendToIsl=true)
Definition server_room.cpp:486
static bool mayReadChannel(const ServerInfo_User &userInfo, const ServerInfo_RoomChannel &channel)
True when userInfo may read channel.
Definition server_room.cpp:214
QMap< int, Server_Game * > games
Definition server_room.h:52
void gameListChanged(const ServerInfo_Game &gameInfo)
QString getRoomPermission() const
Definition server_room.h:90
void removeSaidMessages(const QString &userName, int amount, bool sendToIsl=true)
Definition server_room.cpp:438
QString permissionLevel
Definition server_room.h:46
bool userMayJoin(const ServerInfo_User &userInfo)
Definition server_room.cpp:80
void roomInfoChanged(const ServerInfo_Room &roomInfo)
QString name
Definition server_room.h:44
QMap< QString, ServerInfo_User_Container > externalUsers
Definition server_room.h:55
int chatHistorySize
Definition server_room.h:43
const QMap< int, ServerInfo_Game > & getExternalGames() const
Definition server_room.h:144
RoomEvent * prepareRoomEvent(const ::google::protobuf::Message &roomEvent)
Definition server_room.cpp:230
void removeClient(Server_ProtocolHandler *client)
Definition server_room.cpp:263
QString joinMessage
Definition server_room.h:49
const QMap< QString, ServerInfo_User_Container > & getExternalUsers() const
Definition server_room.h:163
bool autoJoin
Definition server_room.h:48
QStringList gameTypes
Definition server_room.h:50
const QList< ServerInfo_RoomChannel > & getChannels() const
Definition server_room.h:111
int getId() const
Definition server_room.h:78
const QStringList & getGameTypes() const
Definition server_room.h:107
QString getDescription() const
Definition server_room.h:86
QString privilegeLevel
Definition server_room.h:47
QReadWriteLock historyLock
Definition server_room.h:65
QList< ServerInfo_RoomChannel > channels
Definition server_room.h:51
bool getAutoJoin() const
Definition server_room.h:98
void removeExternalUser(const QString &_name)
Definition server_room.cpp:305
void say(const QString &userName, const QString &s, const QString &channelId=QString(), bool sendToIsl=true)
Definition server_room.cpp:385
void updateExternalGameList(const ServerInfo_Game &gameInfo)
Definition server_room.cpp:325
int getGamesCreatedByUser(const QString &name) const
Definition server_room.cpp:545
Definition server.h:48
Definition game_event_handler.h:57
Definition game_event_handler.h:55
Definition room_commands.proto:79
ResponseCode
Definition response.proto:14
Definition room_event.proto:2
Definition serverinfo_game.proto:5
Definition serverinfo_room_channel.proto:2
AccessLevel
Definition serverinfo_room_channel.proto:3
@ Public
Definition serverinfo_room_channel.proto:9
Definition serverinfo_room.proto:6
Definition serverinfo_user.proto:2