mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 00:04:48 -07:00
Merge pull request #1101 from ctrlaltca/registration
[WIP] In-client Registration support
This commit is contained in:
commit
28ccec711e
54 changed files with 3669 additions and 66 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue