diff --git a/cockatrice/src/main.cpp b/cockatrice/src/main.cpp index b73091a8..cdeee600 100644 --- a/cockatrice/src/main.cpp +++ b/cockatrice/src/main.cpp @@ -35,7 +35,6 @@ #include "QtNetwork/QNetworkInterface" #include - #include "main.h" #include "window_main.h" #include "dlg_settings.h" @@ -100,7 +99,7 @@ bool settingsValid() !settingsCache->getPicsPath().isEmpty(); } -void generateClientID() +QString const generateClientID() { QString macList; foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces()) @@ -110,7 +109,7 @@ void generateClientID() macList += interface.hardwareAddress() + "."; } QString strClientID = QCryptographicHash::hash(macList.toUtf8(), QCryptographicHash::Sha1).toHex().right(15); - settingsCache->setClientID(strClientID); + return strClientID; } int main(int argc, char *argv[]) @@ -220,7 +219,7 @@ int main(int argc, char *argv[]) QIcon icon(":/resources/appicon.svg"); ui.setWindowIcon(icon); - generateClientID(); //generate the users client id + settingsCache->setClientID(generateClientID()); qDebug() << "ClientID In Cache: " << settingsCache->getClientID(); ui.showMaximized(); diff --git a/cockatrice/src/main.h b/cockatrice/src/main.h index 3ecb71fd..71feb9a7 100644 --- a/cockatrice/src/main.h +++ b/cockatrice/src/main.h @@ -7,14 +7,14 @@ class QSystemTrayIcon; class SoundEngine; extern CardDatabase *db; - extern QSystemTrayIcon *trayIcon; extern QTranslator *translator; extern const QString translationPrefix; extern QString translationPath; void installNewTranslator(); -void generateClientID(); + +QString const generateClientID(); bool settingsValid(); diff --git a/common/pb/response.proto b/common/pb/response.proto index 09a68275..cc1948be 100644 --- a/common/pb/response.proto +++ b/common/pb/response.proto @@ -35,7 +35,7 @@ message Response { RespActivationAccepted = 31; // Server accepted a reg user activation token RespActivationFailed = 32; // Server didn't accept a reg user activation token RespRegistrationAcceptedNeedsActivation = 33; // Server accepted cient registration, but it will need token activation - RespClientIDRequired = 34; // Server require's client to generate and send its client id before allowing access + RespClientIDRequired = 34; // Server requires client to generate and send its client id before allowing access } enum ResponseType { JOIN_ROOM = 1000; diff --git a/common/server.cpp b/common/server.cpp index ce9e9abd..0fef1dc6 100644 --- a/common/server.cpp +++ b/common/server.cpp @@ -170,7 +170,6 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString event.mutable_user_info()->CopyFrom(session->copyUserInfo(true, true, true)); locker.unlock(); - // check if client id exists (older client compatibility) if (clientid.isEmpty()){ // client id is empty, either out dated client or client has been modified } diff --git a/common/server_protocolhandler.cpp b/common/server_protocolhandler.cpp index 70cb2126..e87fd8fb 100644 --- a/common/server_protocolhandler.cpp +++ b/common/server_protocolhandler.cpp @@ -381,12 +381,16 @@ Response::ResponseCode Server_ProtocolHandler::cmdPing(const Command_Ping & /*cm Response::ResponseCode Server_ProtocolHandler::cmdLogin(const Command_Login &cmd, ResponseContainer &rc) { QString userName = QString::fromStdString(cmd.user_name()).simplified(); - QString clientid = QString::fromStdString(cmd.clientid()).simplified(); + QString clientId = QString::fromStdString(cmd.clientid()).simplified(); + if (userName.isEmpty() || (userInfo != 0)) return Response::RespContextError; + if (clientId.isEmpty()) + return Response::RespContextError; + QString reasonStr; int banSecondsLeft = 0; - AuthenticationResult res = server->loginUser(this, userName, QString::fromStdString(cmd.password()), reasonStr, banSecondsLeft, clientid); + AuthenticationResult res = server->loginUser(this, userName, QString::fromStdString(cmd.password()), reasonStr, banSecondsLeft, clientId); switch (res) { case UserIsBanned: { Response_Login *re = new Response_Login;