mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 09:04:53 -07:00
show ban duration in client
This commit is contained in:
parent
78d188c462
commit
13b992cf12
15 changed files with 159 additions and 91 deletions
|
|
@ -38,7 +38,6 @@ class AbstractClient : public QObject {
|
|||
Q_OBJECT
|
||||
signals:
|
||||
void statusChanged(ClientStatus _status);
|
||||
void serverError(Response::ResponseCode resp, QString reasonStr);
|
||||
|
||||
// Room events
|
||||
void roomEventReceived(const RoomEvent &event);
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ RemoteClient::RemoteClient(QObject *parent)
|
|||
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slotSocketError(QAbstractSocket::SocketError)));
|
||||
|
||||
connect(this, SIGNAL(serverIdentificationEventReceived(const Event_ServerIdentification &)), this, SLOT(processServerIdentificationEvent(const Event_ServerIdentification &)));
|
||||
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()));
|
||||
}
|
||||
|
|
@ -66,6 +67,11 @@ void RemoteClient::processServerIdentificationEvent(const Event_ServerIdentifica
|
|||
sendCommand(pend);
|
||||
}
|
||||
|
||||
void RemoteClient::processConnectionClosedEvent(const Event_ConnectionClosed & /*event*/)
|
||||
{
|
||||
doDisconnectFromServer();
|
||||
}
|
||||
|
||||
void RemoteClient::loginResponse(const Response &response)
|
||||
{
|
||||
const Response_Login &resp = response.GetExtension(Response_Login::ext);
|
||||
|
|
@ -83,7 +89,7 @@ void RemoteClient::loginResponse(const Response &response)
|
|||
ignoreList.append(resp.ignore_list(i));
|
||||
emit ignoreListReceived(ignoreList);
|
||||
} else {
|
||||
emit serverError(response.response_code(), QString::fromStdString(resp.denied_reason_str()));
|
||||
emit loginError(response.response_code(), QString::fromStdString(resp.denied_reason_str()), resp.denied_end_time());
|
||||
setStatus(StatusDisconnecting);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ class RemoteClient : public AbstractClient {
|
|||
signals:
|
||||
void maxPingTime(int seconds, int maxSeconds);
|
||||
void serverTimeout();
|
||||
void loginError(Response::ResponseCode resp, QString reasonStr, quint32 endTime);
|
||||
void socketError(const QString &errorString);
|
||||
void protocolVersionMismatch(int clientVersion, int serverVersion);
|
||||
void protocolError();
|
||||
|
|
@ -22,6 +23,7 @@ private slots:
|
|||
void slotSocketError(QAbstractSocket::SocketError error);
|
||||
void ping();
|
||||
void processServerIdentificationEvent(const Event_ServerIdentification &event);
|
||||
void processConnectionClosedEvent(const Event_ConnectionClosed &event);
|
||||
void loginResponse(const Response &response);
|
||||
void doConnectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password);
|
||||
void doDisconnectFromServer();
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
#include <QFile>
|
||||
#include <QFileDialog>
|
||||
#include <QThread>
|
||||
#include <QDateTime>
|
||||
|
||||
#include "main.h"
|
||||
#include "window_main.h"
|
||||
|
|
@ -67,6 +68,10 @@ void MainWindow::processConnectionClosedEvent(const Event_ConnectionClosed &even
|
|||
case Event_ConnectionClosed::TOO_MANY_CONNECTIONS: reasonStr = tr("There are too many concurrent connections from your address."); break;
|
||||
case Event_ConnectionClosed::BANNED: {
|
||||
reasonStr = tr("Banned by moderator");
|
||||
if (event.has_end_time())
|
||||
reasonStr.append("\n" + tr("Expected end time: %1").arg(QDateTime::fromTime_t(event.end_time()).toString()));
|
||||
else
|
||||
reasonStr.append("\n" + tr("This ban lasts indefinitely."));
|
||||
if (event.has_reason_str())
|
||||
reasonStr.append("\n\n" + QString::fromStdString(event.reason_str()));
|
||||
break;
|
||||
|
|
@ -234,13 +239,29 @@ void MainWindow::serverTimeout()
|
|||
QMessageBox::critical(this, tr("Error"), tr("Server timeout"));
|
||||
}
|
||||
|
||||
void MainWindow::serverError(Response::ResponseCode r, QString reasonStr)
|
||||
void MainWindow::loginError(Response::ResponseCode r, QString reasonStr, quint32 endTime)
|
||||
{
|
||||
switch (r) {
|
||||
case Response::RespWrongPassword: QMessageBox::critical(this, tr("Error"), tr("Invalid login data.")); break;
|
||||
case Response::RespWouldOverwriteOldSession: QMessageBox::critical(this, tr("Error"), tr("There is already an active session using this user name.\nPlease close that session first and re-login.")); break;
|
||||
case Response::RespUserIsBanned: QMessageBox::critical(this, tr("Error"), tr("You are banned.\n%1").arg(reasonStr)); break;
|
||||
default: QMessageBox::critical(this, tr("Error"), tr("Unknown server error: %1").arg(static_cast<int>(r)));
|
||||
case Response::RespWrongPassword:
|
||||
QMessageBox::critical(this, tr("Error"), tr("Invalid login data."));
|
||||
break;
|
||||
case Response::RespWouldOverwriteOldSession:
|
||||
QMessageBox::critical(this, tr("Error"), tr("There is already an active session using this user name.\nPlease close that session first and re-login."));
|
||||
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;
|
||||
}
|
||||
default:
|
||||
QMessageBox::critical(this, tr("Error"), tr("Unknown login error: %1").arg(static_cast<int>(r)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -343,7 +364,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
client = new RemoteClient;
|
||||
connect(client, SIGNAL(connectionClosedEventReceived(const Event_ConnectionClosed &)), this, SLOT(processConnectionClosedEvent(const Event_ConnectionClosed &)));
|
||||
connect(client, SIGNAL(serverShutdownEventReceived(const Event_ServerShutdown &)), this, SLOT(processServerShutdownEvent(const Event_ServerShutdown &)));
|
||||
connect(client, SIGNAL(serverError(Response::ResponseCode, QString)), this, SLOT(serverError(Response::ResponseCode, QString)));
|
||||
connect(client, SIGNAL(loginError(Response::ResponseCode, QString, quint32)), this, SLOT(loginError(Response::ResponseCode, QString, quint32)));
|
||||
connect(client, SIGNAL(socketError(const QString &)), this, SLOT(socketError(const QString &)));
|
||||
connect(client, SIGNAL(serverTimeout()), this, SLOT(serverTimeout()));
|
||||
connect(client, SIGNAL(statusChanged(ClientStatus)), this, SLOT(statusChanged(ClientStatus)));
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ private slots:
|
|||
void processConnectionClosedEvent(const Event_ConnectionClosed &event);
|
||||
void processServerShutdownEvent(const Event_ServerShutdown &event);
|
||||
void serverTimeout();
|
||||
void serverError(Response::ResponseCode r, QString reasonStr);
|
||||
void loginError(Response::ResponseCode r, QString reasonStr, quint32 endTime);
|
||||
void socketError(const QString &errorStr);
|
||||
void protocolVersionMismatch(int localVersion, int remoteVersion);
|
||||
void userInfoReceived(const ServerInfo_User &userInfo);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue