diff --git a/apps/netlauncher/Main.cpp b/apps/netlauncher/Main.cpp index 1ea53ed4f..57c16bb3d 100644 --- a/apps/netlauncher/Main.cpp +++ b/apps/netlauncher/Main.cpp @@ -26,8 +26,6 @@ Main::Main(QWidget *parent) tblServerBrowser->hideColumn(ServerData::ADDR); tblFavorites->hideColumn(ServerData::ADDR); - refresh(); - connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabSwitched(int))); connect(actionAdd, SIGNAL(triggered(bool)), this, SLOT(addServer())); connect(actionAdd_by_IP, SIGNAL(triggered(bool)), this, SLOT(addServerByIP())); @@ -81,9 +79,9 @@ void Main::deleteServer() } } -void Main::refresh() +bool Main::refresh() { - NetController::get()->updateInfo(proxyModel->sourceModel()); + return NetController::get()->updateInfo(proxyModel->sourceModel()); /*tblServerBrowser->resizeColumnToContents(ServerData::HOSTNAME); tblServerBrowser->resizeColumnToContents(ServerData::MODNAME); tblFavorites->resizeColumnToContents(ServerData::HOSTNAME); diff --git a/apps/netlauncher/Main.hpp b/apps/netlauncher/Main.hpp index 08c5d134e..e896d9a3e 100644 --- a/apps/netlauncher/Main.hpp +++ b/apps/netlauncher/Main.hpp @@ -18,12 +18,13 @@ public: explicit Main(QWidget *parent = 0); virtual ~Main(); protected: +public slots: + bool refresh(); protected slots: void tabSwitched(int index); void addServer(); void addServerByIP(); void deleteServer(); - void refresh(); void play(); void serverSelected(); private: diff --git a/apps/netlauncher/NetController.cpp b/apps/netlauncher/NetController.cpp index 40f7a2da4..61d19458a 100644 --- a/apps/netlauncher/NetController.cpp +++ b/apps/netlauncher/NetController.cpp @@ -15,6 +15,7 @@ #include #include #include +#include using namespace std; @@ -59,7 +60,7 @@ struct pattern QString value; }; -void NetController::downloadInfo(QAbstractItemModel *pModel, QModelIndex index) +bool NetController::downloadInfo(QAbstractItemModel *pModel, QModelIndex index) { ServerModel *model = ((ServerModel *) pModel); @@ -76,6 +77,12 @@ void NetController::downloadInfo(QAbstractItemModel *pModel, QModelIndex index) RakSleep(30); } + if(data == "UNKNOWN_ADDRESS") + { + QMessageBox::critical(0, "Error", "Cannot connect to the master server!"); + return false; + } + qDebug() << "Content: " << data; QJsonParseError err; @@ -116,6 +123,7 @@ void NetController::downloadInfo(QAbstractItemModel *pModel, QModelIndex index) model->setData(mi, PingRakNetServer(addr[0].toLatin1().data(), addr[1].toUShort())); } + return true; } bool NetController::updateInfo(QAbstractItemModel *pModel, QModelIndex index) @@ -137,8 +145,9 @@ bool NetController::updateInfo(QAbstractItemModel *pModel, QModelIndex index) qDebug() << iter->addr; } model->removeRows(0, model->rowCount(index)); - downloadInfo(pModel, index); + result = downloadInfo(pModel, index); } + return result; } void NetController::updateInfo() @@ -153,6 +162,12 @@ void NetController::updateInfo() RakSleep(30); } + if(data == "UNKNOWN_ADDRESS") + { + QMessageBox::critical(0, "Error", "Cannot connect to the master server!"); + return; + } + qDebug() << "Content: " << data; QJsonParseError err; diff --git a/apps/netlauncher/NetController.hpp b/apps/netlauncher/NetController.hpp index 93ea3f451..40d45fbb0 100644 --- a/apps/netlauncher/NetController.hpp +++ b/apps/netlauncher/NetController.hpp @@ -18,7 +18,7 @@ public: static NetController *get(); static void Create(std::string addr, unsigned short port); static void Destroy(); - void updateInfo(QAbstractItemModel *pModel, QModelIndex index= QModelIndex()); + bool updateInfo(QAbstractItemModel *pModel, QModelIndex index= QModelIndex()); void updateInfo(); QStringList players(); QStringList plugins(); @@ -29,7 +29,7 @@ protected: ~NetController(); private: NetController(const NetController &controller); - void downloadInfo(QAbstractItemModel *pModel, QModelIndex index); + bool downloadInfo(QAbstractItemModel *pModel, QModelIndex index); static NetController *mThis; ServerData *sd; diff --git a/apps/netlauncher/main.cpp b/apps/netlauncher/main.cpp index 4caddc666..885ead8e6 100644 --- a/apps/netlauncher/main.cpp +++ b/apps/netlauncher/main.cpp @@ -44,7 +44,14 @@ int main(int argc, char *argv[]) atexit(NetController::Destroy); QApplication app(argc, argv); Main d; - d.show(); - // create and show your widgets here - return app.exec(); + if (d.refresh()) + { + d.show(); + return app.exec(); + } + else + { + app.exit(); + return 0; + } } \ No newline at end of file diff --git a/apps/netlauncher/netutils/HTTPNetwork.cpp b/apps/netlauncher/netutils/HTTPNetwork.cpp index c59b1f52a..b266e6acb 100644 --- a/apps/netlauncher/netutils/HTTPNetwork.cpp +++ b/apps/netlauncher/netutils/HTTPNetwork.cpp @@ -75,7 +75,8 @@ std::string HTTPNetwork::getData(const char *uri) { RakNet::RakString createRequest = RakNet::RakString::FormatForGET(uri); - httpConnection->TransmitRequest(createRequest, address.c_str(), port); + if (!httpConnection->TransmitRequest(createRequest, address.c_str(), port)) + return "UNKNOWN_ADDRESS"; return answer(); } @@ -83,7 +84,8 @@ std::string HTTPNetwork::getDataPOST(const char *uri, const char* body, const ch { RakNet::RakString createRequest = RakNet::RakString::FormatForPOST(uri, contentType, body); - httpConnection->TransmitRequest(createRequest, address.c_str(), port); + if (!httpConnection->TransmitRequest(createRequest, address.c_str(), port)) + return "UNKNOWN_ADDRESS"; return answer(); } @@ -91,6 +93,7 @@ std::string HTTPNetwork::getDataPUT(const char *uri, const char* body, const cha { RakNet::RakString createRequest = RakNet::RakString::FormatForPUT(uri, contentType, body); - httpConnection->TransmitRequest(createRequest, address.c_str(), port); + if (!httpConnection->TransmitRequest(createRequest, address.c_str(), port)) + return "UNKNOWN_ADDRESS"; return answer(); }