From ee849f6379658a989be9c4588bb2e3db668b9738 Mon Sep 17 00:00:00 2001 From: woogerboy21 Date: Tue, 29 Mar 2016 17:05:25 -0400 Subject: [PATCH 1/3] Updated ClientID Functionality ClientID is now generated on startup and stored in settings cache. Then upon connect there is a new SrvClientID generated from the ClientID + servername being connected to --- cockatrice/src/remoteclient.cpp | 6 ++---- cockatrice/src/settingscache.cpp | 9 +++++++++ cockatrice/src/settingscache.h | 3 ++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cockatrice/src/remoteclient.cpp b/cockatrice/src/remoteclient.cpp index b652726d..cb184070 100644 --- a/cockatrice/src/remoteclient.cpp +++ b/cockatrice/src/remoteclient.cpp @@ -81,7 +81,7 @@ void RemoteClient::processServerIdentificationEvent(const Event_ServerIdentifica cmdRegister.set_gender((ServerInfo_User_Gender) gender); cmdRegister.set_country(country.toStdString()); cmdRegister.set_real_name(realName.toStdString()); - cmdRegister.set_clientid(settingsCache->getClientID().toStdString()); + cmdRegister.set_clientid(settingsCache->getSrvClientID(lastHostname).toStdString()); PendingCommand *pend = prepareSessionCommand(cmdRegister); connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(registerResponse(Response))); sendCommand(pend); @@ -111,7 +111,7 @@ void RemoteClient::doLogin() { Command_Login cmdLogin; cmdLogin.set_user_name(userName.toStdString()); cmdLogin.set_password(password.toStdString()); - cmdLogin.set_clientid(settingsCache->getClientID().toStdString()); + cmdLogin.set_clientid(settingsCache->getSrvClientID(lastHostname).toStdString()); cmdLogin.set_clientver(VERSION_STRING); if (!clientFeatures.isEmpty()) { @@ -119,7 +119,6 @@ void RemoteClient::doLogin() { for (i = clientFeatures.begin(); i != clientFeatures.end(); ++i) cmdLogin.add_clientfeatures(i.key().toStdString().c_str()); } - PendingCommand *pend = prepareSessionCommand(cmdLogin); connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(loginResponse(Response))); sendCommand(pend); @@ -263,7 +262,6 @@ void RemoteClient::doConnectToServer(const QString &hostname, unsigned int port, userName = _userName; password = _password; - QString clientid = settingsCache->getClientID(); lastHostname = hostname; lastPort = port; diff --git a/cockatrice/src/settingscache.cpp b/cockatrice/src/settingscache.cpp index 9d1f6625..1334e9ac 100644 --- a/cockatrice/src/settingscache.cpp +++ b/cockatrice/src/settingscache.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #if QT_VERSION >= 0x050000 #include @@ -612,4 +613,12 @@ void SettingsCache::setNotifyAboutUpdate(int _notifyaboutupdate) { notifyAboutUpdates = _notifyaboutupdate; settings->setValue("personal/updatenotification", notifyAboutUpdates); +} + +QString SettingsCache::getSrvClientID(const QString _hostname) +{ + QString srvClientID = getClientID(); + srvClientID += _hostname; + QString uniqueServerClientID = QCryptographicHash::hash(srvClientID.toUtf8(), QCryptographicHash::Sha1).toHex().right(15); + return uniqueServerClientID; } \ No newline at end of file diff --git a/cockatrice/src/settingscache.h b/cockatrice/src/settingscache.h index 036f6966..cdeda46b 100644 --- a/cockatrice/src/settingscache.h +++ b/cockatrice/src/settingscache.h @@ -176,7 +176,8 @@ public: bool getRememberGameSettings() const { return rememberGameSettings; } int getKeepAlive() const { return keepalive; } void setClientID(QString clientID); - QString getClientID() { return clientID; } + QString getClientID() { return clientID; } + QString getSrvClientID(const QString _hostname); ShortcutsSettings& shortcuts() const { return *shortcutsSettings; } CardDatabaseSettings& cardDatabase() const { return *cardDatabaseSettings; } ServersSettings& servers() const { return *serversSettings; } From 506ad91b03ff211dc7485d659b846b174bca8c8e Mon Sep 17 00:00:00 2001 From: woogerboy21 Date: Tue, 29 Mar 2016 22:00:42 -0400 Subject: [PATCH 2/3] Privatized Function Moved the updated hashing function out of the settingscache and into the remoteclient and privatized the function for proper use. --- cockatrice/src/remoteclient.cpp | 14 +++++++++++--- cockatrice/src/remoteclient.h | 1 + cockatrice/src/settingscache.cpp | 9 --------- cockatrice/src/settingscache.h | 3 +-- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/cockatrice/src/remoteclient.cpp b/cockatrice/src/remoteclient.cpp index cb184070..e1bda71e 100644 --- a/cockatrice/src/remoteclient.cpp +++ b/cockatrice/src/remoteclient.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "remoteclient.h" #include "settingscache.h" #include "pending_command.h" @@ -81,7 +82,7 @@ void RemoteClient::processServerIdentificationEvent(const Event_ServerIdentifica cmdRegister.set_gender((ServerInfo_User_Gender) gender); cmdRegister.set_country(country.toStdString()); cmdRegister.set_real_name(realName.toStdString()); - cmdRegister.set_clientid(settingsCache->getSrvClientID(lastHostname).toStdString()); + cmdRegister.set_clientid(getSrvClientID(lastHostname).toStdString()); PendingCommand *pend = prepareSessionCommand(cmdRegister); connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(registerResponse(Response))); sendCommand(pend); @@ -107,11 +108,10 @@ void RemoteClient::processServerIdentificationEvent(const Event_ServerIdentifica void RemoteClient::doLogin() { setStatus(StatusLoggingIn); - Command_Login cmdLogin; cmdLogin.set_user_name(userName.toStdString()); cmdLogin.set_password(password.toStdString()); - cmdLogin.set_clientid(settingsCache->getSrvClientID(lastHostname).toStdString()); + cmdLogin.set_clientid(getSrvClientID(lastHostname).toStdString()); cmdLogin.set_clientver(VERSION_STRING); if (!clientFeatures.isEmpty()) { @@ -361,3 +361,11 @@ void RemoteClient::disconnectFromServer() { emit sigDisconnectFromServer(); } + +QString RemoteClient::getSrvClientID(const QString _hostname) +{ + QString srvClientID = settingsCache->getClientID(); + srvClientID += _hostname; + QString uniqueServerClientID = QCryptographicHash::hash(srvClientID.toUtf8(), QCryptographicHash::Sha1).toHex().right(15); + return uniqueServerClientID; +} \ No newline at end of file diff --git a/cockatrice/src/remoteclient.h b/cockatrice/src/remoteclient.h index 3e0ae971..3b54cfda 100644 --- a/cockatrice/src/remoteclient.h +++ b/cockatrice/src/remoteclient.h @@ -51,6 +51,7 @@ private: QTcpSocket *socket; QString lastHostname; int lastPort; + QString getSrvClientID(const QString _hostname); protected slots: void sendCommandContainer(const CommandContainer &cont); public: diff --git a/cockatrice/src/settingscache.cpp b/cockatrice/src/settingscache.cpp index 1334e9ac..9d1f6625 100644 --- a/cockatrice/src/settingscache.cpp +++ b/cockatrice/src/settingscache.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #if QT_VERSION >= 0x050000 #include @@ -613,12 +612,4 @@ void SettingsCache::setNotifyAboutUpdate(int _notifyaboutupdate) { notifyAboutUpdates = _notifyaboutupdate; settings->setValue("personal/updatenotification", notifyAboutUpdates); -} - -QString SettingsCache::getSrvClientID(const QString _hostname) -{ - QString srvClientID = getClientID(); - srvClientID += _hostname; - QString uniqueServerClientID = QCryptographicHash::hash(srvClientID.toUtf8(), QCryptographicHash::Sha1).toHex().right(15); - return uniqueServerClientID; } \ No newline at end of file diff --git a/cockatrice/src/settingscache.h b/cockatrice/src/settingscache.h index cdeda46b..f9456162 100644 --- a/cockatrice/src/settingscache.h +++ b/cockatrice/src/settingscache.h @@ -176,8 +176,7 @@ public: bool getRememberGameSettings() const { return rememberGameSettings; } int getKeepAlive() const { return keepalive; } void setClientID(QString clientID); - QString getClientID() { return clientID; } - QString getSrvClientID(const QString _hostname); + QString getClientID() { return clientID; } ShortcutsSettings& shortcuts() const { return *shortcutsSettings; } CardDatabaseSettings& cardDatabase() const { return *cardDatabaseSettings; } ServersSettings& servers() const { return *serversSettings; } From 44123b9b0bd1fdc8e5f60d6e74ab9e1f0edf1eac Mon Sep 17 00:00:00 2001 From: woogerboy21 Date: Wed, 30 Mar 2016 15:30:58 -0400 Subject: [PATCH 3/3] Untabify Yay! Figured out how to do this in VS2015! --- cockatrice/src/remoteclient.cpp | 8 ++++---- cockatrice/src/remoteclient.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cockatrice/src/remoteclient.cpp b/cockatrice/src/remoteclient.cpp index e1bda71e..59b8e73b 100644 --- a/cockatrice/src/remoteclient.cpp +++ b/cockatrice/src/remoteclient.cpp @@ -364,8 +364,8 @@ void RemoteClient::disconnectFromServer() QString RemoteClient::getSrvClientID(const QString _hostname) { - QString srvClientID = settingsCache->getClientID(); - srvClientID += _hostname; - QString uniqueServerClientID = QCryptographicHash::hash(srvClientID.toUtf8(), QCryptographicHash::Sha1).toHex().right(15); - return uniqueServerClientID; + QString srvClientID = settingsCache->getClientID(); + srvClientID += _hostname; + QString uniqueServerClientID = QCryptographicHash::hash(srvClientID.toUtf8(), QCryptographicHash::Sha1).toHex().right(15); + return uniqueServerClientID; } \ No newline at end of file diff --git a/cockatrice/src/remoteclient.h b/cockatrice/src/remoteclient.h index 3b54cfda..ed0b66db 100644 --- a/cockatrice/src/remoteclient.h +++ b/cockatrice/src/remoteclient.h @@ -51,7 +51,7 @@ private: QTcpSocket *socket; QString lastHostname; int lastPort; - QString getSrvClientID(const QString _hostname); + QString getSrvClientID(const QString _hostname); protected slots: void sendCommandContainer(const CommandContainer &cont); public: