Commit 28ccec71 authored by woogerboy21's avatar woogerboy21
Browse files

Merge pull request #1101 from ctrlaltca/registration

[WIP] In-client Registration support
parents fab0a0ee 657a5164
......@@ -12,6 +12,7 @@ SET(cockatrice_SOURCES
src/dlg_connect.cpp
src/dlg_create_token.cpp
src/dlg_edit_tokens.cpp
src/dlg_register.cpp
src/abstractclient.cpp
src/remoteclient.cpp
src/main.cpp
......
......@@ -29,9 +29,10 @@ enum ClientStatus {
StatusDisconnected,
StatusDisconnecting,
StatusConnecting,
StatusAwaitingWelcome,
StatusRegistering,
StatusActivating,
StatusLoggingIn,
StatusLoggedIn
StatusLoggedIn,
};
class AbstractClient : public QObject {
......@@ -59,6 +60,9 @@ signals:
void buddyListReceived(const QList<ServerInfo_User> &buddyList);
void ignoreListReceived(const QList<ServerInfo_User> &ignoreList);
void replayAddedEventReceived(const Event_ReplayAdded &event);
void registerAccepted();
void registerAcceptedNeedsActivate();
void activateAccepted();
void sigQueuePendingCommand(PendingCommand *pend);
private:
......@@ -71,7 +75,8 @@ protected slots:
void processProtocolItem(const ServerMessage &item);
protected:
QMap<int, PendingCommand *> pendingCommands;
QString userName, password;
QString userName, password, email, country, realName, token;
int gender;
void setStatus(ClientStatus _status);
int getNewCmdId() { return nextCmdId++; }
virtual void sendCommandContainer(const CommandContainer &cont) = 0;
......
This diff is collapsed.
#ifndef DLG_REGISTER_H
#define DLG_REGISTER_H
#include <QDialog>
#include <QLineEdit>
#include <QComboBox>
class QLabel;
class QPushButton;
class QCheckBox;
class DlgRegister : public QDialog {
Q_OBJECT
public:
DlgRegister(QWidget *parent = 0);
QString getHost() const { return hostEdit->text(); }
int getPort() const { return portEdit->text().toInt(); }
QString getPlayerName() const { return playernameEdit->text(); }
QString getPassword() const { return passwordEdit->text(); }
QString getEmail() const { return emailEdit->text(); }
int getGender() const { return genderEdit->currentIndex() - 1; }
QString getCountry() const { return genderEdit->currentIndex() == 0 ? "" : countryEdit->currentText(); }
QString getRealName() const { return realnameEdit->text(); }
private slots:
void actOk();
void actCancel();
private:
QLabel *hostLabel, *portLabel, *playernameLabel, *passwordLabel, *emailLabel, *genderLabel, *countryLabel, *realnameLabel;
QLineEdit *hostEdit, *portEdit, *playernameEdit, *passwordEdit, *emailEdit, *realnameEdit;
QComboBox *genderEdit, *countryEdit;
};
#endif
......@@ -6,6 +6,8 @@
#include "pb/commands.pb.h"
#include "pb/session_commands.pb.h"
#include "pb/response_login.pb.h"
#include "pb/response_register.pb.h"
#include "pb/response_activate.pb.h"
#include "pb/server_message.pb.h"
#include "pb/event_server_identification.pb.h"
......@@ -28,6 +30,8 @@ RemoteClient::RemoteClient(QObject *parent)
connect(this, SIGNAL(connectionClosedEventReceived(Event_ConnectionClosed)), this, SLOT(processConnectionClosedEvent(Event_ConnectionClosed)));
connect(this, SIGNAL(sigConnectToServer(QString, unsigned int, QString, QString)), this, SLOT(doConnectToServer(QString, unsigned int, QString, QString)));
connect(this, SIGNAL(sigDisconnectFromServer()), this, SLOT(doDisconnectFromServer()));
connect(this, SIGNAL(sigRegisterToServer(QString, unsigned int, QString, QString, QString, int, QString, QString)), this, SLOT(doRegisterToServer(QString, unsigned int, QString, QString, QString, int, QString, QString)));
connect(this, SIGNAL(sigActivateToServer(QString)), this, SLOT(doActivateToServer(QString)));
}
RemoteClient::~RemoteClient()
......@@ -52,8 +56,6 @@ void RemoteClient::slotConnected()
sendCommandContainer(CommandContainer());
getNewCmdId();
// end of hack
setStatus(StatusAwaitingWelcome);
}
void RemoteClient::processServerIdentificationEvent(const Event_ServerIdentification &event)
......@@ -63,6 +65,42 @@ void RemoteClient::processServerIdentificationEvent(const Event_ServerIdentifica
setStatus(StatusDisconnecting);
return;
}
if(getStatus() == StatusRegistering)
{
Command_Register cmdRegister;
cmdRegister.set_user_name(userName.toStdString());
cmdRegister.set_password(password.toStdString());
cmdRegister.set_email(email.toStdString());
cmdRegister.set_gender((ServerInfo_User_Gender) gender);
cmdRegister.set_country(country.toStdString());
cmdRegister.set_real_name(realName.toStdString());
PendingCommand *pend = prepareSessionCommand(cmdRegister);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(registerResponse(Response)));
sendCommand(pend);
return;
}
if(getStatus() == StatusActivating)
{
Command_Activate cmdActivate;
cmdActivate.set_user_name(userName.toStdString());
cmdActivate.set_token(token.toStdString());
PendingCommand *pend = prepareSessionCommand(cmdActivate);
connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(activateResponse(Response)));
sendCommand(pend);
return;
}
doLogin();
}
void RemoteClient::doLogin()
{
setStatus(StatusLoggingIn);
Command_Login cmdLogin;
......@@ -101,6 +139,38 @@ void RemoteClient::loginResponse(const Response &response)
}
}
void RemoteClient::registerResponse(const Response &response)
{
const Response_Register &resp = response.GetExtension(Response_Register::ext);
switch(response.response_code())
{
case Response::RespRegistrationAccepted:
emit registerAccepted();
doLogin();
break;
case Response::RespRegistrationAcceptedNeedsActivation:
emit registerAcceptedNeedsActivate();
doLogin();
break;
default:
emit registerError(response.response_code(), QString::fromStdString(resp.denied_reason_str()), resp.denied_end_time());
setStatus(StatusDisconnecting);
doDisconnectFromServer();
break;
}
}
void RemoteClient::activateResponse(const Response &response)
{
if (response.response_code() == Response::RespActivationAccepted) {
emit activateAccepted();
doLogin();
} else {
emit activateError();
}
}
void RemoteClient::readData()
{
lastDataReceived = timeRunning;
......@@ -171,10 +241,40 @@ void RemoteClient::doConnectToServer(const QString &hostname, unsigned int port,
userName = _userName;
password = _password;
lastHostname = hostname;
lastPort = port;
socket->connectToHost(hostname, port);
setStatus(StatusConnecting);
}
void RemoteClient::doRegisterToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password, const QString &_email, const int _gender, const QString &_country, const QString &_realname)
{
doDisconnectFromServer();
userName = _userName;
password = _password;
email = _email;
gender = _gender;
country = _country;
realName = _realname;
lastHostname = hostname;
lastPort = port;
socket->connectToHost(hostname, port);
setStatus(StatusRegistering);
}
void RemoteClient::doActivateToServer(const QString &_token)
{
doDisconnectFromServer();
token = _token;
socket->connectToHost(lastHostname, lastPort);
setStatus(StatusActivating);
}
void RemoteClient::doDisconnectFromServer()
{
timer->stop();
......@@ -225,6 +325,16 @@ void RemoteClient::connectToServer(const QString &hostname, unsigned int port, c
emit sigConnectToServer(hostname, port, _userName, _password);
}
void RemoteClient::registerToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password, const QString &_email, const int _gender, const QString &_country, const QString &_realname)
{
emit sigRegisterToServer(hostname, port, _userName, _password, _email, _gender, _country, _realname);
}
void RemoteClient::activateToServer(const QString &_token)
{
emit sigActivateToServer(_token);
}
void RemoteClient::disconnectFromServer()
{
emit sigDisconnectFromServer();
......
......@@ -12,10 +12,14 @@ signals:
void maxPingTime(int seconds, int maxSeconds);
void serverTimeout();
void loginError(Response::ResponseCode resp, QString reasonStr, quint32 endTime);
void registerError(Response::ResponseCode resp, QString reasonStr, quint32 endTime);
void activateError();
void socketError(const QString &errorString);
void protocolVersionMismatch(int clientVersion, int serverVersion);
void protocolError();
void sigConnectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password);
void sigRegisterToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password, const QString &_email, const int _gender, const QString &_country, const QString &_realname);
void sigActivateToServer(const QString &_token);
void sigDisconnectFromServer();
private slots:
void slotConnected();
......@@ -25,8 +29,14 @@ private slots:
void processServerIdentificationEvent(const Event_ServerIdentification &event);
void processConnectionClosedEvent(const Event_ConnectionClosed &event);
void loginResponse(const Response &response);
void registerResponse(const Response &response);
void activateResponse(const Response &response);
void doConnectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password);
void doRegisterToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password, const QString &_email, const int _gender, const QString &_country, const QString &_realname);
void doLogin();
void doDisconnectFromServer();
void doActivateToServer(const QString &_token);
private:
static const int maxTimeout = 10;
int timeRunning, lastDataReceived;
......@@ -38,6 +48,8 @@ private:
QTimer *timer;
QTcpSocket *socket;
QString lastHostname;
int lastPort;
protected slots:
void sendCommandContainer(const CommandContainer &cont);
public:
......@@ -45,6 +57,8 @@ public:
~RemoteClient();
QString peerName() const { return socket->peerName(); }
void connectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password);
void registerToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password, const QString &_email, const int _gender, const QString &_country, const QString &_realname);
void activateToServer(const QString &_token);
void disconnectFromServer();
};
......
......@@ -34,6 +34,7 @@
#include "main.h"
#include "window_main.h"
#include "dlg_connect.h"
#include "dlg_register.h"
#include "dlg_settings.h"
#include "tab_supervisor.h"
#include "remoteclient.h"
......@@ -97,21 +98,22 @@ void MainWindow::statusChanged(ClientStatus _status)
{
setClientStatusTitle();
switch (_status) {
case StatusConnecting:
break;
case StatusDisconnected:
tabSupervisor->stop();
aSinglePlayer->setEnabled(true);
aConnect->setEnabled(true);
aRegister->setEnabled(true);
aDisconnect->setEnabled(false);
break;
case StatusLoggingIn:
aSinglePlayer->setEnabled(false);
aConnect->setEnabled(false);
aRegister->setEnabled(false);
aDisconnect->setEnabled(true);
break;
case StatusConnecting:
case StatusRegistering:
case StatusLoggedIn:
break;
default:
break;
}
......@@ -122,6 +124,21 @@ void MainWindow::userInfoReceived(const ServerInfo_User &info)
tabSupervisor->start(info);
}
void MainWindow::registerAccepted()
{
QMessageBox::information(this, tr("Success"), tr("Registration accepted.\nWill now login."));
}
void MainWindow::registerAcceptedNeedsActivate()
{
// nothing
}
void MainWindow::activateAccepted()
{
QMessageBox::information(this, tr("Success"), tr("Account activation accepted.\nWill now login."));
}
// Actions
void MainWindow::actConnect()
......@@ -131,6 +148,24 @@ void MainWindow::actConnect()
client->connectToServer(dlg.getHost(), dlg.getPort(), dlg.getPlayerName(), dlg.getPassword());
}
void MainWindow::actRegister()
{
DlgRegister dlg(this);
if (dlg.exec())
{
client->registerToServer(
dlg.getHost(),
dlg.getPort(),
dlg.getPlayerName(),
dlg.getPassword(),
dlg.getEmail(),
dlg.getGender(),
dlg.getCountry(),
dlg.getRealName()
);
}
}
void MainWindow::actDisconnect()
{
client->disconnectFromServer();
......@@ -144,6 +179,7 @@ void MainWindow::actSinglePlayer()
return;
aConnect->setEnabled(false);
aRegister->setEnabled(false);
aSinglePlayer->setEnabled(false);
localServer = new LocalServer(this);
......@@ -191,6 +227,7 @@ void MainWindow::localGameEnded()
localServer = 0;
aConnect->setEnabled(true);
aRegister->setEnabled(true);
aSinglePlayer->setEnabled(true);
}
......@@ -269,11 +306,74 @@ void MainWindow::loginError(Response::ResponseCode r, QString reasonStr, quint32
QMessageBox::critical(this, tr("Error"), tr("Invalid username.\nYou may only use A-Z, a-z, 0-9, _, ., and - in your username."));
break;
case Response::RespRegistrationRequired:
QMessageBox::critical(this, tr("Error"), tr("This server requires user registration."));
if (QMessageBox::question(this, tr("Error"), tr("This server requires user registration. Do you want to register now?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
actRegister();
}
break;
case Response::RespAccountNotActivated: {
bool ok = false;
QString token = QInputDialog::getText(this, tr("Account activation"), tr("Your account has not been activated yet.\n You need to provide the activation token received in the activation email"), QLineEdit::Normal, QString(), &ok);
if(ok && !token.isEmpty())
{
client->activateToServer(token);
return;
}
client->disconnectFromServer();
break;
}
default:
QMessageBox::critical(this, tr("Error"), tr("Unknown login error: %1").arg(static_cast<int>(r)));
break;
}
actConnect();
}
void MainWindow::registerError(Response::ResponseCode r, QString reasonStr, quint32 endTime)
{
switch (r) {
case Response::RespRegistrationDisabled:
QMessageBox::critical(this, tr("Registration denied"), tr("Registration is currently disabled on this server"));
break;
case Response::RespUserAlreadyExists:
QMessageBox::critical(this, tr("Registration denied"), tr("There is already an existing account with the same user name."));
break;
case Response::RespEmailRequiredToRegister:
QMessageBox::critical(this, tr("Registration denied"), tr("It's mandatory to specify a valid email address when registering."));
break;
case Response::RespTooManyRequests:
QMessageBox::critical(this, tr("Registration denied"), tr("Too many registration attempts from your IP address."));
break;
case Response::RespPasswordTooShort:
QMessageBox::critical(this, tr("Registration denied"), tr("Password too short."));
break;
case Response::RespUserIsBanned: {
QString bannedStr;
if (endTime)
bannedStr = tr("You are banned until %1.").arg(QDateTime::fromTime_t(endTime).toString());
else
bannedStr = tr("You are banned indefinitely.");
if (!reasonStr.isEmpty())
bannedStr.append("\n\n" + reasonStr);
QMessageBox::critical(this, tr("Error"), bannedStr);
break;
}
case Response::RespUsernameInvalid:
QMessageBox::critical(this, tr("Error"), tr("Invalid username.\nYou may only use A-Z, a-z, 0-9, _, ., and - in your username."));
break;
case Response::RespRegistrationFailed:
QMessageBox::critical(this, tr("Error"), tr("Registration failed for a technical problem on the server."));
break;
default:
QMessageBox::critical(this, tr("Error"), tr("Unknown login error: %1").arg(static_cast<int>(r)));
}
actRegister();
}
void MainWindow::activateError()
{
QMessageBox::critical(this, tr("Error"), tr("Account activation failed"));
client->disconnectFromServer();
actConnect();
}
......@@ -295,6 +395,7 @@ void MainWindow::setClientStatusTitle()
{
switch (client->getStatus()) {
case StatusConnecting: setWindowTitle(appName + " - " + tr("Connecting to %1...").arg(client->peerName())); break;
case StatusRegistering: setWindowTitle(appName + " - " + tr("Registering to %1 as %2...").arg(client->peerName()).arg(client->getUserName())); break;
case StatusDisconnected: setWindowTitle(appName + " - " + tr("Disconnected")); break;
case StatusLoggingIn: setWindowTitle(appName + " - " + tr("Connected, logging in at %1").arg(client->peerName())); break;
case StatusLoggedIn: setWindowTitle(appName + " - " + tr("Logged in as %1 at %2").arg(client->getUserName()).arg(client->peerName())); break;
......@@ -313,6 +414,7 @@ void MainWindow::retranslateUi()
aDeckEditor->setText(tr("&Deck editor"));
aFullScreen->setText(tr("&Full screen"));
aFullScreen->setShortcut(QKeySequence("Ctrl+F"));
aRegister->setText(tr("&Register to server..."));
aSettings->setText(tr("&Settings..."));
aExit->setText(tr("&Exit"));
......@@ -344,6 +446,8 @@ void MainWindow::createActions()
aFullScreen = new QAction(this);
aFullScreen->setCheckable(true);
connect(aFullScreen, SIGNAL(toggled(bool)), this, SLOT(actFullScreen(bool)));
aRegister = new QAction(this);
connect(aRegister, SIGNAL(triggered()), this, SLOT(actRegister()));
aSettings = new QAction(this);
connect(aSettings, SIGNAL(triggered()), this, SLOT(actSettings()));
aExit = new QAction(this);
......@@ -376,6 +480,7 @@ void MainWindow::createMenus()
cockatriceMenu = menuBar()->addMenu(QString());
cockatriceMenu->addAction(aConnect);
cockatriceMenu->addAction(aDisconnect);
cockatriceMenu->addAction(aRegister);
cockatriceMenu->addSeparator();
cockatriceMenu->addAction(aSinglePlayer);
cockatriceMenu->addAction(aWatchReplay);
......@@ -408,7 +513,13 @@ MainWindow::MainWindow(QWidget *parent)
connect(client, SIGNAL(statusChanged(ClientStatus)), this, SLOT(statusChanged(ClientStatus)));
connect(client, SIGNAL(protocolVersionMismatch(int, int)), this, SLOT(protocolVersionMismatch(int, int)));
connect(client, SIGNAL(userInfoChanged(const ServerInfo_User &)), this, SLOT(userInfoReceived(const ServerInfo_User &)), Qt::BlockingQueuedConnection);
connect(client, SIGNAL(registerAccepted()), this, SLOT(registerAccepted()));
connect(client, SIGNAL(registerAcceptedNeedsActivate()), this, SLOT(registerAcceptedNeedsActivate()));
connect(client, SIGNAL(registerError(Response::ResponseCode, QString, quint32)), this, SLOT(registerError(Response::ResponseCode, QString, quint32)));
connect(client, SIGNAL(activateAccepted()), this, SLOT(activateAccepted()));
connect(client, SIGNAL(activateError()), this, SLOT(activateError()));
clientThread = new QThread(this);
client->moveToThread(clientThread);
clientThread->start();
......
......@@ -43,9 +43,14 @@ private slots:
void processServerShutdownEvent(const Event_ServerShutdown &event);
void serverTimeout();
void loginError(Response::ResponseCode r, QString reasonStr, quint32 endTime);
void registerError(Response::ResponseCode r, QString reasonStr, quint32 endTime);
void activateError();
void socketError(const QString &errorStr);
void protocolVersionMismatch(int localVersion, int remoteVersion);
void userInfoReceived(const ServerInfo_User &userInfo);
void registerAccepted();
void registerAcceptedNeedsActivate();
void activateAccepted();
void localGameEnded();
void pixmapCacheSizeChanged(int newSizeInMBs);
......@@ -55,6 +60,7 @@ private slots:
void actWatchReplay();
void actDeckEditor();
void actFullScreen(bool checked);
void actRegister();
void actSettings();
void actExit();
......@@ -82,7 +88,7 @@ private:
QList<QMenu *> tabMenus;
QMenu *cockatriceMenu, *helpMenu;
QAction *aConnect, *aDisconnect, *aSinglePlayer, *aWatchReplay, *aDeckEditor, *aFullScreen, *aSettings, *aExit,
*aAbout, *aCheckCardUpdates;
*aAbout, *aCheckCardUpdates, *aRegister;
TabSupervisor *tabSupervisor;
QMenu *trayIconMenu;
......
......@@ -114,6 +114,7 @@ SET(PROTO_FILES
isl_message.proto
moderator_commands.proto
move_card_to_zone.proto
response_activate.proto
response_deck_download.proto
response_deck_list.proto
response_deck_upload.proto
......@@ -123,6 +124,7 @@ SET(PROTO_FILES
response_join_room.proto
response_list_users.proto
response_login.proto
response_register.proto
response_replay_download.proto
response_replay_list.proto
response.proto
......
......@@ -24,6 +24,17 @@ message Response {
RespAccessDenied = 20;
RespUsernameInvalid = 21;
RespRegistrationRequired = 22;
RespRegistrationAccepted = 23; // Server agrees to process client's registration request
RespUserAlreadyExists = 24; // Client attempted to register a name which is already registered
RespEmailRequiredToRegister = 25; // Server requires email to register accounts but client did not provide one
RespTooManyRequests = 26; // Server refused to complete command because client has sent too many too quickly
RespPasswordTooShort = 27; // Server requires a decent password
RespAccountNotActivated = 28; // Client attempted to log into a registered username but the account hasn't been activated
RespRegistrationDisabled = 29; // Server does not allow clients to register
RespRegistrationFailed = 30; // Server accepted a reg request but failed to perform the registration
RespActivationAccepted = 31; // Server accepted a reg user activation token
RespActivationFailed = 32; // Server didn't accept a reg user activation token
RespRegistrationAcceptedNeedsActivation = 33; // Server accepted cient registration, but it will need token activation
}
enum ResponseType {
JOIN_ROOM = 1000;
......@@ -35,6 +46,8 @@ message Response {
DECK_LIST = 1006;
DECK_DOWNLOAD = 1007;
DECK_UPLOAD = 1008;
REGISTER = 1009;
ACTIVATE = 1010;
REPLAY_LIST = 1100;
REPLAY_DOWNLOAD = 1101;
}
......
import "response.proto";
message Response_Activate {
extend Response {
optional Response_Activate ext = 1010;
}
}
\ No newline at end of file
import "response.proto";
message Response_Register {
extend Response {
optional Response_Register ext = 1009;
}
optional string denied_reason_str = 1;
optional uint64 denied_end_time = 2;
}
\ No newline at end of file
import "serverinfo_user.proto";
message SessionCommand {
enum SessionCommandType {
PING = 1000;
......@@ -16,6 +18,8 @@ message SessionCommand {
DECK_UPLOAD = 1013;
LIST_ROOMS = 1014;
JOIN_ROOM = 1015;
REGISTER = 1016;
ACTIVATE = 1017;
REPLAY_LIST = 1100;
REPLAY_DOWNLOAD = 1101;
REPLAY_MODIFY_MATCH = 1102;
......@@ -94,3 +98,32 @@ message Command_JoinRoom {
}
optional uint32 room_id = 1;
}
// User wants to register a new account
message Command_Register {
extend SessionCommand {
optional Command_Register ext = 1016;
}
// User name client wants to register
required string user_name = 1;
// Hashed password to be inserted into database
required string password = 2;
// Email address of the client for user validation
optional string email = 3;
// Gender of the user
optional ServerInfo_User.Gender gender = 4;
// Country code of the user. 2 letter ISO format
optional string country = 5;
optional string real_name = 6;
}
// User wants to activate an account
message Command_Activate {
extend SessionCommand {
optional Command_Activate ext = 1017;
}
// User name client wants to activate
required string user_name = 1;
// Activation token
required string token = 2;
}
......@@ -113,7 +113,7 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
QWriteLocker locker(&clientsLock);
AuthenticationResult authState = databaseInterface->checkUserPassword(session, name, password, reasonStr, secondsLeft);
if ((authState == NotLoggedIn) || (authState == UserIsBanned || authState == UsernameInvalid))
if (authState == NotLoggedIn || authState == UserIsBanned || authState == UsernameInvalid || authState == UserIsInactive)
return authState;
ServerInfo_User data = databaseInterface->getUserData(name, true);
......@@ -140,7 +140,7 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
QString tempName = name;
int i = 0;
while (users.contains(tempName) || databaseInterface->userExists(tempName) || databaseInterface->userSessionExists(tempName))
while (users.contains(tempName) || databaseInterface->activeUserExists(tempName) || databaseInterface->userSessionExists(tempName))
tempName = name + "_" + QString::number(++i);
name = tempName;
data.set_name(name.toStdString());
......
......@@ -7,6 +7,7 @@
#include <QMultiMap>
#include <QMutex>
#include <QReadWriteLock>
#include "pb/commands.pb.h"
#include "pb/serverinfo_user.pb.h"
#include "server_player_reference.h"
......@@ -27,7 +28,7 @@ class GameEventContainer;
class CommandContainer;
class Command_JoinGame;
enum AuthenticationResult { NotLoggedIn = 0, PasswordRight = 1, UnknownUser = 2, WouldOverwriteOldSession = 3, UserIsBanned = 4, UsernameInvalid = 5, RegistrationRequired = 6 };
enum AuthenticationResult { NotLoggedIn, PasswordRight, UnknownUser, WouldOverwriteOldSession, UserIsBanned, UsernameInvalid, RegistrationRequired, UserIsInactive };
class Server : public QObject
{
......@@ -44,6 +45,7 @@ public:
~Server();
void setThreaded(bool _threaded) { threaded = _threaded; }
AuthenticationResult loginUser(Server_ProtocolHandler *session, QString &name, const QString &password, QString &reason, int &secondsLeft);
const QMap<int, Server_Room *> &getRooms() { return rooms; }
Server_AbstractUserInterface *findUser(const QString &userName) const;
......
......@@ -13,6 +13,8 @@ public:
: QObject(parent) { }
virtual AuthenticationResult checkUserPassword(Server_ProtocolHandler *handler, const QString &user, const QString &password, QString &reasonStr, int &secondsLeft) = 0;
virtual bool checkUserIsBanned(const QString & /* ipAddress */, const QString & /* userName */, QString & /* banReason */, int & /* banSecondsRemaining */) { return false; }
virtual bool activeUserExists(const QString & /* user */) { return false; }
virtual bool userExists(const QString & /* user */) { return false; }
virtual QMap<QString, ServerInfo_User> getBuddyList(const QString & /* name */) { return QMap<QString, ServerInfo_User>(); }
virtual QMap<QString, ServerInfo_User> getIgnoreList(const QString & /* name */) { return QMap<QString, ServerInfo_User>(); }
......@@ -23,6 +25,7 @@ public:
virtual DeckList *getDeckFromDatabase(int /* deckId */, int /* userId */) { return 0; }
virtual qint64 startSession(const QString & /* userName */, const QString & /* address */) { return 0; }
virtual bool usernameIsValid(const QString & /*userName */) { return true; };
public slots:
virtual void endSession(qint64 /* sessionId */ ) { }
public:
......@@ -35,9 +38,12 @@ public:
virtual bool userSessionExists(const QString & /* userName */) { return false; }
virtual bool getRequireRegistration() { return false; }
virtual bool registerUser(const QString & /* userName */, const QString & /* realName */, ServerInfo_User_Gender const & /* gender */, const QString & /* password */, const QString & /* emailAddress */, const QString & /* country */, bool /* active = false */) { return false; }
virtual bool activateUser(const QString & /* userName */, const QString & /* token */) { return false; }
enum LogMessage_TargetType { MessageTargetRoom, MessageTargetGame, MessageTargetChat, MessageTargetIslRoom };
virtual void logMessage(const int /* senderId */, const QString & /* senderName */, const QString & /* senderIp */, const QString & /* logMessage */, LogMessage_TargetType /* targetType */, const int /* targetId */, const QString & /* targetName */) { };
bool checkUserIsBanned(Server_ProtocolHandler *session, QString &banReason, int &banSecondsRemaining);
};
#endif
......@@ -134,6 +134,10 @@ Response::ResponseCode Server_ProtocolHandler::processSessionCommandContainer(co
SessionCommand debugSc(sc);
debugSc.MutableExtension(Command_Login::ext)->clear_password();
logDebugMessage(QString::fromStdString(debugSc.ShortDebugString()));
} else if (num == SessionCommand::REGISTER) {
SessionCommand logSc(sc);
logSc.MutableExtension(Command_Register::ext)->clear_password();
logDebugMessage(QString::fromStdString(logSc.ShortDebugString()));
} else
logDebugMessage(QString::fromStdString(sc.ShortDebugString()));
}
......@@ -386,6 +390,7 @@ Response::ResponseCode Server_ProtocolHandler::cmdLogin(const Command_Login &cmd
case WouldOverwriteOldSession: return Response::RespWouldOverwriteOldSession;
case UsernameInvalid: return Response::RespUsernameInvalid;
case RegistrationRequired: return Response::RespRegistrationRequired;
case UserIsInactive: return Response::RespAccountNotActivated;
default: authState = res;
}
......
......@@ -28,6 +28,7 @@ class AdminCommand;
class Command_Ping;
class Command_Login;
class Command_Register;
class Command_Message;
class Command_ListUsers;
class Command_GetGamesOfUser;
......@@ -98,6 +99,7 @@ public:
void sendProtocolItem(const SessionEvent &item);
void sendProtocolItem(const GameEventContainer &item);
void sendProtocolItem(const RoomEvent &item);
};
#endif
......@@ -15,6 +15,18 @@ SET(servatrice_SOURCES
src/settingscache.cpp
src/isl_interface.cpp
${VERSION_STRING_CPP}
src/smtp/emailaddress.cpp
src/smtp/mimeattachment.cpp
src/smtp/mimecontentformatter.cpp
src/smtp/mimefile.cpp
src/smtp/mimehtml.cpp
src/smtp/mimeinlinefile.cpp
src/smtp/mimemessage.cpp
src/smtp/mimemultipart.cpp
src/smtp/mimepart.cpp
src/smtp/mimetext.cpp
src/smtp/quotedprintable.cpp
src/smtp/smtpclient.cpp
)
set(servatrice_RESOURCES servatrice.qrc)
......
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