mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-29 22:45:34 +00:00
[Browser] Rework Connect window
This commit is contained in:
parent
92060bd6b6
commit
35b771b19e
3 changed files with 94 additions and 28 deletions
|
@ -122,21 +122,18 @@ void MainWindow::play()
|
|||
if (id < 0)
|
||||
return;
|
||||
|
||||
ServerInfoDialog infoDialog(this);
|
||||
|
||||
ServerModel *sm = ((ServerModel*)proxyModel->sourceModel());
|
||||
|
||||
int sourceId = proxyModel->mapToSource(proxyModel->index(id, ServerData::ADDR)).row();
|
||||
infoDialog.Server(sm->myData[sourceId].addr);
|
||||
|
||||
if (!infoDialog.refresh())
|
||||
{
|
||||
queryHelper->refresh();
|
||||
return;
|
||||
}
|
||||
ServerInfoDialog infoDialog(sm->myData[sourceId].addr, this);
|
||||
|
||||
if (!infoDialog.exec())
|
||||
return;
|
||||
|
||||
if (!infoDialog.isUpdated())
|
||||
return;
|
||||
|
||||
QStringList arguments;
|
||||
arguments.append(QLatin1String("--connect=") + sm->myData[sourceId].addr.toLatin1());
|
||||
|
||||
|
|
|
@ -6,28 +6,65 @@
|
|||
#include "qdebug.h"
|
||||
|
||||
#include "ServerInfoDialog.hpp"
|
||||
#include <apps/browser/netutils/Utils.hpp>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <QThread>
|
||||
|
||||
using namespace std;
|
||||
using namespace RakNet;
|
||||
|
||||
ServerInfoDialog::ServerInfoDialog(QWidget *parent): QDialog(parent)
|
||||
ThrWorker::ThrWorker(ServerInfoDialog *dialog, QString addr, unsigned short port): addr(std::move(addr)), port(port), stopped(false)
|
||||
{
|
||||
this->dialog = dialog;
|
||||
}
|
||||
|
||||
void ThrWorker::process()
|
||||
{
|
||||
stopped = false;
|
||||
auto newSD = QueryClient::Get().Update(SystemAddress(addr.toUtf8(), port));
|
||||
if (dialog != nullptr)
|
||||
dialog->setData(newSD);
|
||||
stopped = true;
|
||||
emit finished();
|
||||
}
|
||||
|
||||
ServerInfoDialog::ServerInfoDialog(const QString &addr, QWidget *parent): QDialog(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
connect(btnRefresh, SIGNAL(clicked()), this, SLOT(refresh()));
|
||||
}
|
||||
refreshThread = new QThread;
|
||||
|
||||
void ServerInfoDialog::Server(const QString &addr)
|
||||
{
|
||||
this->addr = addr;
|
||||
}
|
||||
|
||||
bool ServerInfoDialog::refresh()
|
||||
{
|
||||
QStringList list = addr.split(':');
|
||||
auto sd = QueryClient::Get().Update(SystemAddress(list[0].toLatin1(), list[1].toUShort()));
|
||||
worker = new ThrWorker(this, list[0].toLatin1(), list[1].toUShort());
|
||||
worker->moveToThread(refreshThread);
|
||||
connect(refreshThread, SIGNAL(started()), worker, SLOT(process()));
|
||||
connect(worker, SIGNAL(finished()), refreshThread, SLOT(quit()));
|
||||
connect(refreshThread, SIGNAL(finished()), this, SLOT(refresh()));
|
||||
|
||||
connect(btnRefresh, &QPushButton::clicked, [this]{
|
||||
if (!refreshThread->isRunning())
|
||||
refreshThread->start();
|
||||
});
|
||||
}
|
||||
|
||||
ServerInfoDialog::~ServerInfoDialog()
|
||||
{
|
||||
worker->dialog = nullptr;
|
||||
if (!refreshThread->isRunning())
|
||||
refreshThread->terminate();
|
||||
}
|
||||
|
||||
bool ServerInfoDialog::isUpdated()
|
||||
{
|
||||
return sd.first != UNASSIGNED_SYSTEM_ADDRESS;
|
||||
}
|
||||
|
||||
void ServerInfoDialog::setData(std::pair<RakNet::SystemAddress, QueryData> &newSD)
|
||||
{
|
||||
sd = newSD;
|
||||
}
|
||||
|
||||
void ServerInfoDialog::refresh()
|
||||
{
|
||||
if (sd.first != UNASSIGNED_SYSTEM_ADDRESS)
|
||||
{
|
||||
leAddr->setText(sd.first.ToString(true, ':'));
|
||||
|
@ -37,17 +74,16 @@ bool ServerInfoDialog::refresh()
|
|||
btnConnect->setDisabled(ping == PING_UNREACHABLE);
|
||||
|
||||
listPlayers->clear();
|
||||
|
||||
for (const auto &player : sd.second.players)
|
||||
listPlayers->addItem(QString::fromStdString(player));
|
||||
|
||||
listPlugins->clear();
|
||||
for (auto plugin : sd.second.plugins)
|
||||
for (const auto &plugin : sd.second.plugins)
|
||||
listPlugins->addItem(QString::fromStdString(plugin.name));
|
||||
|
||||
listRules->clear();
|
||||
const static vector<std::string> defaultRules {"gamemode", "maxPlayers", "name", "passw", "players", "version"};
|
||||
for (auto rule : sd.second.rules)
|
||||
for (auto &rule : sd.second.rules)
|
||||
{
|
||||
if (::find(defaultRules.begin(), defaultRules.end(), rule.first) != defaultRules.end())
|
||||
continue;
|
||||
|
@ -60,7 +96,12 @@ bool ServerInfoDialog::refresh()
|
|||
}
|
||||
|
||||
lblPlayers->setText(QString::number(sd.second.players.size()) + " / " + QString::number(sd.second.GetMaxPlayers()));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int ServerInfoDialog::exec()
|
||||
{
|
||||
if (!refreshThread->isRunning())
|
||||
refreshThread->start();
|
||||
return QDialog::exec();
|
||||
}
|
||||
|
|
|
@ -6,17 +6,45 @@
|
|||
#define NEWLAUNCHER_SERVERINFODIALOG_HPP
|
||||
|
||||
#include "ui_ServerInfo.h"
|
||||
#include <apps/browser/netutils/Utils.hpp>
|
||||
#include <RakNetTypes.h>
|
||||
#include <components/openmw-mp/Master/MasterData.hpp>
|
||||
|
||||
class ThrWorker;
|
||||
|
||||
class ServerInfoDialog : public QDialog, public Ui::Dialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ServerInfoDialog(QWidget *parent = nullptr);
|
||||
void Server(const QString &addr);
|
||||
explicit ServerInfoDialog(const QString &addr, QWidget *parent = nullptr);
|
||||
~ServerInfoDialog() override;
|
||||
bool isUpdated();
|
||||
void setData(std::pair<RakNet::SystemAddress, QueryData> &newSD);
|
||||
public slots:
|
||||
bool refresh();
|
||||
void refresh();
|
||||
int exec() Q_DECL_OVERRIDE;
|
||||
private:
|
||||
QThread *refreshThread;
|
||||
ThrWorker* worker;
|
||||
std::pair<RakNet::SystemAddress, QueryData> sd;
|
||||
};
|
||||
|
||||
class ThrWorker: public QObject
|
||||
{
|
||||
friend class ServerInfoDialog;
|
||||
Q_OBJECT
|
||||
public:
|
||||
ThrWorker(ServerInfoDialog *dialog, QString addr, unsigned short port);
|
||||
|
||||
public slots:
|
||||
void process();
|
||||
signals:
|
||||
void finished();
|
||||
private:
|
||||
QString addr;
|
||||
unsigned short port;
|
||||
bool stopped;
|
||||
ServerInfoDialog *dialog;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue