mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 16:44:48 -07:00
display reason for ban to banned user
This commit is contained in:
parent
6344b987de
commit
ff3eb9b5f4
19 changed files with 98 additions and 59 deletions
|
|
@ -36,7 +36,7 @@ class AbstractClient : public QObject {
|
|||
Q_OBJECT
|
||||
signals:
|
||||
void statusChanged(ClientStatus _status);
|
||||
void serverError(Response::ResponseCode resp);
|
||||
void serverError(Response::ResponseCode resp, QString reasonStr);
|
||||
|
||||
// Room events
|
||||
void roomEventReceived(const RoomEvent &event);
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class LocalServer : public Server
|
|||
public:
|
||||
LocalServer(QObject *parent = 0);
|
||||
~LocalServer();
|
||||
AuthenticationResult checkUserPassword(Server_ProtocolHandler * /*handler*/, const QString & /*user*/, const QString & /*password*/) { return UnknownUser; }
|
||||
AuthenticationResult checkUserPassword(Server_ProtocolHandler * /*handler*/, const QString & /*user*/, const QString & /*password*/, QString & /*reasonStr*/) { return UnknownUser; }
|
||||
QString getLoginMessage() const { return QString(); }
|
||||
bool getGameShouldPing() const { return false; }
|
||||
int getMaxGameInactivityTime() const { return 9999999; }
|
||||
|
|
|
|||
|
|
@ -56,8 +56,8 @@ void RemoteClient::processServerIdentificationEvent(const Event_ServerIdentifica
|
|||
|
||||
void RemoteClient::loginResponse(const Response &response)
|
||||
{
|
||||
const Response_Login &resp = response.GetExtension(Response_Login::ext);
|
||||
if (response.response_code() == Response::RespOk) {
|
||||
const Response_Login &resp = response.GetExtension(Response_Login::ext);
|
||||
setStatus(StatusLoggedIn);
|
||||
emit userInfoChanged(resp.user_info());
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ void RemoteClient::loginResponse(const Response &response)
|
|||
ignoreList.append(resp.ignore_list(i));
|
||||
emit ignoreListReceived(ignoreList);
|
||||
} else {
|
||||
emit serverError(response.response_code());
|
||||
emit serverError(response.response_code(), QString::fromStdString(resp.denied_reason_str()));
|
||||
setStatus(StatusDisconnecting);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,6 +81,9 @@ BanDialog::BanDialog(const ServerInfo_User &info, QWidget *parent)
|
|||
QLabel *reasonLabel = new QLabel(tr("Please enter the reason for the ban.\nThis is only saved for moderators and cannot be seen by the banned person."));
|
||||
reasonEdit = new QPlainTextEdit;
|
||||
|
||||
QLabel *visibleReasonLabel = new QLabel(tr("Please enter the reason for the ban that will be visible to the banned person."));
|
||||
visibleReasonEdit = new QPlainTextEdit;
|
||||
|
||||
QPushButton *okButton = new QPushButton(tr("&OK"));
|
||||
okButton->setAutoDefault(true);
|
||||
connect(okButton, SIGNAL(clicked()), this, SLOT(okClicked()));
|
||||
|
|
@ -97,6 +100,8 @@ BanDialog::BanDialog(const ServerInfo_User &info, QWidget *parent)
|
|||
vbox->addWidget(durationGroupBox);
|
||||
vbox->addWidget(reasonLabel);
|
||||
vbox->addWidget(reasonEdit);
|
||||
vbox->addWidget(visibleReasonLabel);
|
||||
vbox->addWidget(visibleReasonEdit);
|
||||
vbox->addLayout(buttonLayout);
|
||||
|
||||
setLayout(vbox);
|
||||
|
|
@ -142,6 +147,11 @@ QString BanDialog::getReason() const
|
|||
return reasonEdit->toPlainText();
|
||||
}
|
||||
|
||||
QString BanDialog::getVisibleReason() const
|
||||
{
|
||||
return visibleReasonEdit->toPlainText();
|
||||
}
|
||||
|
||||
UserListItemDelegate::UserListItemDelegate(QObject *const parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
{
|
||||
|
|
@ -344,6 +354,7 @@ void UserList::banUser_dialogFinished()
|
|||
cmd.set_address(dlg->getBanIP().toStdString());
|
||||
cmd.set_minutes(dlg->getMinutes());
|
||||
cmd.set_reason(dlg->getReason().toStdString());
|
||||
cmd.set_visible_reason(dlg->getVisibleReason().toStdString());
|
||||
|
||||
client->sendCommand(client->prepareModeratorCommand(cmd));
|
||||
}
|
||||
|
|
@ -418,7 +429,7 @@ void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index)
|
|||
cmd.set_user_name(userName.toStdString());
|
||||
|
||||
PendingCommand *pend = client->prepareSessionCommand(cmd);
|
||||
connect(pend, SIGNAL(finished(ProtocolResponse *)), this, SLOT(gamesOfUserReceived(ProtocolResponse *)));
|
||||
connect(pend, SIGNAL(finished(const Response &)), this, SLOT(gamesOfUserReceived(const Response &)));
|
||||
|
||||
client->sendCommand(pend);
|
||||
} else if (actionClicked == aAddToIgnoreList) {
|
||||
|
|
@ -438,7 +449,7 @@ void UserList::showContextMenu(const QPoint &pos, const QModelIndex &index)
|
|||
cmd.set_user_name(userName.toStdString());
|
||||
|
||||
PendingCommand *pend = client->prepareSessionCommand(cmd);
|
||||
connect(pend, SIGNAL(finished(ProtocolResponse *)), this, SLOT(banUser_processUserInfoResponse(ProtocolResponse *)));
|
||||
connect(pend, SIGNAL(finished(const Response &)), this, SLOT(banUser_processUserInfoResponse(const Response &)));
|
||||
|
||||
client->sendCommand(pend);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ private:
|
|||
QLineEdit *nameBanEdit, *ipBanEdit;
|
||||
QSpinBox *daysEdit, *hoursEdit, *minutesEdit;
|
||||
QRadioButton *permanentRadio, *temporaryRadio;
|
||||
QPlainTextEdit *reasonEdit;
|
||||
QPlainTextEdit *reasonEdit, *visibleReasonEdit;
|
||||
private slots:
|
||||
void okClicked();
|
||||
void enableTemporaryEdits(bool enabled);
|
||||
|
|
@ -35,6 +35,7 @@ public:
|
|||
QString getBanIP() const;
|
||||
int getMinutes() const;
|
||||
QString getReason() const;
|
||||
QString getVisibleReason() const;
|
||||
};
|
||||
|
||||
class UserListItemDelegate : public QStyledItemDelegate {
|
||||
|
|
|
|||
|
|
@ -53,17 +53,19 @@ void MainWindow::updateTabMenu(QMenu *menu)
|
|||
|
||||
void MainWindow::processConnectionClosedEvent(const Event_ConnectionClosed &event)
|
||||
{
|
||||
QString reason = QString::fromStdString(event.reason());
|
||||
client->disconnectFromServer();
|
||||
QString reasonStr;
|
||||
if (reason == "too_many_connections")
|
||||
reasonStr = tr("There are too many concurrent connections from your address.");
|
||||
else if (reason == "banned")
|
||||
reasonStr = tr("Banned by moderator.");
|
||||
else if (reason == "server_shutdown")
|
||||
reasonStr = tr("Scheduled server shutdown.");
|
||||
else
|
||||
reasonStr = tr("Unknown reason.");
|
||||
switch (event.reason()) {
|
||||
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_reason_str())
|
||||
reasonStr.append("\n\n" + QString::fromStdString(event.reason_str()));
|
||||
break;
|
||||
}
|
||||
case Event_ConnectionClosed::SERVER_SHUTDOWN: reasonStr = tr("Scheduled server shutdown."); break;
|
||||
default: reasonStr = QString::fromStdString(event.reason_str());
|
||||
}
|
||||
QMessageBox::critical(this, tr("Connection closed"), tr("The server has terminated your connection.\nReason: %1").arg(reasonStr));
|
||||
}
|
||||
|
||||
|
|
@ -201,11 +203,12 @@ void MainWindow::serverTimeout()
|
|||
QMessageBox::critical(this, tr("Error"), tr("Server timeout"));
|
||||
}
|
||||
|
||||
void MainWindow::serverError(Response::ResponseCode r)
|
||||
void MainWindow::serverError(Response::ResponseCode r, QString reasonStr)
|
||||
{
|
||||
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: ;
|
||||
}
|
||||
}
|
||||
|
|
@ -304,7 +307,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
client = new RemoteClient(this);
|
||||
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)), this, SLOT(serverError(Response::ResponseCode)));
|
||||
connect(client, SIGNAL(serverError(Response::ResponseCode, QString)), this, SLOT(serverError(Response::ResponseCode, QString)));
|
||||
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)));
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ private slots:
|
|||
void processConnectionClosedEvent(const Event_ConnectionClosed &event);
|
||||
void processServerShutdownEvent(const Event_ServerShutdown &event);
|
||||
void serverTimeout();
|
||||
void serverError(Response::ResponseCode r);
|
||||
void serverError(Response::ResponseCode r, QString reasonStr);
|
||||
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