Cockatrice 2026-10-19-Development-3.1.2-beta.2
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
remote_client.h
Go to the documentation of this file.
1
6
7#ifndef REMOTECLIENT_H
8#define REMOTECLIENT_H
9
11#include "libcockatrice/protocol/pb/response.pb.h"
12#include "libcockatrice/protocol/pb/session_commands.pb.h"
13
14#include <QAbstractSocket>
15#include <QByteArray>
16#include <QLoggingCategory>
17#include <QString>
18#include <QTcpSocket>
19#include <QWebSocket>
20#include <QtGlobal>
21#include <qtmetamacros.h>
22
26class QObject;
27template <typename T> class QList;
28
29inline Q_LOGGING_CATEGORY(RemoteClientLog, "remote_client");
30
31class QTimer;
32
34{
35 Q_OBJECT
36signals:
38 void loginError(Response::ResponseCode resp, QString reasonStr, quint32 endTime, QList<QString> missingFeatures);
39 void registerError(Response::ResponseCode resp, QString reasonStr, quint32 endTime);
41 void socketError(const QString &errorString);
42 void protocolVersionMismatch(int clientVersion, int serverVersion);
43 void
44 sigConnectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password);
45 void sigRegisterToServer(const QString &hostname,
46 unsigned int port,
47 const QString &_userName,
48 const QString &_password,
49 const QString &_email,
50 const QString &_country,
51 const QString &_realname);
52 void sigActivateToServer(const QString &_token);
55 void sigRequestForgotPasswordToServer(const QString &hostname, unsigned int port, const QString &_userName);
59 void sigSubmitForgotPasswordResetToServer(const QString &hostname,
60 unsigned int port,
61 const QString &_userName,
62 const QString &_token,
63 const QString &_newpassword);
65 void sigSubmitForgotPasswordChallengeToServer(const QString &hostname,
66 unsigned int port,
67 const QString &_userName,
68 const QString &_email);
73 void sigPasswordVerifierReady(const QString &verifier);
74private slots:
75 void slotConnected();
76 void readData();
77 void websocketMessageReceived(const QByteArray &message);
78 void slotSocketError(QAbstractSocket::SocketError error);
79 void slotWebSocketError(QAbstractSocket::SocketError error);
80 void ping();
83 void passwordSaltResponse(const Response &response);
84 void loginResponse(const Response &response);
85 void registerResponse(const Response &response);
86 void activateResponse(const Response &response);
87 void
88 doConnectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password);
89 void doRegisterToServer(const QString &hostname,
90 unsigned int port,
91 const QString &_userName,
92 const QString &_password,
93 const QString &_email,
94 const QString &_country,
95 const QString &_realname);
97 void doLogin();
98 void doHashedLogin();
101 void submitPasswordVerifierResponse(const Response &response);
103 void doActivateToServer(const QString &_token);
104 void doRequestForgotPasswordToServer(const QString &hostname, unsigned int port, const QString &_userName);
105 void requestForgotPasswordResponse(const Response &response);
106 void doSubmitForgotPasswordResetToServer(const QString &hostname,
107 unsigned int port,
108 const QString &_userName,
109 const QString &_token,
110 const QString &_newpassword);
111 void submitForgotPasswordResetResponse(const Response &response);
112 void doSubmitForgotPasswordChallengeToServer(const QString &hostname,
113 unsigned int port,
114 const QString &_userName,
115 const QString &_email);
117
118private:
122 QByteArray inputBuffer;
127 QTimer *timer;
128 QTcpSocket *socket;
129 QWebSocket *websocket;
131 unsigned int lastPort;
141
142 QString getSrvClientID(const QString &_hostname);
143 bool newMissingFeatureFound(const QString &_serversMissingFeatures);
145 void connectToHost(const QString &hostname, unsigned int port);
146
147protected slots:
148 void sendCommandContainer(const CommandContainer &cont) override;
149
150public:
151 explicit RemoteClient(QObject *parent = nullptr, INetworkSettingsProvider *networkSettingsProvider = nullptr);
152 ~RemoteClient() override;
153 QString peerName() const
154 {
155 if (usingWebSocket) {
156 return websocket->peerName();
157 } else {
158 return socket->peerName();
159 }
160 }
161 quint16 peerPort() const
162 {
163 if (usingWebSocket) {
164 return websocket->peerPort();
165 } else {
166 return socket->peerPort();
167 }
168 }
169 QString serverName() const override
170 {
171 return lastHostname;
172 }
173 quint16 serverPort() const override
174 {
175 return static_cast<quint16>(lastPort);
176 }
177 void
178 connectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password);
181 void setStoredVerifier(const QString &verifier)
182 {
183 storedVerifier = verifier;
184 }
185 void registerToServer(const QString &hostname,
186 unsigned int port,
187 const QString &_userName,
188 const QString &_password,
189 const QString &_email,
190 const QString &_country,
191 const QString &_realname);
192 void activateToServer(const QString &_token);
194 void requestForgotPasswordToServer(const QString &hostname, unsigned int port, const QString &_userName);
195 void submitForgotPasswordResetToServer(const QString &hostname,
196 unsigned int port,
197 const QString &_userName,
198 const QString &_token,
199 const QString &_newpassword);
200 void submitForgotPasswordChallengeToServer(const QString &hostname,
201 unsigned int port,
202 const QString &_userName,
203 const QString &_email);
204};
205
206#endif
AbstractClient(QObject *parent=nullptr)
Definition abstract_client.cpp:43
Definition interface_network_settings_provider.h:6
Definition remote_connection_controller.h:20
void slotConnected()
Definition remote_client.cpp:112
void sigRequestForgotPasswordToServer(const QString &hostname, unsigned int port, const QString &_userName)
void processServerIdentificationEvent(const Event_ServerIdentification &event)
Definition remote_client.cpp:125
void connectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password)
Definition remote_client.cpp:715
int maxTimeout
Definition remote_client.h:120
void sigSubmitForgotPasswordChallengeToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_email)
void clearNewClientFeatures()
Definition remote_client.cpp:774
void disconnectFromServer()
Definition remote_client.cpp:739
void registerResponse(const Response &response)
Definition remote_client.cpp:455
bool usingWebSocket
Definition remote_client.h:125
void processConnectionClosedEvent(const Event_ConnectionClosed &event)
Definition remote_client.cpp:316
void sigForgotPasswordError()
RemoteClient(QObject *parent=nullptr, INetworkSettingsProvider *networkSettingsProvider=nullptr)
Definition remote_client.cpp:43
void requestForgotPasswordResponse(const Response &response)
Definition remote_client.cpp:814
bool newMissingFeatureFound(const QString &_serversMissingFeatures)
Definition remote_client.cpp:760
int timeRunning
Definition remote_client.h:121
bool handshakeStarted
Definition remote_client.h:124
void connectToHost(const QString &hostname, unsigned int port)
Definition remote_client.cpp:594
void ping()
Definition remote_client.cpp:684
void doRegisterToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password, const QString &_email, const QString &_country, const QString &_realname)
Definition remote_client.cpp:622
void doDisconnectFromServer()
Definition remote_client.cpp:655
void submitPasswordVerifierResponse(const Response &response)
Definition remote_client.cpp:303
void readData()
Definition remote_client.cpp:492
QString hashedPassword
Definition remote_client.h:132
void loginResponse(const Response &response)
Definition remote_client.cpp:401
QString derivedVerifier
Verifier derived during the current login, persisted after success.
Definition remote_client.h:138
void registerToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password, const QString &_email, const QString &_country, const QString &_realname)
Definition remote_client.cpp:723
void sigPromptForForgotPasswordReset()
void serverTimeout()
QTimer * timer
Definition remote_client.h:127
void setStoredVerifier(const QString &verifier)
Provide a stored "$scrypt$..." verifier so the client can authenticate without the plaintext password...
Definition remote_client.h:181
void doActivateToServer(const QString &_token)
Definition remote_client.cpp:645
void sigSubmitForgotPasswordResetToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_token, const QString &_newpassword)
void submitForgotPasswordResetResponse(const Response &response)
Definition remote_client.cpp:849
void activateToServer(const QString &_token)
Definition remote_client.cpp:734
void doSubmitPasswordVerifier()
Definition remote_client.cpp:292
QWebSocket * websocket
Definition remote_client.h:129
bool messageInProgress
Definition remote_client.h:123
void sigActivateToServer(const QString &_token)
void loginError(Response::ResponseCode resp, QString reasonStr, quint32 endTime, QList< QString > missingFeatures)
void passwordSaltResponse(const Response &response)
Definition remote_client.cpp:321
void doConnectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password)
Definition remote_client.cpp:605
void doSubmitForgotPasswordChallengeToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_email)
Definition remote_client.cpp:874
void slotSocketError(QAbstractSocket::SocketError error)
Definition remote_client.cpp:95
void websocketMessageReceived(const QByteArray &message)
Definition remote_client.cpp:546
void notifyUserAboutUpdate()
bool passwordNeedsMigration
Definition remote_client.h:133
void sigPasswordVerifierReady(const QString &verifier)
Emitted once a scrypt verifier for the given account is known and can be persisted instead of the pla...
void sigForgotPasswordSuccess()
void activateError()
int lastDataReceived
Definition remote_client.h:121
QString lastHostname
Definition remote_client.h:130
QTcpSocket * socket
Definition remote_client.h:128
void sigRegisterToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password, const QString &_email, const QString &_country, const QString &_realname)
QString pendingVerifier
Verifier sent for migration, persisted once the server accepts it.
Definition remote_client.h:140
void sigPromptForForgotPasswordChallenge()
void sendCommandContainer(const CommandContainer &cont) override
Definition remote_client.cpp:559
void socketError(const QString &errorString)
void slotWebSocketError(QAbstractSocket::SocketError error)
Definition remote_client.cpp:102
void doLogin()
Definition remote_client.cpp:254
void activateResponse(const Response &response)
Definition remote_client.cpp:481
void submitForgotPasswordResetToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_token, const QString &_newpassword)
Definition remote_client.cpp:793
INetworkSettingsProvider * networkSettingsProvider
Definition remote_client.h:119
void sigDisconnectFromServer()
void doRequestPasswordSalt()
Definition remote_client.cpp:226
void sigConnectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password)
void submitForgotPasswordChallengeResponse(const Response &response)
Definition remote_client.cpp:890
QString storedVerifier
A previously stored "$scrypt$..." verifier used to authenticate without the plaintext password.
Definition remote_client.h:136
void protocolVersionMismatch(int clientVersion, int serverVersion)
void doSubmitForgotPasswordResetToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_token, const QString &_newpassword)
Definition remote_client.cpp:830
void requestForgotPasswordToServer(const QString &hostname, unsigned int port, const QString &_userName)
Definition remote_client.cpp:788
void doHashedLogin()
Definition remote_client.cpp:280
void registerError(Response::ResponseCode resp, QString reasonStr, quint32 endTime)
void doRequestForgotPasswordToServer(const QString &hostname, unsigned int port, const QString &_userName)
Definition remote_client.cpp:802
quint16 serverPort() const override
Definition remote_client.h:173
QByteArray inputBuffer
Definition remote_client.h:122
void submitForgotPasswordChallengeToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_email)
Definition remote_client.cpp:866
unsigned int lastPort
Definition remote_client.h:131
int messageLength
Definition remote_client.h:126
QString peerName() const
Definition remote_client.h:153
QString getSrvClientID(const QString &_hostname)
Definition remote_client.cpp:744
quint16 peerPort() const
Definition remote_client.h:161
Command_Login generateCommandLogin()
Definition remote_client.cpp:237
QString serverName() const override
Returns the server address configured for the current connection.
Definition remote_client.h:169
Q_LOGGING_CATEGORY(CrashReportLog, "crash_report")
Definition commands.proto:8
Definition session_commands.proto:59
Definition event_connection_closed.proto:3
Definition event_server_identification.proto:3
Definition response.proto:11
ResponseCode
Definition response.proto:14