mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-05 04:53:54 -07:00
server shutdown function
This commit is contained in:
parent
5e3db65846
commit
a4c3d48389
33 changed files with 1410 additions and 604 deletions
|
|
@ -32,15 +32,16 @@ void AbstractClient::processProtocolItem(ProtocolItem *item)
|
|||
GenericEvent *genericEvent = qobject_cast<GenericEvent *>(item);
|
||||
if (genericEvent) {
|
||||
switch (genericEvent->getItemId()) {
|
||||
case ItemId_Event_ConnectionClosed: emit connectionClosedEventReceived(qobject_cast<Event_ConnectionClosed *>(item)); break;
|
||||
case ItemId_Event_AddToList: emit addToListEventReceived(qobject_cast<Event_AddToList *>(item)); break;
|
||||
case ItemId_Event_RemoveFromList: emit removeFromListEventReceived(qobject_cast<Event_RemoveFromList *>(item)); break;
|
||||
case ItemId_Event_UserJoined: emit userJoinedEventReceived(qobject_cast<Event_UserJoined *>(item)); break;
|
||||
case ItemId_Event_UserLeft: emit userLeftEventReceived(qobject_cast<Event_UserLeft *>(item)); break;
|
||||
case ItemId_Event_ServerMessage: emit serverMessageEventReceived(qobject_cast<Event_ServerMessage *>(item)); break;
|
||||
case ItemId_Event_ListRooms: emit listRoomsEventReceived(qobject_cast<Event_ListRooms *>(item)); break;
|
||||
case ItemId_Event_GameJoined: emit gameJoinedEventReceived(qobject_cast<Event_GameJoined *>(item)); break;
|
||||
case ItemId_Event_Message: emit messageEventReceived(qobject_cast<Event_Message *>(item)); break;
|
||||
case ItemId_Event_ConnectionClosed: emit connectionClosedEventReceived(static_cast<Event_ConnectionClosed *>(item)); break;
|
||||
case ItemId_Event_ServerShutdown: emit serverShutdownEventReceived(static_cast<Event_ServerShutdown *>(item)); break;
|
||||
case ItemId_Event_AddToList: emit addToListEventReceived(static_cast<Event_AddToList *>(item)); break;
|
||||
case ItemId_Event_RemoveFromList: emit removeFromListEventReceived(static_cast<Event_RemoveFromList *>(item)); break;
|
||||
case ItemId_Event_UserJoined: emit userJoinedEventReceived(static_cast<Event_UserJoined *>(item)); break;
|
||||
case ItemId_Event_UserLeft: emit userLeftEventReceived(static_cast<Event_UserLeft *>(item)); break;
|
||||
case ItemId_Event_ServerMessage: emit serverMessageEventReceived(static_cast<Event_ServerMessage *>(item)); break;
|
||||
case ItemId_Event_ListRooms: emit listRoomsEventReceived(static_cast<Event_ListRooms *>(item)); break;
|
||||
case ItemId_Event_GameJoined: emit gameJoinedEventReceived(static_cast<Event_GameJoined *>(item)); break;
|
||||
case ItemId_Event_Message: emit messageEventReceived(static_cast<Event_Message *>(item)); break;
|
||||
}
|
||||
if (genericEvent->getReceiverMayDelete())
|
||||
delete genericEvent;
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ class Event_ListRooms;
|
|||
class Event_GameJoined;
|
||||
class Event_Message;
|
||||
class Event_ConnectionClosed;
|
||||
class Event_ServerShutdown;
|
||||
|
||||
enum ClientStatus {
|
||||
StatusDisconnected,
|
||||
|
|
@ -43,6 +44,7 @@ signals:
|
|||
void gameEventContainerReceived(GameEventContainer *event);
|
||||
// Generic events
|
||||
void connectionClosedEventReceived(Event_ConnectionClosed *event);
|
||||
void serverShutdownEventReceived(Event_ServerShutdown *event);
|
||||
void addToListEventReceived(Event_AddToList *event);
|
||||
void removeFromListEventReceived(Event_RemoveFromList *event);
|
||||
void userJoinedEventReceived(Event_UserJoined *event);
|
||||
|
|
|
|||
|
|
@ -18,8 +18,9 @@ private:
|
|||
ResponseCode cmdDeckDel(Command_DeckDel * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
|
||||
ResponseCode cmdDeckUpload(Command_DeckUpload * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
|
||||
ResponseCode cmdDeckDownload(Command_DeckDownload * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
|
||||
ResponseCode cmdUpdateServerMessage(Command_UpdateServerMessage * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
|
||||
ResponseCode cmdBanFromServer(Command_BanFromServer * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
|
||||
ResponseCode cmdShutdownServer(Command_ShutdownServer * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
|
||||
ResponseCode cmdUpdateServerMessage(Command_UpdateServerMessage * /*cmd*/, CommandContainer * /*cont*/) { return RespFunctionNotAllowed; }
|
||||
public:
|
||||
LocalServerInterface(LocalServer *_server);
|
||||
~LocalServerInterface();
|
||||
|
|
|
|||
|
|
@ -1,19 +1,72 @@
|
|||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QGridLayout>
|
||||
#include <QPushButton>
|
||||
#include <QGroupBox>
|
||||
#include <QMessageBox>
|
||||
#include <QSpinBox>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include "tab_admin.h"
|
||||
#include "abstractclient.h"
|
||||
#include "protocol_items.h"
|
||||
|
||||
TabAdmin::TabAdmin(TabSupervisor *_tabSupervisor, AbstractClient *_client, QWidget *parent)
|
||||
: Tab(_tabSupervisor, parent), locked(true), client(_client)
|
||||
ShutdownDialog::ShutdownDialog(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
QLabel *reasonLabel = new QLabel(tr("&Reason for shutdown:"));
|
||||
reasonEdit = new QLineEdit;
|
||||
reasonLabel->setBuddy(reasonEdit);
|
||||
QLabel *minutesLabel = new QLabel(tr("&Time until shutdown (minutes):"));
|
||||
minutesEdit = new QSpinBox;
|
||||
minutesLabel->setBuddy(minutesEdit);
|
||||
minutesEdit->setMinimum(0);
|
||||
minutesEdit->setValue(5);
|
||||
|
||||
QPushButton *okButton = new QPushButton(tr("&OK"));
|
||||
okButton->setAutoDefault(true);
|
||||
okButton->setDefault(true);
|
||||
connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
|
||||
QPushButton *cancelButton = new QPushButton(tr("&Cancel"));
|
||||
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
|
||||
|
||||
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
||||
buttonLayout->addStretch();
|
||||
buttonLayout->addWidget(okButton);
|
||||
buttonLayout->addWidget(cancelButton);
|
||||
|
||||
QGridLayout *mainLayout = new QGridLayout;
|
||||
mainLayout->addWidget(reasonLabel, 0, 0);
|
||||
mainLayout->addWidget(reasonEdit, 0, 1);
|
||||
mainLayout->addWidget(minutesLabel, 1, 0);
|
||||
mainLayout->addWidget(minutesEdit, 1, 1);
|
||||
mainLayout->addLayout(buttonLayout, 2, 0, 1, 2);
|
||||
|
||||
setLayout(mainLayout);
|
||||
setWindowTitle(tr("Shut down server"));
|
||||
}
|
||||
|
||||
QString ShutdownDialog::getReason() const
|
||||
{
|
||||
return reasonEdit->text();
|
||||
}
|
||||
|
||||
int ShutdownDialog::getMinutes() const
|
||||
{
|
||||
return minutesEdit->value();
|
||||
}
|
||||
|
||||
TabAdmin::TabAdmin(TabSupervisor *_tabSupervisor, AbstractClient *_client, bool _fullAdmin, QWidget *parent)
|
||||
: Tab(_tabSupervisor, parent), locked(true), client(_client), fullAdmin(_fullAdmin)
|
||||
{
|
||||
updateServerMessageButton = new QPushButton;
|
||||
connect(updateServerMessageButton, SIGNAL(clicked()), this, SLOT(actUpdateServerMessage()));
|
||||
shutdownServerButton = new QPushButton;
|
||||
connect(shutdownServerButton, SIGNAL(clicked()), this, SLOT(actShutdownServer()));
|
||||
|
||||
QVBoxLayout *vbox = new QVBoxLayout;
|
||||
vbox->addWidget(updateServerMessageButton);
|
||||
vbox->addWidget(shutdownServerButton);
|
||||
vbox->addStretch();
|
||||
|
||||
adminGroupBox = new QGroupBox;
|
||||
|
|
@ -38,6 +91,7 @@ TabAdmin::TabAdmin(TabSupervisor *_tabSupervisor, AbstractClient *_client, QWidg
|
|||
void TabAdmin::retranslateUi()
|
||||
{
|
||||
updateServerMessageButton->setText(tr("Update server &message"));
|
||||
shutdownServerButton->setText(tr("&Shut down server"));
|
||||
adminGroupBox->setTitle(tr("Server administration functions"));
|
||||
|
||||
unlockButton->setText(tr("&Unlock functions"));
|
||||
|
|
@ -49,10 +103,18 @@ void TabAdmin::actUpdateServerMessage()
|
|||
client->sendCommand(new Command_UpdateServerMessage());
|
||||
}
|
||||
|
||||
void TabAdmin::actShutdownServer()
|
||||
{
|
||||
ShutdownDialog dlg;
|
||||
if (dlg.exec())
|
||||
client->sendCommand(new Command_ShutdownServer(dlg.getReason(), dlg.getMinutes()));
|
||||
}
|
||||
|
||||
void TabAdmin::actUnlock()
|
||||
{
|
||||
if (QMessageBox::question(this, tr("Unlock administration functions"), tr("Do you really want to unlock the administration functions?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
|
||||
adminGroupBox->setEnabled(true);
|
||||
if (fullAdmin)
|
||||
adminGroupBox->setEnabled(true);
|
||||
lockButton->setEnabled(true);
|
||||
unlockButton->setEnabled(false);
|
||||
locked = false;
|
||||
|
|
@ -61,7 +123,8 @@ void TabAdmin::actUnlock()
|
|||
|
||||
void TabAdmin::actLock()
|
||||
{
|
||||
adminGroupBox->setEnabled(false);
|
||||
if (fullAdmin)
|
||||
adminGroupBox->setEnabled(false);
|
||||
lockButton->setEnabled(false);
|
||||
unlockButton->setEnabled(true);
|
||||
locked = true;
|
||||
|
|
|
|||
|
|
@ -2,27 +2,43 @@
|
|||
#define TAB_ADMIN_H
|
||||
|
||||
#include "tab.h"
|
||||
#include <QDialog>
|
||||
|
||||
class AbstractClient;
|
||||
|
||||
class QGroupBox;
|
||||
class QPushButton;
|
||||
class QSpinBox;
|
||||
class QLineEdit;
|
||||
|
||||
class ShutdownDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
private:
|
||||
QLineEdit *reasonEdit;
|
||||
QSpinBox *minutesEdit;
|
||||
public:
|
||||
ShutdownDialog(QWidget *parent = 0);
|
||||
QString getReason() const;
|
||||
int getMinutes() const;
|
||||
};
|
||||
|
||||
class TabAdmin : public Tab {
|
||||
Q_OBJECT
|
||||
private:
|
||||
bool locked;
|
||||
AbstractClient *client;
|
||||
QPushButton *updateServerMessageButton;
|
||||
bool fullAdmin;
|
||||
QPushButton *updateServerMessageButton, *shutdownServerButton;
|
||||
QGroupBox *adminGroupBox;
|
||||
QPushButton *unlockButton, *lockButton;
|
||||
private slots:
|
||||
void actUpdateServerMessage();
|
||||
void actShutdownServer();
|
||||
|
||||
void actUnlock();
|
||||
void actLock();
|
||||
public:
|
||||
TabAdmin(TabSupervisor *_tabSupervisor, AbstractClient *_client, QWidget *parent = 0);
|
||||
TabAdmin(TabSupervisor *_tabSupervisor, AbstractClient *_client, bool _fullAdmin, QWidget *parent = 0);
|
||||
void retranslateUi();
|
||||
QString getTabText() const { return tr("Administration"); }
|
||||
bool getLocked() const { return locked; }
|
||||
|
|
|
|||
|
|
@ -135,8 +135,8 @@ void TabSupervisor::start(AbstractClient *_client, ServerInfo_User *userInfo)
|
|||
} else
|
||||
tabDeckStorage = 0;
|
||||
|
||||
if (userInfo->getUserLevel() & ServerInfo_User::IsAdmin) {
|
||||
tabAdmin = new TabAdmin(this, client);
|
||||
if (userInfo->getUserLevel() & ServerInfo_User::IsModerator) {
|
||||
tabAdmin = new TabAdmin(this, client, (userInfo->getUserLevel() & ServerInfo_User::IsAdmin));
|
||||
myAddTab(tabAdmin);
|
||||
} else
|
||||
tabAdmin = 0;
|
||||
|
|
|
|||
|
|
@ -56,11 +56,18 @@ void MainWindow::processConnectionClosedEvent(Event_ConnectionClosed *event)
|
|||
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.");
|
||||
QMessageBox::critical(this, tr("Connection closed"), tr("The server has terminated your connection.\nReason: %1").arg(reasonStr));
|
||||
}
|
||||
|
||||
void MainWindow::processServerShutdownEvent(Event_ServerShutdown *event)
|
||||
{
|
||||
QMessageBox::information(this, tr("Scheduled server shutdown"), tr("The server is going to be restarted in %n minute(s).\nAll running games will be lost.\nReason for shutdown: %1", "", event->getMinutes()).arg(event->getReason()));
|
||||
}
|
||||
|
||||
void MainWindow::statusChanged(ClientStatus _status)
|
||||
{
|
||||
setClientStatusTitle();
|
||||
|
|
@ -290,6 +297,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
|
||||
client = new RemoteClient(this);
|
||||
connect(client, SIGNAL(connectionClosedEventReceived(Event_ConnectionClosed *)), this, SLOT(processConnectionClosedEvent(Event_ConnectionClosed *)));
|
||||
connect(client, SIGNAL(serverShutdownEventReceived(Event_ServerShutdown *)), this, SLOT(processServerShutdownEvent(Event_ServerShutdown *)));
|
||||
connect(client, SIGNAL(serverError(ResponseCode)), this, SLOT(serverError(ResponseCode)));
|
||||
connect(client, SIGNAL(socketError(const QString &)), this, SLOT(socketError(const QString &)));
|
||||
connect(client, SIGNAL(serverTimeout()), this, SLOT(serverTimeout()));
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ private slots:
|
|||
void updateTabMenu(QMenu *menu);
|
||||
void statusChanged(ClientStatus _status);
|
||||
void processConnectionClosedEvent(Event_ConnectionClosed *event);
|
||||
void processServerShutdownEvent(Event_ServerShutdown *event);
|
||||
void serverTimeout();
|
||||
void serverError(ResponseCode r);
|
||||
void socketError(const QString &errorStr);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue