mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 00:04:48 -07:00
Clang-format (#3028)
* 1/3 Add .clang-format file and travis compilation check * 2/3 Run clang-format * 3/3 Fix compilation problems due to include reordering * 3bis/3 AfterControlStatement: false
This commit is contained in:
parent
8dbdd24c8e
commit
b29bd9e070
272 changed files with 13378 additions and 9535 deletions
|
|
@ -1,29 +1,29 @@
|
|||
#include <QDebug>
|
||||
#include <QList>
|
||||
#include <QTimer>
|
||||
#include <QThread>
|
||||
#include <QCryptographicHash>
|
||||
#include <QHostInfo>
|
||||
#include <QHostAddress>
|
||||
#include "remoteclient.h"
|
||||
#include "settingscache.h"
|
||||
#include "pending_command.h"
|
||||
#include "main.h"
|
||||
#include "pb/commands.pb.h"
|
||||
#include "pb/session_commands.pb.h"
|
||||
#include "pb/response_login.pb.h"
|
||||
#include "pb/response_register.pb.h"
|
||||
#include "pb/event_server_identification.pb.h"
|
||||
#include "pb/response_activate.pb.h"
|
||||
#include "pb/response_forgotpasswordrequest.pb.h"
|
||||
#include "pb/response_login.pb.h"
|
||||
#include "pb/response_register.pb.h"
|
||||
#include "pb/server_message.pb.h"
|
||||
#include "pb/event_server_identification.pb.h"
|
||||
#include "pb/session_commands.pb.h"
|
||||
#include "pending_command.h"
|
||||
#include "settingscache.h"
|
||||
#include "main.h"
|
||||
#include "version_string.h"
|
||||
#include <QCryptographicHash>
|
||||
#include <QDebug>
|
||||
#include <QHostAddress>
|
||||
#include <QHostInfo>
|
||||
#include <QList>
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
|
||||
static const unsigned int protocolVersion = 14;
|
||||
|
||||
RemoteClient::RemoteClient(QObject *parent)
|
||||
: AbstractClient(parent), timeRunning(0), lastDataReceived(0), messageInProgress(false), handshakeStarted(false), messageLength(0)
|
||||
: AbstractClient(parent), timeRunning(0), lastDataReceived(0), messageInProgress(false), handshakeStarted(false),
|
||||
messageLength(0)
|
||||
{
|
||||
|
||||
clearNewClientFeatures();
|
||||
|
|
@ -32,21 +32,28 @@ RemoteClient::RemoteClient(QObject *parent)
|
|||
timer->setInterval(keepalive * 1000);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(ping()));
|
||||
|
||||
|
||||
socket = new QTcpSocket(this);
|
||||
socket->setSocketOption(QAbstractSocket::LowDelayOption, 1);
|
||||
connect(socket, SIGNAL(connected()), this, SLOT(slotConnected()));
|
||||
connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
|
||||
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slotSocketError(QAbstractSocket::SocketError)));
|
||||
connect(this, SIGNAL(serverIdentificationEventReceived(const Event_ServerIdentification &)), this, SLOT(processServerIdentificationEvent(const Event_ServerIdentification &)));
|
||||
connect(this, SIGNAL(connectionClosedEventReceived(Event_ConnectionClosed)), this, SLOT(processConnectionClosedEvent(Event_ConnectionClosed)));
|
||||
connect(this, SIGNAL(sigConnectToServer(QString, unsigned int, QString, QString)), this, SLOT(doConnectToServer(QString, unsigned int, QString, QString)));
|
||||
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this,
|
||||
SLOT(slotSocketError(QAbstractSocket::SocketError)));
|
||||
connect(this, SIGNAL(serverIdentificationEventReceived(const Event_ServerIdentification &)), this,
|
||||
SLOT(processServerIdentificationEvent(const Event_ServerIdentification &)));
|
||||
connect(this, SIGNAL(connectionClosedEventReceived(Event_ConnectionClosed)), this,
|
||||
SLOT(processConnectionClosedEvent(Event_ConnectionClosed)));
|
||||
connect(this, SIGNAL(sigConnectToServer(QString, unsigned int, QString, QString)), this,
|
||||
SLOT(doConnectToServer(QString, unsigned int, QString, QString)));
|
||||
connect(this, SIGNAL(sigDisconnectFromServer()), this, SLOT(doDisconnectFromServer()));
|
||||
connect(this, SIGNAL(sigRegisterToServer(QString, unsigned int, QString, QString, QString, int, QString, QString)), this, SLOT(doRegisterToServer(QString, unsigned int, QString, QString, QString, int, QString, QString)));
|
||||
connect(this, SIGNAL(sigRegisterToServer(QString, unsigned int, QString, QString, QString, int, QString, QString)),
|
||||
this, SLOT(doRegisterToServer(QString, unsigned int, QString, QString, QString, int, QString, QString)));
|
||||
connect(this, SIGNAL(sigActivateToServer(QString)), this, SLOT(doActivateToServer(QString)));
|
||||
connect(this, SIGNAL(sigRequestForgotPasswordToServer(QString, unsigned int, QString)), this, SLOT(doRequestForgotPasswordToServer(QString, unsigned int, QString)));
|
||||
connect(this, SIGNAL(sigSubmitForgotPasswordResetToServer(QString, unsigned int, QString, QString, QString)), this, SLOT(doSubmitForgotPasswordResetToServer(QString, unsigned int, QString, QString, QString)));
|
||||
connect(this, SIGNAL(sigSubmitForgotPasswordChallengeToServer(QString, unsigned int, QString, QString)), this, SLOT(doSubmitForgotPasswordChallengeToServer(QString, unsigned int, QString, QString)));
|
||||
connect(this, SIGNAL(sigRequestForgotPasswordToServer(QString, unsigned int, QString)), this,
|
||||
SLOT(doRequestForgotPasswordToServer(QString, unsigned int, QString)));
|
||||
connect(this, SIGNAL(sigSubmitForgotPasswordResetToServer(QString, unsigned int, QString, QString, QString)), this,
|
||||
SLOT(doSubmitForgotPasswordResetToServer(QString, unsigned int, QString, QString, QString)));
|
||||
connect(this, SIGNAL(sigSubmitForgotPasswordChallengeToServer(QString, unsigned int, QString, QString)), this,
|
||||
SLOT(doSubmitForgotPasswordChallengeToServer(QString, unsigned int, QString, QString)));
|
||||
}
|
||||
|
||||
RemoteClient::~RemoteClient()
|
||||
|
|
@ -81,49 +88,48 @@ void RemoteClient::processServerIdentificationEvent(const Event_ServerIdentifica
|
|||
return;
|
||||
}
|
||||
|
||||
if (getStatus() == StatusRequestingForgotPassword)
|
||||
{
|
||||
if (getStatus() == StatusRequestingForgotPassword) {
|
||||
Command_ForgotPasswordRequest cmdForgotPasswordRequest;
|
||||
cmdForgotPasswordRequest.set_user_name(userName.toStdString());
|
||||
cmdForgotPasswordRequest.set_clientid(getSrvClientID(lastHostname).toStdString());
|
||||
PendingCommand *pend = prepareSessionCommand(cmdForgotPasswordRequest);
|
||||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(requestForgotPasswordResponse(Response)));
|
||||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
|
||||
SLOT(requestForgotPasswordResponse(Response)));
|
||||
sendCommand(pend);
|
||||
return;
|
||||
}
|
||||
|
||||
if (getStatus() == StatusSubmitForgotPasswordReset)
|
||||
{
|
||||
if (getStatus() == StatusSubmitForgotPasswordReset) {
|
||||
Command_ForgotPasswordReset cmdForgotPasswordReset;
|
||||
cmdForgotPasswordReset.set_user_name(userName.toStdString());
|
||||
cmdForgotPasswordReset.set_clientid(getSrvClientID(lastHostname).toStdString());
|
||||
cmdForgotPasswordReset.set_token(token.toStdString());
|
||||
cmdForgotPasswordReset.set_new_password(password.toStdString());
|
||||
PendingCommand *pend = prepareSessionCommand(cmdForgotPasswordReset);
|
||||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(submitForgotPasswordResetResponse(Response)));
|
||||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
|
||||
SLOT(submitForgotPasswordResetResponse(Response)));
|
||||
sendCommand(pend);
|
||||
return;
|
||||
}
|
||||
|
||||
if (getStatus() == StatusSubmitForgotPasswordChallenge)
|
||||
{
|
||||
if (getStatus() == StatusSubmitForgotPasswordChallenge) {
|
||||
Command_ForgotPasswordChallenge cmdForgotPasswordChallenge;
|
||||
cmdForgotPasswordChallenge.set_user_name(userName.toStdString());
|
||||
cmdForgotPasswordChallenge.set_clientid(getSrvClientID(lastHostname).toStdString());
|
||||
cmdForgotPasswordChallenge.set_email(email.toStdString());
|
||||
PendingCommand *pend = prepareSessionCommand(cmdForgotPasswordChallenge);
|
||||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(submitForgotPasswordChallengeResponse(Response)));
|
||||
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this,
|
||||
SLOT(submitForgotPasswordChallengeResponse(Response)));
|
||||
sendCommand(pend);
|
||||
return;
|
||||
}
|
||||
|
||||
if(getStatus() == StatusRegistering)
|
||||
{
|
||||
if (getStatus() == StatusRegistering) {
|
||||
Command_Register cmdRegister;
|
||||
cmdRegister.set_user_name(userName.toStdString());
|
||||
cmdRegister.set_password(password.toStdString());
|
||||
cmdRegister.set_email(email.toStdString());
|
||||
cmdRegister.set_gender((ServerInfo_User_Gender) gender);
|
||||
cmdRegister.set_gender((ServerInfo_User_Gender)gender);
|
||||
cmdRegister.set_country(country.toStdString());
|
||||
cmdRegister.set_real_name(realName.toStdString());
|
||||
cmdRegister.set_clientid(getSrvClientID(lastHostname).toStdString());
|
||||
|
|
@ -134,8 +140,7 @@ void RemoteClient::processServerIdentificationEvent(const Event_ServerIdentifica
|
|||
return;
|
||||
}
|
||||
|
||||
if(getStatus() == StatusActivating)
|
||||
{
|
||||
if (getStatus() == StatusActivating) {
|
||||
Command_Activate cmdActivate;
|
||||
cmdActivate.set_user_name(userName.toStdString());
|
||||
cmdActivate.set_token(token.toStdString());
|
||||
|
|
@ -151,7 +156,8 @@ void RemoteClient::processServerIdentificationEvent(const Event_ServerIdentifica
|
|||
doLogin();
|
||||
}
|
||||
|
||||
void RemoteClient::doLogin() {
|
||||
void RemoteClient::doLogin()
|
||||
{
|
||||
setStatus(StatusLoggingIn);
|
||||
Command_Login cmdLogin;
|
||||
cmdLogin.set_user_name(userName.toStdString());
|
||||
|
|
@ -177,7 +183,7 @@ void RemoteClient::processConnectionClosedEvent(const Event_ConnectionClosed & /
|
|||
void RemoteClient::loginResponse(const Response &response)
|
||||
{
|
||||
const Response_Login &resp = response.GetExtension(Response_Login::ext);
|
||||
|
||||
|
||||
QString possibleMissingFeatures;
|
||||
if (resp.missing_features_size() > 0) {
|
||||
for (int i = 0; i < resp.missing_features_size(); ++i)
|
||||
|
|
@ -198,7 +204,8 @@ void RemoteClient::loginResponse(const Response &response)
|
|||
ignoreList.append(resp.ignore_list(i));
|
||||
emit ignoreListReceived(ignoreList);
|
||||
|
||||
if (newMissingFeatureFound(possibleMissingFeatures) && resp.missing_features_size() > 0 && settingsCache->getNotifyAboutUpdates()) {
|
||||
if (newMissingFeatureFound(possibleMissingFeatures) && resp.missing_features_size() > 0 &&
|
||||
settingsCache->getNotifyAboutUpdates()) {
|
||||
settingsCache->setKnownMissingFeatures(possibleMissingFeatures);
|
||||
emit notifyUserAboutUpdate();
|
||||
}
|
||||
|
|
@ -209,7 +216,8 @@ void RemoteClient::loginResponse(const Response &response)
|
|||
for (int i = 0; i < resp.missing_features_size(); ++i)
|
||||
missingFeatures << QString::fromStdString(resp.missing_features(i));
|
||||
}
|
||||
emit loginError(response.response_code(), QString::fromStdString(resp.denied_reason_str()), resp.denied_end_time(), missingFeatures);
|
||||
emit loginError(response.response_code(), QString::fromStdString(resp.denied_reason_str()),
|
||||
resp.denied_end_time(), missingFeatures);
|
||||
setStatus(StatusDisconnecting);
|
||||
}
|
||||
}
|
||||
|
|
@ -217,8 +225,7 @@ void RemoteClient::loginResponse(const Response &response)
|
|||
void RemoteClient::registerResponse(const Response &response)
|
||||
{
|
||||
const Response_Register &resp = response.GetExtension(Response_Register::ext);
|
||||
switch(response.response_code())
|
||||
{
|
||||
switch (response.response_code()) {
|
||||
case Response::RespRegistrationAccepted:
|
||||
emit registerAccepted();
|
||||
doLogin();
|
||||
|
|
@ -228,7 +235,8 @@ void RemoteClient::registerResponse(const Response &response)
|
|||
doLogin();
|
||||
break;
|
||||
default:
|
||||
emit registerError(response.response_code(), QString::fromStdString(resp.denied_reason_str()), resp.denied_end_time());
|
||||
emit registerError(response.response_code(), QString::fromStdString(resp.denied_reason_str()),
|
||||
resp.denied_end_time());
|
||||
setStatus(StatusDisconnecting);
|
||||
doDisconnectFromServer();
|
||||
break;
|
||||
|
|
@ -264,11 +272,11 @@ void RemoteClient::readData()
|
|||
messageLength = 60;
|
||||
}
|
||||
} else {
|
||||
// end of hack
|
||||
messageLength = (((quint32) (unsigned char) inputBuffer[0]) << 24)
|
||||
+ (((quint32) (unsigned char) inputBuffer[1]) << 16)
|
||||
+ (((quint32) (unsigned char) inputBuffer[2]) << 8)
|
||||
+ ((quint32) (unsigned char) inputBuffer[3]);
|
||||
// end of hack
|
||||
messageLength = (((quint32)(unsigned char)inputBuffer[0]) << 24) +
|
||||
(((quint32)(unsigned char)inputBuffer[1]) << 16) +
|
||||
(((quint32)(unsigned char)inputBuffer[2]) << 8) +
|
||||
((quint32)(unsigned char)inputBuffer[3]);
|
||||
inputBuffer.remove(0, 4);
|
||||
messageInProgress = true;
|
||||
}
|
||||
|
|
@ -302,15 +310,18 @@ void RemoteClient::sendCommandContainer(const CommandContainer &cont)
|
|||
#endif
|
||||
buf.resize(size + 4);
|
||||
cont.SerializeToArray(buf.data() + 4, size);
|
||||
buf.data()[3] = (unsigned char) size;
|
||||
buf.data()[2] = (unsigned char) (size >> 8);
|
||||
buf.data()[1] = (unsigned char) (size >> 16);
|
||||
buf.data()[0] = (unsigned char) (size >> 24);
|
||||
buf.data()[3] = (unsigned char)size;
|
||||
buf.data()[2] = (unsigned char)(size >> 8);
|
||||
buf.data()[1] = (unsigned char)(size >> 16);
|
||||
buf.data()[0] = (unsigned char)(size >> 24);
|
||||
|
||||
socket->write(buf);
|
||||
}
|
||||
|
||||
void RemoteClient::doConnectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password)
|
||||
void RemoteClient::doConnectToServer(const QString &hostname,
|
||||
unsigned int port,
|
||||
const QString &_userName,
|
||||
const QString &_password)
|
||||
{
|
||||
doDisconnectFromServer();
|
||||
|
||||
|
|
@ -323,7 +334,14 @@ void RemoteClient::doConnectToServer(const QString &hostname, unsigned int port,
|
|||
setStatus(StatusConnecting);
|
||||
}
|
||||
|
||||
void RemoteClient::doRegisterToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password, const QString &_email, const int _gender, const QString &_country, const QString &_realname)
|
||||
void RemoteClient::doRegisterToServer(const QString &hostname,
|
||||
unsigned int port,
|
||||
const QString &_userName,
|
||||
const QString &_password,
|
||||
const QString &_email,
|
||||
const int _gender,
|
||||
const QString &_country,
|
||||
const QString &_realname)
|
||||
{
|
||||
doDisconnectFromServer();
|
||||
|
||||
|
|
@ -396,12 +414,22 @@ void RemoteClient::ping()
|
|||
}
|
||||
}
|
||||
|
||||
void RemoteClient::connectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password)
|
||||
void RemoteClient::connectToServer(const QString &hostname,
|
||||
unsigned int port,
|
||||
const QString &_userName,
|
||||
const QString &_password)
|
||||
{
|
||||
emit sigConnectToServer(hostname, port, _userName, _password);
|
||||
}
|
||||
|
||||
void RemoteClient::registerToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password, const QString &_email, const int _gender, const QString &_country, const QString &_realname)
|
||||
void RemoteClient::registerToServer(const QString &hostname,
|
||||
unsigned int port,
|
||||
const QString &_userName,
|
||||
const QString &_password,
|
||||
const QString &_email,
|
||||
const int _gender,
|
||||
const QString &_country,
|
||||
const QString &_realname)
|
||||
{
|
||||
emit sigRegisterToServer(hostname, port, _userName, _password, _email, _gender, _country, _realname);
|
||||
}
|
||||
|
|
@ -423,12 +451,12 @@ QString RemoteClient::getSrvClientID(const QString _hostname)
|
|||
if (!hostInfo.error()) {
|
||||
QHostAddress hostAddress = hostInfo.addresses().first();
|
||||
srvClientID += hostAddress.toString();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
qDebug() << "Warning: ClientID generation host lookup failure [" << hostInfo.errorString() << "]";
|
||||
srvClientID += _hostname;
|
||||
}
|
||||
QString uniqueServerClientID = QCryptographicHash::hash(srvClientID.toUtf8(), QCryptographicHash::Sha1).toHex().right(15);
|
||||
QString uniqueServerClientID =
|
||||
QCryptographicHash::hash(srvClientID.toUtf8(), QCryptographicHash::Sha1).toHex().right(15);
|
||||
return uniqueServerClientID;
|
||||
}
|
||||
|
||||
|
|
@ -436,7 +464,7 @@ bool RemoteClient::newMissingFeatureFound(QString _serversMissingFeatures)
|
|||
{
|
||||
bool newMissingFeature = false;
|
||||
QStringList serversMissingFeaturesList = _serversMissingFeatures.split(",");
|
||||
foreach(const QString &feature, serversMissingFeaturesList) {
|
||||
foreach (const QString &feature, serversMissingFeaturesList) {
|
||||
if (!feature.isEmpty()) {
|
||||
if (!settingsCache->getKnownMissingFeatures().contains(feature))
|
||||
return true;
|
||||
|
|
@ -449,7 +477,7 @@ void RemoteClient::clearNewClientFeatures()
|
|||
{
|
||||
QString newKnownMissingFeatures;
|
||||
QStringList existingKnownMissingFeatures = settingsCache->getKnownMissingFeatures().split(",");
|
||||
foreach(const QString &existingKnownFeature, existingKnownMissingFeatures) {
|
||||
foreach (const QString &existingKnownFeature, existingKnownMissingFeatures) {
|
||||
if (!existingKnownFeature.isEmpty()) {
|
||||
if (!clientFeatures.contains(existingKnownFeature))
|
||||
newKnownMissingFeatures.append("," + existingKnownFeature);
|
||||
|
|
@ -463,7 +491,11 @@ void RemoteClient::requestForgotPasswordToServer(const QString &hostname, unsign
|
|||
emit sigRequestForgotPasswordToServer(hostname, port, _userName);
|
||||
}
|
||||
|
||||
void RemoteClient::submitForgotPasswordResetToServer(const QString & hostname, unsigned int port, const QString & _userName, const QString & _token, const QString & _newpassword)
|
||||
void RemoteClient::submitForgotPasswordResetToServer(const QString &hostname,
|
||||
unsigned int port,
|
||||
const QString &_userName,
|
||||
const QString &_token,
|
||||
const QString &_newpassword)
|
||||
{
|
||||
emit sigSubmitForgotPasswordResetToServer(hostname, port, _userName, _token, _newpassword);
|
||||
}
|
||||
|
|
@ -483,22 +515,22 @@ void RemoteClient::doRequestForgotPasswordToServer(const QString &hostname, unsi
|
|||
void RemoteClient::requestForgotPasswordResponse(const Response &response)
|
||||
{
|
||||
const Response_ForgotPasswordRequest &resp = response.GetExtension(Response_ForgotPasswordRequest::ext);
|
||||
if (response.response_code() == Response::RespOk)
|
||||
{
|
||||
if (response.response_code() == Response::RespOk) {
|
||||
if (resp.challenge_email()) {
|
||||
emit sigPromptForForgotPasswordChallenge();
|
||||
}
|
||||
else
|
||||
} else
|
||||
emit sigPromptForForgotPasswordReset();
|
||||
}
|
||||
else
|
||||
} else
|
||||
emit sigForgotPasswordError();
|
||||
|
||||
doDisconnectFromServer();
|
||||
|
||||
}
|
||||
|
||||
void RemoteClient::doSubmitForgotPasswordResetToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_token, const QString &_newpassword)
|
||||
void RemoteClient::doSubmitForgotPasswordResetToServer(const QString &hostname,
|
||||
unsigned int port,
|
||||
const QString &_userName,
|
||||
const QString &_token,
|
||||
const QString &_newpassword)
|
||||
{
|
||||
doDisconnectFromServer();
|
||||
|
||||
|
|
@ -522,12 +554,18 @@ void RemoteClient::submitForgotPasswordResetResponse(const Response &response)
|
|||
doDisconnectFromServer();
|
||||
}
|
||||
|
||||
void RemoteClient::submitForgotPasswordChallengeToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_email)
|
||||
void RemoteClient::submitForgotPasswordChallengeToServer(const QString &hostname,
|
||||
unsigned int port,
|
||||
const QString &_userName,
|
||||
const QString &_email)
|
||||
{
|
||||
emit sigSubmitForgotPasswordChallengeToServer(hostname, port, _userName, _email);
|
||||
}
|
||||
|
||||
void RemoteClient::doSubmitForgotPasswordChallengeToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_email)
|
||||
void RemoteClient::doSubmitForgotPasswordChallengeToServer(const QString &hostname,
|
||||
unsigned int port,
|
||||
const QString &_userName,
|
||||
const QString &_email)
|
||||
{
|
||||
doDisconnectFromServer();
|
||||
|
||||
|
|
@ -544,8 +582,7 @@ void RemoteClient::submitForgotPasswordChallengeResponse(const Response &respons
|
|||
{
|
||||
if (response.response_code() == Response::RespOk) {
|
||||
emit sigPromptForForgotPasswordReset();
|
||||
}
|
||||
else
|
||||
} else
|
||||
emit sigForgotPasswordError();
|
||||
|
||||
doDisconnectFromServer();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue