Merge pull request #1010 from poixen/server_shutdown_warnings
Updated server shutdown timer logic
This commit is contained in:
commit
924dd174e3
4 changed files with 34 additions and 21 deletions
|
@ -86,7 +86,13 @@ void MainWindow::processConnectionClosedEvent(const Event_ConnectionClosed &even
|
||||||
|
|
||||||
void MainWindow::processServerShutdownEvent(const Event_ServerShutdown &event)
|
void MainWindow::processServerShutdownEvent(const 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.minutes()).arg(QString::fromStdString(event.reason())));
|
if (serverShutdownMessageBox)
|
||||||
|
serverShutdownMessageBox->close();
|
||||||
|
serverShutdownMessageBox = new QMessageBox(this);
|
||||||
|
serverShutdownMessageBox->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
serverShutdownMessageBox->setInformativeText(tr("The server is going to be restarted in %n minute(s).\nAll running games will be lost.\nReason for shutdown: %1", "", event.minutes()).arg(QString::fromStdString(event.reason())));
|
||||||
|
serverShutdownMessageBox->setText(tr("Scheduled server shutdown"));
|
||||||
|
serverShutdownMessageBox->exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::statusChanged(ClientStatus _status)
|
void MainWindow::statusChanged(ClientStatus _status)
|
||||||
|
|
|
@ -31,6 +31,7 @@ class LocalClient;
|
||||||
class LocalServer;
|
class LocalServer;
|
||||||
class ServerInfo_User;
|
class ServerInfo_User;
|
||||||
class QThread;
|
class QThread;
|
||||||
|
class QMessageBox;
|
||||||
|
|
||||||
class MainWindow : public QMainWindow {
|
class MainWindow : public QMainWindow {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -86,6 +87,8 @@ private:
|
||||||
|
|
||||||
LocalServer *localServer;
|
LocalServer *localServer;
|
||||||
bool bHasActivated;
|
bool bHasActivated;
|
||||||
|
|
||||||
|
QMessageBox *serverShutdownMessageBox;
|
||||||
public:
|
public:
|
||||||
MainWindow(QWidget *parent = 0);
|
MainWindow(QWidget *parent = 0);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
|
@ -126,7 +126,7 @@ void Servatrice_IslServer::incomingConnection(qintptr socketDescriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
Servatrice::Servatrice(QObject *parent)
|
Servatrice::Servatrice(QObject *parent)
|
||||||
: Server(true, parent), uptime(0), shutdownTimer(0)
|
: Server(true, parent), uptime(0), shutdownTimer(0), isFirstShutdownMessage(true)
|
||||||
{
|
{
|
||||||
qRegisterMetaType<QSqlDatabase>("QSqlDatabase");
|
qRegisterMetaType<QSqlDatabase>("QSqlDatabase");
|
||||||
}
|
}
|
||||||
|
@ -485,26 +485,29 @@ void Servatrice::shutdownTimeout()
|
||||||
{
|
{
|
||||||
--shutdownMinutes;
|
--shutdownMinutes;
|
||||||
|
|
||||||
SessionEvent *se;
|
if (shutdownMinutes <= 5 || isFirstShutdownMessage || shutdownMinutes % 10 == 0) {
|
||||||
if (shutdownMinutes) {
|
isFirstShutdownMessage = false;
|
||||||
Event_ServerShutdown event;
|
SessionEvent *se;
|
||||||
event.set_reason(shutdownReason.toStdString());
|
if (shutdownMinutes) {
|
||||||
event.set_minutes(shutdownMinutes);
|
Event_ServerShutdown event;
|
||||||
se = Server_ProtocolHandler::prepareSessionEvent(event);
|
event.set_reason(shutdownReason.toStdString());
|
||||||
} else {
|
event.set_minutes(shutdownMinutes);
|
||||||
Event_ConnectionClosed event;
|
se = Server_ProtocolHandler::prepareSessionEvent(event);
|
||||||
event.set_reason(Event_ConnectionClosed::SERVER_SHUTDOWN);
|
} else {
|
||||||
se = Server_ProtocolHandler::prepareSessionEvent(event);
|
Event_ConnectionClosed event;
|
||||||
|
event.set_reason(Event_ConnectionClosed::SERVER_SHUTDOWN);
|
||||||
|
se = Server_ProtocolHandler::prepareSessionEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
clientsLock.lockForRead();
|
||||||
|
for (int i = 0; i < clients.size(); ++i)
|
||||||
|
clients[i]->sendProtocolItem(*se);
|
||||||
|
clientsLock.unlock();
|
||||||
|
delete se;
|
||||||
|
|
||||||
|
if (!shutdownMinutes)
|
||||||
|
deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
clientsLock.lockForRead();
|
|
||||||
for (int i = 0; i < clients.size(); ++i)
|
|
||||||
clients[i]->sendProtocolItem(*se);
|
|
||||||
clientsLock.unlock();
|
|
||||||
delete se;
|
|
||||||
|
|
||||||
if (!shutdownMinutes)
|
|
||||||
deleteLater();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Servatrice::islConnectionExists(int serverId) const
|
bool Servatrice::islConnectionExists(int serverId) const
|
||||||
|
|
|
@ -120,6 +120,7 @@ private:
|
||||||
QString shutdownReason;
|
QString shutdownReason;
|
||||||
int shutdownMinutes;
|
int shutdownMinutes;
|
||||||
QTimer *shutdownTimer;
|
QTimer *shutdownTimer;
|
||||||
|
bool isFirstShutdownMessage;
|
||||||
|
|
||||||
mutable QMutex serverListMutex;
|
mutable QMutex serverListMutex;
|
||||||
QList<ServerProperties> serverList;
|
QList<ServerProperties> serverList;
|
||||||
|
|
Loading…
Reference in a new issue