mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-07-07 00:21:35 +00:00
Fix waiting answer when browser not connected to the master server
This commit is contained in:
parent
968546b20c
commit
4604ee49bf
6 changed files with 39 additions and 15 deletions
|
@ -26,8 +26,6 @@ Main::Main(QWidget *parent)
|
||||||
tblServerBrowser->hideColumn(ServerData::ADDR);
|
tblServerBrowser->hideColumn(ServerData::ADDR);
|
||||||
tblFavorites->hideColumn(ServerData::ADDR);
|
tblFavorites->hideColumn(ServerData::ADDR);
|
||||||
|
|
||||||
refresh();
|
|
||||||
|
|
||||||
connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabSwitched(int)));
|
connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabSwitched(int)));
|
||||||
connect(actionAdd, SIGNAL(triggered(bool)), this, SLOT(addServer()));
|
connect(actionAdd, SIGNAL(triggered(bool)), this, SLOT(addServer()));
|
||||||
connect(actionAdd_by_IP, SIGNAL(triggered(bool)), this, SLOT(addServerByIP()));
|
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::HOSTNAME);
|
||||||
tblServerBrowser->resizeColumnToContents(ServerData::MODNAME);
|
tblServerBrowser->resizeColumnToContents(ServerData::MODNAME);
|
||||||
tblFavorites->resizeColumnToContents(ServerData::HOSTNAME);
|
tblFavorites->resizeColumnToContents(ServerData::HOSTNAME);
|
||||||
|
|
|
@ -18,12 +18,13 @@ public:
|
||||||
explicit Main(QWidget *parent = 0);
|
explicit Main(QWidget *parent = 0);
|
||||||
virtual ~Main();
|
virtual ~Main();
|
||||||
protected:
|
protected:
|
||||||
|
public slots:
|
||||||
|
bool refresh();
|
||||||
protected slots:
|
protected slots:
|
||||||
void tabSwitched(int index);
|
void tabSwitched(int index);
|
||||||
void addServer();
|
void addServer();
|
||||||
void addServerByIP();
|
void addServerByIP();
|
||||||
void deleteServer();
|
void deleteServer();
|
||||||
void refresh();
|
|
||||||
void play();
|
void play();
|
||||||
void serverSelected();
|
void serverSelected();
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <QtWidgets/QMessageBox>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -59,7 +60,7 @@ struct pattern
|
||||||
QString value;
|
QString value;
|
||||||
};
|
};
|
||||||
|
|
||||||
void NetController::downloadInfo(QAbstractItemModel *pModel, QModelIndex index)
|
bool NetController::downloadInfo(QAbstractItemModel *pModel, QModelIndex index)
|
||||||
{
|
{
|
||||||
ServerModel *model = ((ServerModel *) pModel);
|
ServerModel *model = ((ServerModel *) pModel);
|
||||||
|
|
||||||
|
@ -76,6 +77,12 @@ void NetController::downloadInfo(QAbstractItemModel *pModel, QModelIndex index)
|
||||||
RakSleep(30);
|
RakSleep(30);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(data == "UNKNOWN_ADDRESS")
|
||||||
|
{
|
||||||
|
QMessageBox::critical(0, "Error", "Cannot connect to the master server!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
qDebug() << "Content: " << data;
|
qDebug() << "Content: " << data;
|
||||||
|
|
||||||
QJsonParseError err;
|
QJsonParseError err;
|
||||||
|
@ -116,6 +123,7 @@ void NetController::downloadInfo(QAbstractItemModel *pModel, QModelIndex index)
|
||||||
model->setData(mi, PingRakNetServer(addr[0].toLatin1().data(), addr[1].toUShort()));
|
model->setData(mi, PingRakNetServer(addr[0].toLatin1().data(), addr[1].toUShort()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetController::updateInfo(QAbstractItemModel *pModel, QModelIndex index)
|
bool NetController::updateInfo(QAbstractItemModel *pModel, QModelIndex index)
|
||||||
|
@ -137,8 +145,9 @@ bool NetController::updateInfo(QAbstractItemModel *pModel, QModelIndex index)
|
||||||
qDebug() << iter->addr;
|
qDebug() << iter->addr;
|
||||||
}
|
}
|
||||||
model->removeRows(0, model->rowCount(index));
|
model->removeRows(0, model->rowCount(index));
|
||||||
downloadInfo(pModel, index);
|
result = downloadInfo(pModel, index);
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetController::updateInfo()
|
void NetController::updateInfo()
|
||||||
|
@ -153,6 +162,12 @@ void NetController::updateInfo()
|
||||||
RakSleep(30);
|
RakSleep(30);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(data == "UNKNOWN_ADDRESS")
|
||||||
|
{
|
||||||
|
QMessageBox::critical(0, "Error", "Cannot connect to the master server!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
qDebug() << "Content: " << data;
|
qDebug() << "Content: " << data;
|
||||||
|
|
||||||
QJsonParseError err;
|
QJsonParseError err;
|
||||||
|
|
|
@ -18,7 +18,7 @@ public:
|
||||||
static NetController *get();
|
static NetController *get();
|
||||||
static void Create(std::string addr, unsigned short port);
|
static void Create(std::string addr, unsigned short port);
|
||||||
static void Destroy();
|
static void Destroy();
|
||||||
void updateInfo(QAbstractItemModel *pModel, QModelIndex index= QModelIndex());
|
bool updateInfo(QAbstractItemModel *pModel, QModelIndex index= QModelIndex());
|
||||||
void updateInfo();
|
void updateInfo();
|
||||||
QStringList players();
|
QStringList players();
|
||||||
QStringList plugins();
|
QStringList plugins();
|
||||||
|
@ -29,7 +29,7 @@ protected:
|
||||||
~NetController();
|
~NetController();
|
||||||
private:
|
private:
|
||||||
NetController(const NetController &controller);
|
NetController(const NetController &controller);
|
||||||
void downloadInfo(QAbstractItemModel *pModel, QModelIndex index);
|
bool downloadInfo(QAbstractItemModel *pModel, QModelIndex index);
|
||||||
|
|
||||||
static NetController *mThis;
|
static NetController *mThis;
|
||||||
ServerData *sd;
|
ServerData *sd;
|
||||||
|
|
|
@ -44,7 +44,14 @@ int main(int argc, char *argv[])
|
||||||
atexit(NetController::Destroy);
|
atexit(NetController::Destroy);
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
Main d;
|
Main d;
|
||||||
d.show();
|
if (d.refresh())
|
||||||
// create and show your widgets here
|
{
|
||||||
return app.exec();
|
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);
|
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();
|
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);
|
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();
|
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);
|
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();
|
return answer();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue