Fix waiting answer when browser not connected to the master server

coverity_scan^2
Koncord 8 years ago
parent 968546b20c
commit 4604ee49bf

@ -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);

@ -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:

@ -15,6 +15,7 @@
#include <QJsonDocument>
#include <QJsonArray>
#include <memory>
#include <QtWidgets/QMessageBox>
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;

@ -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;

@ -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;
}
}

@ -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();
}

Loading…
Cancel
Save