Cockatrice 2025-11-30-Development-2.11.0-beta.38
A cross-platform virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
abstract_client.h
Go to the documentation of this file.
1
6
7#ifndef ABSTRACTCLIENT_H
8#define ABSTRACTCLIENT_H
9
10#include <QMutex>
11#include <QVariant>
12#include <libcockatrice/protocol/pb/response.pb.h>
13#include <libcockatrice/protocol/pb/serverinfo_user.pb.h>
14
15class PendingCommand;
16class CommandContainer;
17class RoomEvent;
18class GameEventContainer;
19class ServerMessage;
20class Event_ServerIdentification;
21class Event_AddToList;
22class Event_RemoveFromList;
23class Event_UserJoined;
24class Event_UserLeft;
25class Event_ServerMessage;
26class Event_ListRooms;
27class Event_GameJoined;
28class Event_UserMessage;
29class Event_NotifyUser;
30class Event_ConnectionClosed;
31class Event_ServerShutdown;
32class Event_ReplayAdded;
33class FeatureSet;
34
49
50class AbstractClient : public QObject
51{
52 Q_OBJECT
53signals:
55 void maxPingTime(int seconds, int maxSeconds);
56
57 // Room events
58 void roomEventReceived(const RoomEvent &event);
59 // Game events
60 void gameEventContainerReceived(const GameEventContainer &event);
61 // Session events
62 void serverIdentificationEventReceived(const Event_ServerIdentification &event);
63 void connectionClosedEventReceived(const Event_ConnectionClosed &event);
64 void serverShutdownEventReceived(const Event_ServerShutdown &event);
65 void addToListEventReceived(const Event_AddToList &event);
66 void removeFromListEventReceived(const Event_RemoveFromList &event);
67 void userJoinedEventReceived(const Event_UserJoined &event);
68 void userLeftEventReceived(const Event_UserLeft &event);
69 void serverMessageEventReceived(const Event_ServerMessage &event);
70 void listRoomsEventReceived(const Event_ListRooms &event);
71 void gameJoinedEventReceived(const Event_GameJoined &event);
72 void userMessageEventReceived(const Event_UserMessage &event);
73 void notifyUserEventReceived(const Event_NotifyUser &event);
74 void userInfoChanged(const ServerInfo_User &userInfo);
75 void buddyListReceived(const QList<ServerInfo_User> &buddyList);
76 void ignoreListReceived(const QList<ServerInfo_User> &ignoreList);
77 void replayAddedEventReceived(const Event_ReplayAdded &event);
81
83
84private:
86 mutable QMutex clientMutex;
88private slots:
90protected slots:
91 void processProtocolItem(const ServerMessage &item);
92
93protected:
94 QMap<int, PendingCommand *> pendingCommands;
97 void setStatus(ClientStatus _status);
99 {
100 return nextCmdId++;
101 }
102 virtual void sendCommandContainer(const CommandContainer &cont) = 0;
103
104public:
105 explicit AbstractClient(QObject *parent = nullptr);
106 ~AbstractClient() override;
107
109 {
110 QMutexLocker locker(&clientMutex);
111 return status;
112 }
113 void sendCommand(const CommandContainer &cont);
114 void sendCommand(PendingCommand *pend);
115
117 {
119 }
120 const QString &getUserName() const
121 {
122 return userName;
123 }
124
125 static PendingCommand *prepareSessionCommand(const ::google::protobuf::Message &cmd);
126 static PendingCommand *prepareRoomCommand(const ::google::protobuf::Message &cmd, int roomId);
127 static PendingCommand *prepareModeratorCommand(const ::google::protobuf::Message &cmd);
128 static PendingCommand *prepareAdminCommand(const ::google::protobuf::Message &cmd);
129
130 QMap<QString, bool> clientFeatures;
131};
132
133#endif
ClientStatus
Definition abstract_client.h:36
@ StatusLoggingIn
Definition abstract_client.h:42
@ StatusLoggedIn
Definition abstract_client.h:43
@ StatusActivating
Definition abstract_client.h:41
@ StatusRequestingForgotPassword
Definition abstract_client.h:44
@ StatusConnecting
Definition abstract_client.h:39
@ StatusDisconnecting
Definition abstract_client.h:38
@ StatusDisconnected
Definition abstract_client.h:37
@ StatusSubmitForgotPasswordReset
Definition abstract_client.h:45
@ StatusSubmitForgotPasswordChallenge
Definition abstract_client.h:46
@ StatusGettingPasswordSalt
Definition abstract_client.h:47
@ StatusRegistering
Definition abstract_client.h:40
void roomEventReceived(const RoomEvent &event)
void userMessageEventReceived(const Event_UserMessage &event)
static PendingCommand * prepareAdminCommand(const ::google::protobuf::Message &cmd)
Definition abstract_client.cpp:191
void addToListEventReceived(const Event_AddToList &event)
void registerAccepted()
QString email
Definition abstract_client.h:95
void removeFromListEventReceived(const Event_RemoveFromList &event)
void gameEventContainerReceived(const GameEventContainer &event)
void serverMessageEventReceived(const Event_ServerMessage &event)
void gameJoinedEventReceived(const Event_GameJoined &event)
void notifyUserEventReceived(const Event_NotifyUser &event)
QMap< QString, bool > clientFeatures
Definition abstract_client.h:130
bool getServerSupportsPasswordHash() const
Definition abstract_client.h:116
void ignoreListReceived(const QList< ServerInfo_User > &ignoreList)
void processProtocolItem(const ServerMessage &item)
Definition abstract_client.cpp:61
bool serverSupportsPasswordHash
Definition abstract_client.h:96
~AbstractClient() override
Definition abstract_client.cpp:57
QString userName
Definition abstract_client.h:95
QString realName
Definition abstract_client.h:95
void sendCommand(const CommandContainer &cont)
Definition abstract_client.cpp:144
void buddyListReceived(const QList< ServerInfo_User > &buddyList)
void serverIdentificationEventReceived(const Event_ServerIdentification &event)
int nextCmdId
Definition abstract_client.h:85
QString token
Definition abstract_client.h:95
void connectionClosedEventReceived(const Event_ConnectionClosed &event)
int getNewCmdId()
Definition abstract_client.h:98
void maxPingTime(int seconds, int maxSeconds)
static PendingCommand * prepareModeratorCommand(const ::google::protobuf::Message &cmd)
Definition abstract_client.cpp:183
QMutex clientMutex
Definition abstract_client.h:86
QString country
Definition abstract_client.h:95
void replayAddedEventReceived(const Event_ReplayAdded &event)
void listRoomsEventReceived(const Event_ListRooms &event)
void statusChanged(ClientStatus _status)
void userInfoChanged(const ServerInfo_User &userInfo)
void setStatus(ClientStatus _status)
Definition abstract_client.cpp:135
AbstractClient(QObject *parent=nullptr)
Definition abstract_client.cpp:23
void sigQueuePendingCommand(PendingCommand *pend)
QString password
Definition abstract_client.h:95
ClientStatus getStatus() const
Definition abstract_client.h:108
const QString & getUserName() const
Definition abstract_client.h:120
QMap< int, PendingCommand * > pendingCommands
Definition abstract_client.h:94
virtual void sendCommandContainer(const CommandContainer &cont)=0
ClientStatus status
Definition abstract_client.h:87
void serverShutdownEventReceived(const Event_ServerShutdown &event)
void activateAccepted()
void registerAcceptedNeedsActivate()
void queuePendingCommand(PendingCommand *pend)
Definition abstract_client.cpp:155
void userJoinedEventReceived(const Event_UserJoined &event)
static PendingCommand * prepareRoomCommand(const ::google::protobuf::Message &cmd, int roomId)
Definition abstract_client.cpp:174
void userLeftEventReceived(const Event_UserLeft &event)
static PendingCommand * prepareSessionCommand(const ::google::protobuf::Message &cmd)
Definition abstract_client.cpp:166
Definition featureset.h:9
Definition pending_command.h:15