mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 18:19:55 +00:00
[Browser] Minor improvements
This commit is contained in:
parent
4845599bda
commit
5c79e7106f
17 changed files with 41 additions and 60 deletions
|
@ -65,7 +65,7 @@ MainWindow::~MainWindow()
|
||||||
delete mGameInvoker;
|
delete mGameInvoker;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::addServerAndUpdate(QString addr)
|
void MainWindow::addServerAndUpdate(const QString &addr)
|
||||||
{
|
{
|
||||||
favorites->insertRow(0);
|
favorites->insertRow(0);
|
||||||
QModelIndex mi = favorites->index(0, ServerData::ADDR);
|
QModelIndex mi = favorites->index(0, ServerData::ADDR);
|
||||||
|
|
|
@ -17,11 +17,11 @@ class MainWindow : public QMainWindow, private Ui::MainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(QWidget *parent = 0);
|
explicit MainWindow(QWidget *parent = nullptr);
|
||||||
virtual ~MainWindow();
|
~MainWindow() override;
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent * event) Q_DECL_OVERRIDE;
|
void closeEvent(QCloseEvent * event) Q_DECL_OVERRIDE;
|
||||||
void addServerAndUpdate(QString addr);
|
void addServerAndUpdate(const QString &addr);
|
||||||
protected slots:
|
protected slots:
|
||||||
void tabSwitched(int index);
|
void tabSwitched(int index);
|
||||||
void addServer();
|
void addServer();
|
||||||
|
|
|
@ -14,7 +14,7 @@ class MySortFilterProxyModel : public QSortFilterProxyModel
|
||||||
protected:
|
protected:
|
||||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const Q_DECL_FINAL;
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const Q_DECL_FINAL;
|
||||||
public:
|
public:
|
||||||
MySortFilterProxyModel(QObject *parent);
|
explicit MySortFilterProxyModel(QObject *parent);
|
||||||
void filterFullServer(bool state);
|
void filterFullServer(bool state);
|
||||||
void filterEmptyServers(bool state);
|
void filterEmptyServers(bool state);
|
||||||
void pingLessThan(int maxPing);
|
void pingLessThan(int maxPing);
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include "PingUpdater.hpp"
|
#include "PingUpdater.hpp"
|
||||||
|
|
||||||
void PingHelper::Add(int row, AddrPair addrPair)
|
void PingHelper::Add(int row, const AddrPair &addrPair)
|
||||||
{
|
{
|
||||||
pingUpdater->addServer(row, addrPair);
|
pingUpdater->addServer(row, addrPair);
|
||||||
if (!pingThread->isRunning())
|
if (!pingThread->isRunning())
|
||||||
|
@ -48,11 +48,4 @@ PingHelper::PingHelper()
|
||||||
connect(this, SIGNAL(stop()), pingUpdater, SLOT(stop()));
|
connect(this, SIGNAL(stop()), pingUpdater, SLOT(stop()));
|
||||||
//connect(pingUpdater, SIGNAL(finished()), pingUpdater, SLOT(deleteLater()));
|
//connect(pingUpdater, SIGNAL(finished()), pingUpdater, SLOT(deleteLater()));
|
||||||
connect(pingUpdater, SIGNAL(updateModel(int, unsigned)), this, SLOT(update(int, unsigned)));
|
connect(pingUpdater, SIGNAL(updateModel(int, unsigned)), this, SLOT(update(int, unsigned)));
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
PingHelper::~PingHelper()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,17 +17,16 @@ class PingHelper : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void Add(int row, AddrPair addrPair);
|
void Add(int row, const AddrPair &addrPair);
|
||||||
void Stop();
|
void Stop();
|
||||||
void SetModel(QAbstractTableModel *model);
|
void SetModel(QAbstractTableModel *model);
|
||||||
//void UpdateImmedialy(PingUpdater::AddrPair addrPair);
|
//void UpdateImmedialy(PingUpdater::AddrPair addrPair);
|
||||||
static PingHelper &Get();
|
static PingHelper &Get();
|
||||||
private:
|
|
||||||
PingHelper();
|
|
||||||
~PingHelper();
|
|
||||||
|
|
||||||
PingHelper(const PingHelper&) = delete;
|
PingHelper(const PingHelper&) = delete;
|
||||||
PingHelper& operator=(const PingHelper&) = delete;
|
PingHelper& operator=(const PingHelper&) = delete;
|
||||||
|
private:
|
||||||
|
PingHelper();
|
||||||
signals:
|
signals:
|
||||||
void stop();
|
void stop();
|
||||||
public slots:
|
public slots:
|
||||||
|
|
|
@ -14,7 +14,7 @@ void PingUpdater::stop()
|
||||||
run = false;
|
run = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PingUpdater::addServer(int row, AddrPair addr)
|
void PingUpdater::addServer(int row, const AddrPair &addr)
|
||||||
{
|
{
|
||||||
servers.push_back({row, addr});
|
servers.push_back({row, addr});
|
||||||
run = true;
|
run = true;
|
||||||
|
|
|
@ -14,7 +14,7 @@ class PingUpdater : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
void addServer(int row, AddrPair addrPair);
|
void addServer(int row, const AddrPair &addrPair);
|
||||||
public slots:
|
public slots:
|
||||||
void stop();
|
void stop();
|
||||||
void process();
|
void process();
|
||||||
|
|
|
@ -19,8 +19,8 @@ QueryHelper::QueryHelper(QAbstractItemModel *model)
|
||||||
connect(queryThread, SIGNAL(started()), queryUpdate, SLOT(process()));
|
connect(queryThread, SIGNAL(started()), queryUpdate, SLOT(process()));
|
||||||
connect(queryUpdate, SIGNAL(finished()), queryThread, SLOT(quit()));
|
connect(queryUpdate, SIGNAL(finished()), queryThread, SLOT(quit()));
|
||||||
connect(queryUpdate, &QueryUpdate::finished, [this](){emit finished();});
|
connect(queryUpdate, &QueryUpdate::finished, [this](){emit finished();});
|
||||||
connect(queryUpdate, SIGNAL(updateModel(QString, unsigned short, QueryData)),
|
connect(queryUpdate, SIGNAL(updateModel(const QString&, unsigned short, const QueryData&)),
|
||||||
this, SLOT(update(QString, unsigned short, QueryData)));
|
this, SLOT(update(const QString&, unsigned short, const QueryData&)));
|
||||||
queryUpdate->moveToThread(queryThread);
|
queryUpdate->moveToThread(queryThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ void QueryHelper::terminate()
|
||||||
queryThread->terminate();
|
queryThread->terminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QueryHelper::update(QString addr, unsigned short port, QueryData data)
|
void QueryHelper::update(const QString &addr, unsigned short port, const QueryData& data)
|
||||||
{
|
{
|
||||||
ServerModel *model = ((ServerModel*)_model);
|
ServerModel *model = ((ServerModel*)_model);
|
||||||
model->insertRow(model->rowCount());
|
model->insertRow(model->rowCount());
|
||||||
|
@ -80,7 +80,7 @@ void QueryUpdate::process()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto server : data)
|
for (const auto &server : data)
|
||||||
emit updateModel(server.first.ToString(false), server.first.GetPort(), server.second);
|
emit updateModel(server.first.ToString(false), server.first.GetPort(), server.second);
|
||||||
emit finished();
|
emit finished();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ public slots:
|
||||||
void refresh();
|
void refresh();
|
||||||
void terminate();
|
void terminate();
|
||||||
private slots:
|
private slots:
|
||||||
void update(QString addr, unsigned short port, QueryData data);
|
void update(const QString &addr, unsigned short port, const QueryData& data);
|
||||||
signals:
|
signals:
|
||||||
void finished();
|
void finished();
|
||||||
void started();
|
void started();
|
||||||
|
@ -38,7 +38,7 @@ class QueryUpdate : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
signals:
|
signals:
|
||||||
void finished();
|
void finished();
|
||||||
void updateModel(QString addr, unsigned short port, QueryData data);
|
void updateModel(const QString &addr, unsigned short port, const QueryData& data);
|
||||||
public slots:
|
public slots:
|
||||||
void process();
|
void process();
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "ServerInfoDialog.hpp"
|
#include "ServerInfoDialog.hpp"
|
||||||
#include <apps/browser/netutils/Utils.hpp>
|
#include <apps/browser/netutils/Utils.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace RakNet;
|
using namespace RakNet;
|
||||||
|
@ -18,12 +19,7 @@ ServerInfoDialog::ServerInfoDialog(QWidget *parent): QDialog(parent)
|
||||||
connect(btnRefresh, SIGNAL(clicked()), this, SLOT(refresh()));
|
connect(btnRefresh, SIGNAL(clicked()), this, SLOT(refresh()));
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerInfoDialog::~ServerInfoDialog()
|
void ServerInfoDialog::Server(const QString &addr)
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void ServerInfoDialog::Server(QString addr)
|
|
||||||
{
|
{
|
||||||
this->addr = addr;
|
this->addr = addr;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +38,7 @@ bool ServerInfoDialog::refresh()
|
||||||
|
|
||||||
listPlayers->clear();
|
listPlayers->clear();
|
||||||
|
|
||||||
for (auto player : sd.second.players)
|
for (const auto &player : sd.second.players)
|
||||||
listPlayers->addItem(QString::fromStdString(player));
|
listPlayers->addItem(QString::fromStdString(player));
|
||||||
|
|
||||||
listPlugins->clear();
|
listPlugins->clear();
|
||||||
|
|
|
@ -11,9 +11,8 @@ class ServerInfoDialog : public QDialog, public Ui::Dialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ServerInfoDialog(QWidget *parent = 0);
|
explicit ServerInfoDialog(QWidget *parent = nullptr);
|
||||||
virtual ~ServerInfoDialog();
|
void Server(const QString &addr);
|
||||||
void Server(QString addr);
|
|
||||||
public slots:
|
public slots:
|
||||||
bool refresh();
|
bool refresh();
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -5,12 +5,6 @@
|
||||||
ServerModel::ServerModel(QObject *parent) : QAbstractTableModel(parent)
|
ServerModel::ServerModel(QObject *parent) : QAbstractTableModel(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerModel::~ServerModel()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*QHash<int, QByteArray> ServerModel::roleNames() const
|
/*QHash<int, QByteArray> ServerModel::roleNames() const
|
||||||
{
|
{
|
||||||
return roles;
|
return roles;
|
||||||
|
|
|
@ -29,8 +29,7 @@ class ServerModel: public QAbstractTableModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ServerModel(QObject *parent = 0);
|
explicit ServerModel(QObject *parent = nullptr);
|
||||||
~ServerModel();
|
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_FINAL;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_FINAL;
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_FINAL;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_FINAL;
|
||||||
int columnCount(const QModelIndex &parent) const Q_DECL_FINAL;
|
int columnCount(const QModelIndex &parent) const Q_DECL_FINAL;
|
||||||
|
|
|
@ -30,7 +30,7 @@ QueryClient::~QueryClient()
|
||||||
RakPeerInterface::DestroyInstance(peer);
|
RakPeerInterface::DestroyInstance(peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QueryClient::SetServer(std::string addr, unsigned short port)
|
void QueryClient::SetServer(const string &addr, unsigned short port)
|
||||||
{
|
{
|
||||||
masterAddr = SystemAddress(addr.c_str(), port);
|
masterAddr = SystemAddress(addr.c_str(), port);
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ map<SystemAddress, QueryData> QueryClient::Query()
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
pair<SystemAddress, QueryData> QueryClient::Update(RakNet::SystemAddress addr)
|
pair<SystemAddress, QueryData> QueryClient::Update(const RakNet::SystemAddress &addr)
|
||||||
{
|
{
|
||||||
qDebug() << "Locking mutex in QueryClient::Update(RakNet::SystemAddress addr)";
|
qDebug() << "Locking mutex in QueryClient::Update(RakNet::SystemAddress addr)";
|
||||||
pair<SystemAddress, QueryData> server;
|
pair<SystemAddress, QueryData> server;
|
||||||
|
|
|
@ -14,16 +14,16 @@
|
||||||
|
|
||||||
class QueryClient
|
class QueryClient
|
||||||
{
|
{
|
||||||
private:
|
public:
|
||||||
QueryClient(QueryClient const &) = delete;
|
QueryClient(QueryClient const &) = delete;
|
||||||
QueryClient(QueryClient &&) = delete;
|
QueryClient(QueryClient &&) = delete;
|
||||||
QueryClient &operator=(QueryClient const &) = delete;
|
QueryClient &operator=(QueryClient const &) = delete;
|
||||||
QueryClient &operator=(QueryClient &&) = delete;
|
QueryClient &operator=(QueryClient &&) = delete;
|
||||||
public:
|
|
||||||
static QueryClient &Get();
|
static QueryClient &Get();
|
||||||
void SetServer(std::string addr, unsigned short port);
|
void SetServer(const std::string &addr, unsigned short port);
|
||||||
std::map<RakNet::SystemAddress, QueryData> Query();
|
std::map<RakNet::SystemAddress, QueryData> Query();
|
||||||
std::pair<RakNet::SystemAddress, QueryData> Update(RakNet::SystemAddress addr);
|
std::pair<RakNet::SystemAddress, QueryData> Update(const RakNet::SystemAddress &addr);
|
||||||
int Status();
|
int Status();
|
||||||
private:
|
private:
|
||||||
RakNet::ConnectionState Connect();
|
RakNet::ConnectionState Connect();
|
||||||
|
|
|
@ -69,9 +69,9 @@ ServerExtendedData getExtendedData(const char *addr, unsigned short port)
|
||||||
sstr << TES3MP_VERSION;
|
sstr << TES3MP_VERSION;
|
||||||
sstr << TES3MP_PROTO_VERSION;
|
sstr << TES3MP_PROTO_VERSION;
|
||||||
|
|
||||||
std::string msg = "";
|
std::string msg;
|
||||||
|
|
||||||
if (peer->Connect(addr, port, sstr.str().c_str(), (int)(sstr.str().size()), 0, 0, 3, 500, 0) != RakNet::CONNECTION_ATTEMPT_STARTED)
|
if (peer->Connect(addr, port, sstr.str().c_str(), (int)(sstr.str().size()), nullptr, 0, 3, 500, 0) != RakNet::CONNECTION_ATTEMPT_STARTED)
|
||||||
msg = "Connection attempt failed.\n";
|
msg = "Connection attempt failed.\n";
|
||||||
|
|
||||||
|
|
||||||
|
@ -142,14 +142,14 @@ ServerExtendedData getExtendedData(const char *addr, unsigned short port)
|
||||||
{
|
{
|
||||||
RakNet::RakString str;
|
RakNet::RakString str;
|
||||||
bs.Read(str);
|
bs.Read(str);
|
||||||
data.players.push_back(str.C_String());
|
data.players.emplace_back(str.C_String());
|
||||||
}
|
}
|
||||||
bs.Read(length);
|
bs.Read(length);
|
||||||
for (size_t i = 0; i < length; i++)
|
for (size_t i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
RakNet::RakString str;
|
RakNet::RakString str;
|
||||||
bs.Read(str);
|
bs.Read(str);
|
||||||
data.plugins.push_back(str.C_String());
|
data.plugins.emplace_back(str.C_String());
|
||||||
}
|
}
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#define NEWMASTERPROTO_MASTERDATA_HPP
|
#define NEWMASTERPROTO_MASTERDATA_HPP
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
@ -30,7 +31,7 @@ struct Plugin
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string name;
|
||||||
unsigned hash;
|
unsigned hash;
|
||||||
Plugin(std::string name = "", unsigned hash = 0): name(name), hash(hash) {};
|
explicit Plugin(std::string name = "", unsigned hash = 0): name(std::move(name)), hash(hash) {};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct QueryData
|
struct QueryData
|
||||||
|
@ -50,23 +51,23 @@ struct QueryData
|
||||||
rules["passw"].type = 'v';
|
rules["passw"].type = 'v';
|
||||||
rules["passw"].val = 0;
|
rules["passw"].val = 0;
|
||||||
}
|
}
|
||||||
const char *GetName() { return rules["name"].str.c_str(); }
|
const char *GetName() const { return rules.at("name").str.c_str(); }
|
||||||
void SetName(const char *name) { rules["name"].str = name; }
|
void SetName(const char *name) { rules["name"].str = name; }
|
||||||
|
|
||||||
const char *GetVersion() { return rules["version"].str.c_str(); }
|
const char *GetVersion() const { return rules.at("version").str.c_str(); }
|
||||||
void SetVersion(const char *version) { rules["version"].str = version; }
|
void SetVersion(const char *version) { rules["version"].str = version; }
|
||||||
|
|
||||||
int GetPlayers() { return rules["players"].val; }
|
int GetPlayers() const { return rules.at("players").val; }
|
||||||
void SetPlayers(int players) { rules["players"].val = players; }
|
void SetPlayers(int players) { rules["players"].val = players; }
|
||||||
|
|
||||||
int GetMaxPlayers() { return rules["maxPlayers"].val; }
|
int GetMaxPlayers() const { return rules.at("maxPlayers").val; }
|
||||||
void SetMaxPlayers(int players) { rules["maxPlayers"].val = players; }
|
void SetMaxPlayers(int players) { rules["maxPlayers"].val = players; }
|
||||||
|
|
||||||
const char *GetGameMode() { return rules["gamemode"].str.c_str(); }
|
const char *GetGameMode() const { return rules.at("gamemode").str.c_str(); }
|
||||||
void SetGameMode(const char *str) { rules["gamemode"].str = str; }
|
void SetGameMode(const char *str) { rules["gamemode"].str = str; }
|
||||||
|
|
||||||
void SetPassword(int value) { rules["passw"].val = value; };
|
void SetPassword(int value) { rules["passw"].val = value; };
|
||||||
int GetPassword() { return rules["passw"].val; }
|
int GetPassword() const { return rules.at("passw").val; }
|
||||||
|
|
||||||
|
|
||||||
std::vector<std::string> players;
|
std::vector<std::string> players;
|
||||||
|
|
Loading…
Reference in a new issue