|
|
|
#include "netutils/QueryClient.hpp"
|
|
|
|
#include "netutils/Utils.hpp"
|
|
|
|
#include "QueryHelper.hpp"
|
|
|
|
#include "PingHelper.hpp"
|
|
|
|
|
|
|
|
QueryUpdate *queryUpdate;
|
|
|
|
|
|
|
|
|
|
|
|
QueryHelper::QueryHelper(QAbstractItemModel *model)
|
|
|
|
{
|
|
|
|
qRegisterMetaType<QueryData>("QueryData");
|
|
|
|
queryThread = new QThread;
|
|
|
|
queryUpdate = new QueryUpdate;
|
|
|
|
_model = model;
|
|
|
|
connect(queryThread, SIGNAL(started()), queryUpdate, SLOT(process()));
|
|
|
|
connect(queryUpdate, SIGNAL(finished()), queryThread, SLOT(quit()));
|
|
|
|
connect(queryUpdate, &QueryUpdate::finished, [this](){emit finished();});
|
[Browser] Rework browser for improved stability & clarity
(cherry picked from commits 5c79e7106f840ef217b9bf45ec5d3bd925825863, 57353cdffff3580566415039544fae15052e8d73, 15723adb9a0383d8ebb8b7e26849b2de70b9952d, 01a5196a92f27f0c09bd053daf4d779d0c113974, ed75563a94174ca38cb67beba9c0e35a810dfbd2, 3839a2dcfd8fbbc7598771ee604f9ff9eb08e044, 1fd16ba69c4893cfe7379ea6bb0f65e5ac59cd4b, 66283943c593a406592daf0b90491d42a2e80050, ba8613a179936631d6c5fa7ae6dedb8a5f3eb684, 5b8f4f3e92d662f36580b94184057b648be9f01d, 35b771b19e00a813350553f686c0971334bbc3b5, 043eb224e29ca7b41a738eb598e16131ccfedd1a, 05fac2f67d5281d72b48bdba0db14e6bd7974765)
6 years ago
|
|
|
connect(queryUpdate, SIGNAL(updateModel(const QString&, unsigned short, const QueryData&)),
|
|
|
|
this, SLOT(update(const QString&, unsigned short, const QueryData&)));
|
|
|
|
queryUpdate->moveToThread(queryThread);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QueryHelper::refresh()
|
|
|
|
{
|
|
|
|
if (!queryThread->isRunning())
|
|
|
|
{
|
|
|
|
_model->removeRows(0, _model->rowCount());
|
[Browser] Rework browser for improved stability & clarity
(cherry picked from commits 5c79e7106f840ef217b9bf45ec5d3bd925825863, 57353cdffff3580566415039544fae15052e8d73, 15723adb9a0383d8ebb8b7e26849b2de70b9952d, 01a5196a92f27f0c09bd053daf4d779d0c113974, ed75563a94174ca38cb67beba9c0e35a810dfbd2, 3839a2dcfd8fbbc7598771ee604f9ff9eb08e044, 1fd16ba69c4893cfe7379ea6bb0f65e5ac59cd4b, 66283943c593a406592daf0b90491d42a2e80050, ba8613a179936631d6c5fa7ae6dedb8a5f3eb684, 5b8f4f3e92d662f36580b94184057b648be9f01d, 35b771b19e00a813350553f686c0971334bbc3b5, 043eb224e29ca7b41a738eb598e16131ccfedd1a, 05fac2f67d5281d72b48bdba0db14e6bd7974765)
6 years ago
|
|
|
PingHelper::Get().Stop();
|
|
|
|
queryThread->start();
|
|
|
|
emit started();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QueryHelper::terminate()
|
|
|
|
{
|
|
|
|
queryThread->terminate();
|
|
|
|
}
|
|
|
|
|
[Browser] Rework browser for improved stability & clarity
(cherry picked from commits 5c79e7106f840ef217b9bf45ec5d3bd925825863, 57353cdffff3580566415039544fae15052e8d73, 15723adb9a0383d8ebb8b7e26849b2de70b9952d, 01a5196a92f27f0c09bd053daf4d779d0c113974, ed75563a94174ca38cb67beba9c0e35a810dfbd2, 3839a2dcfd8fbbc7598771ee604f9ff9eb08e044, 1fd16ba69c4893cfe7379ea6bb0f65e5ac59cd4b, 66283943c593a406592daf0b90491d42a2e80050, ba8613a179936631d6c5fa7ae6dedb8a5f3eb684, 5b8f4f3e92d662f36580b94184057b648be9f01d, 35b771b19e00a813350553f686c0971334bbc3b5, 043eb224e29ca7b41a738eb598e16131ccfedd1a, 05fac2f67d5281d72b48bdba0db14e6bd7974765)
6 years ago
|
|
|
void QueryHelper::update(const QString &addr, unsigned short port, const QueryData& data)
|
|
|
|
{
|
|
|
|
ServerModel *model = ((ServerModel*)_model);
|
|
|
|
model->insertRow(model->rowCount());
|
|
|
|
int row = model->rowCount() - 1;
|
|
|
|
|
|
|
|
QModelIndex mi = model->index(row, ServerData::ADDR);
|
|
|
|
model->setData(mi, addr + ":" + QString::number(port));
|
|
|
|
|
|
|
|
mi = model->index(row, ServerData::PLAYERS);
|
|
|
|
model->setData(mi, (int)data.players.size());
|
|
|
|
|
|
|
|
mi = model->index(row, ServerData::MAX_PLAYERS);
|
|
|
|
model->setData(mi, data.GetMaxPlayers());
|
|
|
|
|
|
|
|
mi = model->index(row, ServerData::HOSTNAME);
|
|
|
|
model->setData(mi, data.GetName());
|
|
|
|
|
|
|
|
mi = model->index(row, ServerData::MODNAME);
|
|
|
|
model->setData(mi, data.GetGameMode());
|
|
|
|
|
|
|
|
mi = model->index(row, ServerData::VERSION);
|
|
|
|
model->setData(mi, data.GetVersion());
|
|
|
|
|
|
|
|
mi = model->index(row, ServerData::PASSW);
|
|
|
|
model->setData(mi, data.GetPassword() == 1);
|
|
|
|
|
|
|
|
mi = model->index(row, ServerData::PING);
|
|
|
|
model->setData(mi, PING_UNREACHABLE);
|
|
|
|
PingHelper::Get().Add(row, {addr, port});
|
|
|
|
}
|
|
|
|
|
|
|
|
void QueryUpdate::process()
|
|
|
|
{
|
|
|
|
auto data = QueryClient::Get().Query();
|
|
|
|
if (QueryClient::Get().Status() != ID_MASTER_QUERY)
|
|
|
|
{
|
|
|
|
emit finished();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
[Browser] Rework browser for improved stability & clarity
(cherry picked from commits 5c79e7106f840ef217b9bf45ec5d3bd925825863, 57353cdffff3580566415039544fae15052e8d73, 15723adb9a0383d8ebb8b7e26849b2de70b9952d, 01a5196a92f27f0c09bd053daf4d779d0c113974, ed75563a94174ca38cb67beba9c0e35a810dfbd2, 3839a2dcfd8fbbc7598771ee604f9ff9eb08e044, 1fd16ba69c4893cfe7379ea6bb0f65e5ac59cd4b, 66283943c593a406592daf0b90491d42a2e80050, ba8613a179936631d6c5fa7ae6dedb8a5f3eb684, 5b8f4f3e92d662f36580b94184057b648be9f01d, 35b771b19e00a813350553f686c0971334bbc3b5, 043eb224e29ca7b41a738eb598e16131ccfedd1a, 05fac2f67d5281d72b48bdba0db14e6bd7974765)
6 years ago
|
|
|
for (const auto &server : data)
|
|
|
|
emit updateModel(server.first.ToString(false), server.first.GetPort(), server.second);
|
|
|
|
emit finished();
|
|
|
|
}
|