Commit 15555c16 authored by Fabio Bas's avatar Fabio Bas
Browse files

Fix servatrice's regonly mode

parent faa66e4d
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <QThread> #include <QThread>
#include <QDebug> #include <QDebug>
#include <QSettings>
Server::Server(bool _threaded, QObject *parent) Server::Server(bool _threaded, QObject *parent)
: QObject(parent), threaded(_threaded), nextLocalGameId(0) : QObject(parent), threaded(_threaded), nextLocalGameId(0)
...@@ -132,8 +131,7 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString ...@@ -132,8 +131,7 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
} else if (authState == UnknownUser) { } else if (authState == UnknownUser) {
// Change user name so that no two users have the same names, // Change user name so that no two users have the same names,
// don't interfere with registered user names though. // don't interfere with registered user names though.
QSettings settings("servatrice.ini", QSettings::IniFormat); bool requireReg = databaseInterface->getRequireRegistration();
bool requireReg = settings.value("authentication/regonly", 0).toBool();
if (requireReg) { if (requireReg) {
qDebug("Login denied: registration required"); qDebug("Login denied: registration required");
databaseInterface->unlockSessionTables(); databaseInterface->unlockSessionTables();
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define SERVER_DATABASE_INTERFACE_H #define SERVER_DATABASE_INTERFACE_H
#include <QObject> #include <QObject>
#include <QSettings>
#include "server.h" #include "server.h"
...@@ -32,6 +33,8 @@ public: ...@@ -32,6 +33,8 @@ public:
virtual void lockSessionTables() { } virtual void lockSessionTables() { }
virtual void unlockSessionTables() { } virtual void unlockSessionTables() { }
virtual bool userSessionExists(const QString & /* userName */) { return false; } virtual bool userSessionExists(const QString & /* userName */) { return false; }
virtual bool getRequireRegistration() { return false; }
}; };
#endif #endif
...@@ -136,7 +136,7 @@ bool Servatrice::initServer() ...@@ -136,7 +136,7 @@ bool Servatrice::initServer()
{ {
serverName = settingsCache->value("server/name", "My Cockatrice server").toString(); serverName = settingsCache->value("server/name", "My Cockatrice server").toString();
serverId = settingsCache->value("server/id", 0).toInt(); 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(); const QString authenticationMethodStr = settingsCache->value("authentication/method").toString();
if (authenticationMethodStr == "sql") { if (authenticationMethodStr == "sql") {
......
...@@ -89,6 +89,11 @@ bool Servatrice_DatabaseInterface::usernameIsValid(const QString &user) ...@@ -89,6 +89,11 @@ bool Servatrice_DatabaseInterface::usernameIsValid(const QString &user)
return (result.size() > 0); 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) AuthenticationResult Servatrice_DatabaseInterface::checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reasonStr, int &banSecondsLeft)
{ {
switch (server->getAuthenticationMethod()) { switch (server->getAuthenticationMethod()) {
......
...@@ -51,6 +51,7 @@ public: ...@@ -51,6 +51,7 @@ public:
void unlockSessionTables(); void unlockSessionTables();
bool userSessionExists(const QString &userName); bool userSessionExists(const QString &userName);
bool getRequireRegistration();
}; };
#endif #endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment