mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-05-19 07:47:14 +02:00
move ServerPingTask in its own file
This commit is contained in:
parent
8b90a9f2b3
commit
dbb88ca7df
@ -922,6 +922,8 @@ SET(LAUNCHER_SOURCES
|
|||||||
ui/pages/instance/McClient.h
|
ui/pages/instance/McClient.h
|
||||||
ui/pages/instance/McResolver.cpp
|
ui/pages/instance/McResolver.cpp
|
||||||
ui/pages/instance/McResolver.h
|
ui/pages/instance/McResolver.h
|
||||||
|
ui/pages/instance/ServerPingTask.cpp
|
||||||
|
ui/pages/instance/ServerPingTask.h
|
||||||
|
|
||||||
# GUI - global settings pages
|
# GUI - global settings pages
|
||||||
ui/pages/global/AccountListPage.cpp
|
ui/pages/global/AccountListPage.cpp
|
||||||
|
44
launcher/ui/pages/instance/ServerPingTask.cpp
Normal file
44
launcher/ui/pages/instance/ServerPingTask.cpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#include <QFutureWatcher>
|
||||||
|
|
||||||
|
#include "ServerPingTask.h"
|
||||||
|
#include "McResolver.h"
|
||||||
|
#include "McClient.h"
|
||||||
|
|
||||||
|
void ServerPingTask::executeTask() {
|
||||||
|
qDebug() << "Querying status of " << QString("%1:%2").arg(m_domain).arg(m_port);
|
||||||
|
|
||||||
|
// Resolve the actual IP and port for the server
|
||||||
|
McResolver *resolver = new McResolver(nullptr, m_domain, m_port);
|
||||||
|
QObject::connect(resolver, &McResolver::succeeded, [this, resolver](QString ip, int port) {
|
||||||
|
qDebug() << "Resolved Address for" << m_domain << ": " << ip << ":" << port;
|
||||||
|
|
||||||
|
// Now that we have the IP and port, query the server
|
||||||
|
McClient *client = new McClient(nullptr, m_domain, ip, port);
|
||||||
|
auto onlineFuture = client->getOnlinePlayers();
|
||||||
|
|
||||||
|
// Wait for query to finish
|
||||||
|
QFutureWatcher<int> *watcher = new QFutureWatcher<int>();
|
||||||
|
QObject::connect(watcher, &QFutureWatcher<int>::finished, [this, client, onlineFuture, watcher]() {
|
||||||
|
client->deleteLater();
|
||||||
|
watcher->deleteLater();
|
||||||
|
|
||||||
|
int online = onlineFuture.result();
|
||||||
|
if (online == -1) {
|
||||||
|
qDebug() << "Failed to get online players";
|
||||||
|
emitFailed();
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
qDebug() << "Online players: " << online;
|
||||||
|
m_outputOnlinePlayers = online;
|
||||||
|
emitSucceeded();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
watcher->setFuture(onlineFuture);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Delete McResolver object when done
|
||||||
|
QObject::connect(resolver, &McResolver::finished, [resolver]() {
|
||||||
|
resolver->deleteLater();
|
||||||
|
});
|
||||||
|
resolver->ping();
|
||||||
|
}
|
22
launcher/ui/pages/instance/ServerPingTask.h
Normal file
22
launcher/ui/pages/instance/ServerPingTask.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
#include <tasks/Task.h>
|
||||||
|
|
||||||
|
|
||||||
|
class ServerPingTask : public Task {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ServerPingTask(QString domain, int port) : Task(), m_domain(domain), m_port(port) {}
|
||||||
|
~ServerPingTask() override = default;
|
||||||
|
int m_outputOnlinePlayers = -1;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_domain;
|
||||||
|
int m_port;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void executeTask() override;
|
||||||
|
};
|
@ -38,9 +38,7 @@
|
|||||||
#include "ServersPage.h"
|
#include "ServersPage.h"
|
||||||
#include "ui/dialogs/CustomMessageBox.h"
|
#include "ui/dialogs/CustomMessageBox.h"
|
||||||
#include "ui_ServersPage.h"
|
#include "ui_ServersPage.h"
|
||||||
|
#include "ServerPingTask.h"
|
||||||
#include "McClient.h"
|
|
||||||
#include "McResolver.h"
|
|
||||||
|
|
||||||
#include <FileSystem.h>
|
#include <FileSystem.h>
|
||||||
#include <io/stream_reader.h>
|
#include <io/stream_reader.h>
|
||||||
@ -130,58 +128,6 @@ struct Server {
|
|||||||
int m_maxPlayers = 0;
|
int m_maxPlayers = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ServerPingTask : public Task {
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit ServerPingTask(QString domain, int port) : Task(), m_domain(domain), m_port(port) {}
|
|
||||||
~ServerPingTask() override = default;
|
|
||||||
int m_outputOnlinePlayers = -1;
|
|
||||||
|
|
||||||
private:
|
|
||||||
QString m_domain;
|
|
||||||
int m_port;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void executeTask() override {
|
|
||||||
qDebug() << "Querying status of " << QString("%1:%2").arg(m_domain).arg(m_port);
|
|
||||||
|
|
||||||
// Resolve the actual IP and port for the server
|
|
||||||
McResolver *resolver = new McResolver(nullptr, m_domain, m_port);
|
|
||||||
QObject::connect(resolver, &McResolver::succeeded, [this, resolver](QString ip, int port) {
|
|
||||||
qDebug() << "Resolved Address for" << m_domain << ": " << ip << ":" << port;
|
|
||||||
|
|
||||||
// Now that we have the IP and port, query the server
|
|
||||||
McClient *client = new McClient(nullptr, m_domain, ip, port);
|
|
||||||
auto onlineFuture = client->getOnlinePlayers();
|
|
||||||
|
|
||||||
// Wait for query to finish
|
|
||||||
QFutureWatcher<int> *watcher = new QFutureWatcher<int>();
|
|
||||||
QObject::connect(watcher, &QFutureWatcher<int>::finished, [this, client, onlineFuture, watcher]() {
|
|
||||||
client->deleteLater();
|
|
||||||
watcher->deleteLater();
|
|
||||||
|
|
||||||
int online = onlineFuture.result();
|
|
||||||
if (online == -1) {
|
|
||||||
qDebug() << "Failed to get online players";
|
|
||||||
emitFailed();
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
qDebug() << "Online players: " << online;
|
|
||||||
m_outputOnlinePlayers = online;
|
|
||||||
emitSucceeded();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
watcher->setFuture(onlineFuture);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Delete McResolver object when done
|
|
||||||
QObject::connect(resolver, &McResolver::finished, [resolver]() {
|
|
||||||
resolver->deleteLater();
|
|
||||||
});
|
|
||||||
resolver->ping();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static std::unique_ptr<nbt::tag_compound> parseServersDat(const QString& filename)
|
static std::unique_ptr<nbt::tag_compound> parseServersDat(const QString& filename)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user