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)
|
||||
{
|
||||
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)
|
||||
|
|
|
@ -31,6 +31,7 @@ class LocalClient;
|
|||
class LocalServer;
|
||||
class ServerInfo_User;
|
||||
class QThread;
|
||||
class QMessageBox;
|
||||
|
||||
class MainWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
|
@ -86,6 +87,8 @@ private:
|
|||
|
||||
LocalServer *localServer;
|
||||
bool bHasActivated;
|
||||
|
||||
QMessageBox *serverShutdownMessageBox;
|
||||
public:
|
||||
MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
|
|
|
@ -126,7 +126,7 @@ void Servatrice_IslServer::incomingConnection(qintptr socketDescriptor)
|
|||
}
|
||||
|
||||
Servatrice::Servatrice(QObject *parent)
|
||||
: Server(true, parent), uptime(0), shutdownTimer(0)
|
||||
: Server(true, parent), uptime(0), shutdownTimer(0), isFirstShutdownMessage(true)
|
||||
{
|
||||
qRegisterMetaType<QSqlDatabase>("QSqlDatabase");
|
||||
}
|
||||
|
@ -485,26 +485,29 @@ void Servatrice::shutdownTimeout()
|
|||
{
|
||||
--shutdownMinutes;
|
||||
|
||||
SessionEvent *se;
|
||||
if (shutdownMinutes) {
|
||||
Event_ServerShutdown event;
|
||||
event.set_reason(shutdownReason.toStdString());
|
||||
event.set_minutes(shutdownMinutes);
|
||||
se = Server_ProtocolHandler::prepareSessionEvent(event);
|
||||
} else {
|
||||
Event_ConnectionClosed event;
|
||||
event.set_reason(Event_ConnectionClosed::SERVER_SHUTDOWN);
|
||||
se = Server_ProtocolHandler::prepareSessionEvent(event);
|
||||
if (shutdownMinutes <= 5 || isFirstShutdownMessage || shutdownMinutes % 10 == 0) {
|
||||
isFirstShutdownMessage = false;
|
||||
SessionEvent *se;
|
||||
if (shutdownMinutes) {
|
||||
Event_ServerShutdown event;
|
||||
event.set_reason(shutdownReason.toStdString());
|
||||
event.set_minutes(shutdownMinutes);
|
||||
se = Server_ProtocolHandler::prepareSessionEvent(event);
|
||||
} else {
|
||||
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
|
||||
|
|
|
@ -120,6 +120,7 @@ private:
|
|||
QString shutdownReason;
|
||||
int shutdownMinutes;
|
||||
QTimer *shutdownTimer;
|
||||
bool isFirstShutdownMessage;
|
||||
|
||||
mutable QMutex serverListMutex;
|
||||
QList<ServerProperties> serverList;
|
||||
|
|
Loading…
Reference in a new issue