From ec5d1b7a861c003fbe8df0ee298d5b0ccfe23bc9 Mon Sep 17 00:00:00 2001 From: Koncord Date: Sat, 27 May 2017 11:25:00 +0800 Subject: [PATCH] [Browser] Do not try to open window if server is no more reachable --- apps/browser/MainWindow.cpp | 8 +++++++- apps/browser/ServerInfoDialog.cpp | 8 +++----- apps/browser/ServerInfoDialog.hpp | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/apps/browser/MainWindow.cpp b/apps/browser/MainWindow.cpp index 59e4dd60b..4bc62fcf5 100644 --- a/apps/browser/MainWindow.cpp +++ b/apps/browser/MainWindow.cpp @@ -121,7 +121,13 @@ void MainWindow::play() int sourceId = proxyModel->mapToSource(proxyModel->index(id, ServerData::ADDR)).row(); infoDialog.Server(sm->myData[sourceId].addr); - infoDialog.refresh(); + + if (!infoDialog.refresh()) + { + queryHelper->refresh(); + return; + } + if(!infoDialog.exec()) return; diff --git a/apps/browser/ServerInfoDialog.cpp b/apps/browser/ServerInfoDialog.cpp index d4c614069..5afcfb222 100644 --- a/apps/browser/ServerInfoDialog.cpp +++ b/apps/browser/ServerInfoDialog.cpp @@ -28,7 +28,7 @@ void ServerInfoDialog::Server(QString addr) this->addr = addr; } -void ServerInfoDialog::refresh() +bool ServerInfoDialog::refresh() { QStringList list = addr.split(':'); auto sd = QueryClient::Get().Update(SystemAddress(list[0].toLatin1(), list[1].toUShort())); @@ -43,15 +43,11 @@ void ServerInfoDialog::refresh() listPlayers->clear(); for(auto player : sd.second.players) - { listPlayers->addItem(QString::fromStdString(player)); - }; listPlugins->clear(); for(auto plugin : sd.second.plugins) - { listPlugins->addItem(QString::fromStdString(plugin.name)); - } listRules->clear(); const static vector defaultRules {"gamemode", "maxPlayers", "name", "passw", "players", "version"}; @@ -68,5 +64,7 @@ void ServerInfoDialog::refresh() } lblPlayers->setText(QString::number(sd.second.players.size()) + " / " + QString::number(sd.second.GetMaxPlayers())); + return true; } + return false; } diff --git a/apps/browser/ServerInfoDialog.hpp b/apps/browser/ServerInfoDialog.hpp index d67c369fb..33b802150 100644 --- a/apps/browser/ServerInfoDialog.hpp +++ b/apps/browser/ServerInfoDialog.hpp @@ -15,7 +15,7 @@ public: virtual ~ServerInfoDialog(); void Server(QString addr); public slots: - void refresh(); + bool refresh(); private: QString addr; };