From 15555c16fd83f38201627ee6748b30971c4bb0f2 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Mon, 6 Oct 2014 22:56:09 +0200 Subject: [PATCH 1/2] Fix servatrice's regonly mode --- common/server.cpp | 4 +--- common/server_database_interface.h | 3 +++ servatrice/src/servatrice.cpp | 2 +- servatrice/src/servatrice_database_interface.cpp | 5 +++++ servatrice/src/servatrice_database_interface.h | 3 ++- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/common/server.cpp b/common/server.cpp index 6ab4750e..ff49a6dc 100644 --- a/common/server.cpp +++ b/common/server.cpp @@ -34,7 +34,6 @@ #include #include #include -#include Server::Server(bool _threaded, QObject *parent) : QObject(parent), threaded(_threaded), nextLocalGameId(0) @@ -132,8 +131,7 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString } else if (authState == UnknownUser) { // Change user name so that no two users have the same names, // don't interfere with registered user names though. - QSettings settings("servatrice.ini", QSettings::IniFormat); - bool requireReg = settings.value("authentication/regonly", 0).toBool(); + bool requireReg = databaseInterface->getRequireRegistration(); if (requireReg) { qDebug("Login denied: registration required"); databaseInterface->unlockSessionTables(); diff --git a/common/server_database_interface.h b/common/server_database_interface.h index 798ae9d9..a08e9526 100644 --- a/common/server_database_interface.h +++ b/common/server_database_interface.h @@ -2,6 +2,7 @@ #define SERVER_DATABASE_INTERFACE_H #include +#include #include "server.h" @@ -32,6 +33,8 @@ public: virtual void lockSessionTables() { } virtual void unlockSessionTables() { } virtual bool userSessionExists(const QString & /* userName */) { return false; } + + virtual bool getRequireRegistration() { return false; } }; #endif diff --git a/servatrice/src/servatrice.cpp b/servatrice/src/servatrice.cpp index c7abc432..a95b95a4 100644 --- a/servatrice/src/servatrice.cpp +++ b/servatrice/src/servatrice.cpp @@ -136,7 +136,7 @@ bool Servatrice::initServer() { serverName = settingsCache->value("server/name", "My Cockatrice server").toString(); serverId = settingsCache->value("server/id", 0).toInt(); - bool regServerOnly = settingsCache->value("server/regonly", 0).toBool(); + bool regServerOnly = settingsCache->value("authentication/regonly", 0).toBool(); const QString authenticationMethodStr = settingsCache->value("authentication/method").toString(); if (authenticationMethodStr == "sql") { diff --git a/servatrice/src/servatrice_database_interface.cpp b/servatrice/src/servatrice_database_interface.cpp index 2a97664b..a8c27e09 100644 --- a/servatrice/src/servatrice_database_interface.cpp +++ b/servatrice/src/servatrice_database_interface.cpp @@ -89,6 +89,11 @@ bool Servatrice_DatabaseInterface::usernameIsValid(const QString &user) return (result.size() > 0); } +bool Servatrice_DatabaseInterface::getRequireRegistration() +{ + return settingsCache->value("authentication/regonly", 0).toBool(); +} + AuthenticationResult Servatrice_DatabaseInterface::checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reasonStr, int &banSecondsLeft) { switch (server->getAuthenticationMethod()) { diff --git a/servatrice/src/servatrice_database_interface.h b/servatrice/src/servatrice_database_interface.h index e1d6d813..8e8ab5c6 100644 --- a/servatrice/src/servatrice_database_interface.h +++ b/servatrice/src/servatrice_database_interface.h @@ -50,7 +50,8 @@ public: void lockSessionTables(); void unlockSessionTables(); bool userSessionExists(const QString &userName); - + + bool getRequireRegistration(); }; #endif From 22af789c9e6d1110ab521a243a3a973d01e22169 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Tue, 7 Oct 2014 17:04:22 +0200 Subject: [PATCH 2/2] Servatrice: log to console authentication method on startup --- servatrice/src/servatrice.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/servatrice/src/servatrice.cpp b/servatrice/src/servatrice.cpp index a95b95a4..168c230c 100644 --- a/servatrice/src/servatrice.cpp +++ b/servatrice/src/servatrice.cpp @@ -140,14 +140,18 @@ bool Servatrice::initServer() const QString authenticationMethodStr = settingsCache->value("authentication/method").toString(); if (authenticationMethodStr == "sql") { + qDebug() << "Authenticating method: sql"; authenticationMethod = AuthenticationSql; } else if(authenticationMethodStr == "password") { + qDebug() << "Authenticating method: password"; authenticationMethod = AuthenticationPassword; } else { if (regServerOnly) { qDebug() << "Registration only server enabled but no authentication method defined: Error."; return false; } + + qDebug() << "Authenticating method: none"; authenticationMethod = AuthenticationNone; }