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

Fix servatrice's regonly mode

parent faa66e4d
......@@ -34,7 +34,6 @@
#include <QCoreApplication>
#include <QThread>
#include <QDebug>
#include <QSettings>
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();
......
......@@ -2,6 +2,7 @@
#define SERVER_DATABASE_INTERFACE_H
#include <QObject>
#include <QSettings>
#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
......@@ -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") {
......
......@@ -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()) {
......
......@@ -50,7 +50,8 @@ public:
void lockSessionTables();
void unlockSessionTables();
bool userSessionExists(const QString &userName);
bool getRequireRegistration();
};
#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