mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 17:14:52 -07:00
Merge pull request #179 from woogerboy21/registered-user-only-server
Registered Only Server
This commit is contained in:
commit
5c46cfc169
7 changed files with 319 additions and 300 deletions
|
|
@ -23,6 +23,7 @@ message Response {
|
|||
RespUserIsBanned = 19;
|
||||
RespAccessDenied = 20;
|
||||
RespUsernameInvalid = 21;
|
||||
RespRegistrationRequired = 22;
|
||||
}
|
||||
enum ResponseType {
|
||||
JOIN_ROOM = 1000;
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@
|
|||
#include <QCoreApplication>
|
||||
#include <QThread>
|
||||
#include <QDebug>
|
||||
#include <QSettings>
|
||||
|
||||
Server::Server(bool _threaded, QObject *parent)
|
||||
: QObject(parent), threaded(_threaded), nextLocalGameId(0)
|
||||
|
|
@ -131,6 +132,14 @@ 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();
|
||||
if (requireReg) {
|
||||
qDebug("Login denied: registration required");
|
||||
databaseInterface->unlockSessionTables();
|
||||
return RegistrationRequired;
|
||||
}
|
||||
|
||||
QString tempName = name;
|
||||
int i = 0;
|
||||
while (users.contains(tempName) || databaseInterface->userExists(tempName) || databaseInterface->userSessionExists(tempName))
|
||||
|
|
@ -142,7 +151,7 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
|
|||
users.insert(name, session);
|
||||
qDebug() << "Server::loginUser:" << session << "name=" << name;
|
||||
|
||||
data.set_session_id(databaseInterface->startSession(name, session->getAddress()));
|
||||
data.set_session_id(databaseInterface->startSession(name, session->getAddress()));
|
||||
databaseInterface->unlockSessionTables();
|
||||
|
||||
usersBySessionId.insert(data.session_id(), session);
|
||||
|
|
@ -478,7 +487,7 @@ void Server::broadcastRoomUpdate(const ServerInfo_Room &roomInfo, bool sendToIsl
|
|||
|
||||
clientsLock.lockForRead();
|
||||
for (int i = 0; i < clients.size(); ++i)
|
||||
if (clients[i]->getAcceptsRoomListChanges())
|
||||
if (clients[i]->getAcceptsRoomListChanges())
|
||||
clients[i]->sendProtocolItem(*se);
|
||||
clientsLock.unlock();
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class GameEventContainer;
|
|||
class CommandContainer;
|
||||
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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -345,6 +345,7 @@ Response::ResponseCode Server_ProtocolHandler::cmdLogin(const Command_Login &cmd
|
|||
case NotLoggedIn: return Response::RespWrongPassword;
|
||||
case WouldOverwriteOldSession: return Response::RespWouldOverwriteOldSession;
|
||||
case UsernameInvalid: return Response::RespUsernameInvalid;
|
||||
case RegistrationRequired: return Response::RespRegistrationRequired;
|
||||
default: authState = res;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue