Registered Only Server
Implemented the ability to set the server to only allow registered users. Also updated client to reflect the log-in rejection as well as put a check in place for the server to not start if db connection is not available yet registration is required.
This commit is contained in:
parent
fb4a7b3274
commit
d246fa39fe
7 changed files with 27 additions and 6 deletions
|
@ -1,4 +1,4 @@
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (C) 2008 by Max-Wilhelm Bruker *
|
* Copyright (C) 2008 by Max-Wilhelm Bruker *
|
||||||
* brukie@gmx.net *
|
* brukie@gmx.net *
|
||||||
* *
|
* *
|
||||||
|
@ -225,7 +225,7 @@ void MainWindow::actAbout()
|
||||||
+ tr("French:") + " Yannick Hammer, Arnaud Faes<br>"
|
+ tr("French:") + " Yannick Hammer, Arnaud Faes<br>"
|
||||||
+ tr("Japanese:") + " Nagase Task<br>"
|
+ tr("Japanese:") + " Nagase Task<br>"
|
||||||
+ tr("Russian:") + " Alexander Davidov<br>"
|
+ tr("Russian:") + " Alexander Davidov<br>"
|
||||||
// + tr("Czech:") + " Ondřej Trhoň<br>"
|
// + tr("Czech:") + " Ondrej Trhon<br>"
|
||||||
// + tr("Slovak:") + " Ganjalf Rendy<br>"
|
// + tr("Slovak:") + " Ganjalf Rendy<br>"
|
||||||
+ tr("Italian:") + " Luigi Sciolla<br>"
|
+ tr("Italian:") + " Luigi Sciolla<br>"
|
||||||
+ tr("Swedish:") + " Jessica Dahl<br>"
|
+ tr("Swedish:") + " Jessica Dahl<br>"
|
||||||
|
@ -261,6 +261,9 @@ void MainWindow::loginError(Response::ResponseCode r, QString reasonStr, quint32
|
||||||
case Response::RespUsernameInvalid:
|
case Response::RespUsernameInvalid:
|
||||||
QMessageBox::critical(this, tr("Error"), tr("Invalid username."));
|
QMessageBox::critical(this, tr("Error"), tr("Invalid username."));
|
||||||
break;
|
break;
|
||||||
|
case Response::RespRegistrationRequired:
|
||||||
|
QMessageBox::critical(this, tr("Error"), tr("This server requires user registration."));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
QMessageBox::critical(this, tr("Error"), tr("Unknown login error: %1").arg(static_cast<int>(r)));
|
QMessageBox::critical(this, tr("Error"), tr("Unknown login error: %1").arg(static_cast<int>(r)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ message Response {
|
||||||
RespUserIsBanned = 19;
|
RespUserIsBanned = 19;
|
||||||
RespAccessDenied = 20;
|
RespAccessDenied = 20;
|
||||||
RespUsernameInvalid = 21;
|
RespUsernameInvalid = 21;
|
||||||
|
RespRegistrationRequired = 22;
|
||||||
}
|
}
|
||||||
enum ResponseType {
|
enum ResponseType {
|
||||||
JOIN_ROOM = 1000;
|
JOIN_ROOM = 1000;
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#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)
|
||||||
|
@ -131,6 +132,14 @@ 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 = new QSettings("servatrice.ini", QSettings::IniFormat);
|
||||||
|
bool requireReg = settings->value("server/regonly").toBool();
|
||||||
|
if (requireReg) {
|
||||||
|
qDebug("Login denied: registration required");
|
||||||
|
databaseInterface->unlockSessionTables();
|
||||||
|
return RegistrationRequired;
|
||||||
|
}
|
||||||
|
|
||||||
QString tempName = name;
|
QString tempName = name;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (users.contains(tempName) || databaseInterface->userExists(tempName) || databaseInterface->userSessionExists(tempName))
|
while (users.contains(tempName) || databaseInterface->userExists(tempName) || databaseInterface->userSessionExists(tempName))
|
||||||
|
|
|
@ -27,7 +27,7 @@ class GameEventContainer;
|
||||||
class CommandContainer;
|
class CommandContainer;
|
||||||
class Command_JoinGame;
|
class Command_JoinGame;
|
||||||
|
|
||||||
enum AuthenticationResult { NotLoggedIn = 0, PasswordRight = 1, UnknownUser = 2, WouldOverwriteOldSession = 3, UserIsBanned = 4, UsernameInvalid = 5 };
|
enum AuthenticationResult { NotLoggedIn = 0, PasswordRight = 1, UnknownUser = 2, WouldOverwriteOldSession = 3, UserIsBanned = 4, UsernameInvalid = 5, RegistrationRequired = 6 };
|
||||||
|
|
||||||
class Server : public QObject
|
class Server : public QObject
|
||||||
{
|
{
|
||||||
|
|
|
@ -345,6 +345,7 @@ Response::ResponseCode Server_ProtocolHandler::cmdLogin(const Command_Login &cmd
|
||||||
case NotLoggedIn: return Response::RespWrongPassword;
|
case NotLoggedIn: return Response::RespWrongPassword;
|
||||||
case WouldOverwriteOldSession: return Response::RespWouldOverwriteOldSession;
|
case WouldOverwriteOldSession: return Response::RespWouldOverwriteOldSession;
|
||||||
case UsernameInvalid: return Response::RespUsernameInvalid;
|
case UsernameInvalid: return Response::RespUsernameInvalid;
|
||||||
|
case RegistrationRequired: return Response::RespRegistrationRequired;
|
||||||
default: authState = res;
|
default: authState = res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ id=1
|
||||||
number_pools=1
|
number_pools=1
|
||||||
writelog=1
|
writelog=1
|
||||||
logfilters=""
|
logfilters=""
|
||||||
|
regonly=0
|
||||||
|
|
||||||
[servernetwork]
|
[servernetwork]
|
||||||
active=0
|
active=0
|
||||||
|
|
|
@ -132,12 +132,18 @@ bool Servatrice::initServer()
|
||||||
{
|
{
|
||||||
serverName = settings->value("server/name").toString();
|
serverName = settings->value("server/name").toString();
|
||||||
serverId = settings->value("server/id", 0).toInt();
|
serverId = settings->value("server/id", 0).toInt();
|
||||||
|
bool regServerOnly = settings->value("server/regonly", 0).toBool();
|
||||||
|
|
||||||
const QString authenticationMethodStr = settings->value("authentication/method").toString();
|
const QString authenticationMethodStr = settings->value("authentication/method").toString();
|
||||||
if (authenticationMethodStr == "sql")
|
if (authenticationMethodStr == "sql") {
|
||||||
authenticationMethod = AuthenticationSql;
|
authenticationMethod = AuthenticationSql;
|
||||||
else
|
} else {
|
||||||
|
if (regServerOnly) {
|
||||||
|
qDebug() << "Registration only server enabled but no DB Connection : Error.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
authenticationMethod = AuthenticationNone;
|
authenticationMethod = AuthenticationNone;
|
||||||
|
}
|
||||||
|
|
||||||
QString dbTypeStr = settings->value("database/type").toString();
|
QString dbTypeStr = settings->value("database/type").toString();
|
||||||
if (dbTypeStr == "mysql")
|
if (dbTypeStr == "mysql")
|
||||||
|
|
Loading…
Reference in a new issue