Fix servatrice's regonly mode
This commit is contained in:
parent
faa66e4d7f
commit
15555c16fd
5 changed files with 12 additions and 5 deletions
|
@ -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
|
||||||
} 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 @@
|
||||||
#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:
|
||||||
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()
|
||||||
{
|
{
|
||||||
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)
|
||||||
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()) {
|
||||||
|
|
|
@ -50,7 +50,8 @@ public:
|
||||||
void lockSessionTables();
|
void lockSessionTables();
|
||||||
void unlockSessionTables();
|
void unlockSessionTables();
|
||||||
bool userSessionExists(const QString &userName);
|
bool userSessionExists(const QString &userName);
|
||||||
|
|
||||||
|
bool getRequireRegistration();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue