mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-04-29 22:24:26 +02:00
chore: format some of the project files (#3677)
This commit is contained in:
commit
e9afa16aa1
@ -5,3 +5,9 @@ bbb3b3e6f6e3c0f95873f22e6d0a4aaf350f49d9
|
||||
|
||||
# (nix) alejandra -> nixfmt
|
||||
4c81d8c53d09196426568c4a31a4e752ed05397a
|
||||
|
||||
# reformat codebase
|
||||
1d468ac35ad88d8c77cc83f25e3704d9bd7df01b
|
||||
|
||||
# format a part of codebase
|
||||
5c8481a118c8fefbfe901001d7828eaf6866eac4
|
||||
|
@ -128,6 +128,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys.h>
|
||||
#include <QStringLiteral>
|
||||
#include "SysInfo.h"
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
|
@ -167,8 +167,8 @@ bool LogModel::isOverFlow()
|
||||
return m_numLines >= m_maxLines && m_stopOnOverflow;
|
||||
}
|
||||
|
||||
|
||||
MessageLevel::Enum LogModel::previousLevel() {
|
||||
MessageLevel::Enum LogModel::previousLevel()
|
||||
{
|
||||
if (!m_content.isEmpty()) {
|
||||
return m_content.last().level;
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ std::optional<LogParser::ParsedItem> LogParser::parseNext()
|
||||
if (m_buffer.trimmed().isEmpty()) {
|
||||
auto text = QString(m_buffer);
|
||||
m_buffer.clear();
|
||||
return LogParser::PlainText { text };
|
||||
return LogParser::PlainText{ text };
|
||||
}
|
||||
|
||||
// check if we have a full xml log4j event
|
||||
|
@ -1003,7 +1003,6 @@ QMap<QString, QString> MinecraftInstance::createCensorFilterFromSession(AuthSess
|
||||
return filter;
|
||||
}
|
||||
|
||||
|
||||
QStringList MinecraftInstance::getLogFileSearchPaths()
|
||||
{
|
||||
return { FS::PathCombine(gameRoot(), "crash-reports"), FS::PathCombine(gameRoot(), "logs"), gameRoot() };
|
||||
|
@ -84,7 +84,7 @@ class Mod : public Resource {
|
||||
|
||||
bool valid() const override;
|
||||
|
||||
[[nodiscard]] int compare(const Resource & other, SortType type) const override;
|
||||
[[nodiscard]] int compare(const Resource& other, SortType type) const override;
|
||||
[[nodiscard]] bool applyFilter(QRegularExpression filter) const override;
|
||||
|
||||
// Delete all the files of this mod
|
||||
|
@ -48,7 +48,8 @@ TexturePackFolderModel::TexturePackFolderModel(const QDir& dir, BaseInstance* in
|
||||
m_column_names = QStringList({ "Enable", "Image", "Name", "Last Modified", "Provider", "Size" });
|
||||
m_column_names_translated = QStringList({ tr("Enable"), tr("Image"), tr("Name"), tr("Last Modified"), tr("Provider"), tr("Size") });
|
||||
m_column_sort_keys = { SortType::ENABLED, SortType::NAME, SortType::NAME, SortType::DATE, SortType::PROVIDER, SortType::SIZE };
|
||||
m_column_resize_modes = { QHeaderView::Interactive, QHeaderView::Interactive, QHeaderView::Stretch, QHeaderView::Interactive, QHeaderView::Interactive, QHeaderView::Interactive };
|
||||
m_column_resize_modes = { QHeaderView::Interactive, QHeaderView::Interactive, QHeaderView::Stretch,
|
||||
QHeaderView::Interactive, QHeaderView::Interactive, QHeaderView::Interactive };
|
||||
m_columnsHideable = { false, true, false, true, true, true };
|
||||
m_columnsHiddenByDefault = { false, false, false, false, false, true };
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ auto HttpMetaCache::evictEntry(MetaEntryPtr entry) -> bool
|
||||
return true;
|
||||
}
|
||||
|
||||
//returns true on success, false otherwise
|
||||
// returns true on success, false otherwise
|
||||
auto HttpMetaCache::evictAll() -> bool
|
||||
{
|
||||
bool ret = true;
|
||||
@ -178,7 +178,7 @@ auto HttpMetaCache::evictAll() -> bool
|
||||
qCWarning(taskHttpMetaCacheLogC) << "Unexpected missing cache entry" << entry->m_basePath;
|
||||
}
|
||||
map.entry_list.clear();
|
||||
//AND all return codes together so the result is true iff all runs of deletePath() are true
|
||||
// AND all return codes together so the result is true iff all runs of deletePath() are true
|
||||
ret &= FS::deletePath(map.base_path);
|
||||
}
|
||||
return ret;
|
||||
|
@ -79,7 +79,6 @@ Q_DECLARE_METATYPE(TaskStepProgress)
|
||||
|
||||
using TaskStepProgressList = QList<std::shared_ptr<TaskStepProgress>>;
|
||||
|
||||
|
||||
/*!
|
||||
* Represents a task that has to be done.
|
||||
* To create a task, you need to subclass this class, implement the executeTask() method and call
|
||||
|
@ -1311,7 +1311,7 @@ void MainWindow::on_actionReportBug_triggered()
|
||||
|
||||
void MainWindow::on_actionClearMetadata_triggered()
|
||||
{
|
||||
//This if contains side effects!
|
||||
// This if contains side effects!
|
||||
if (!APPLICATION->metacache()->evictAll()) {
|
||||
CustomMessageBox::selectable(this, tr("Error"),
|
||||
tr("Metadata cache clear Failed!\nTo clear the metadata cache manually, press Folders -> View "
|
||||
|
@ -37,11 +37,11 @@
|
||||
|
||||
#include <Application.h>
|
||||
#include <QObjectPtr.h>
|
||||
#include "ui/widgets/JavaSettingsWidget.h"
|
||||
#include <QDialog>
|
||||
#include <QStringListModel>
|
||||
#include "JavaCommon.h"
|
||||
#include "ui/pages/BasePage.h"
|
||||
#include "ui/widgets/JavaSettingsWidget.h"
|
||||
|
||||
class SettingsObject;
|
||||
|
||||
|
@ -35,17 +35,18 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include "Application.h"
|
||||
#include "BaseInstance.h"
|
||||
#include "ui/pages/BasePage.h"
|
||||
#include "ui/widgets/MinecraftSettingsWidget.h"
|
||||
#include <QWidget>
|
||||
|
||||
class InstanceSettingsPage : public MinecraftSettingsWidget, public BasePage {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit InstanceSettingsPage(MinecraftInstancePtr instance, QWidget* parent = nullptr) : MinecraftSettingsWidget(std::move(instance), parent)
|
||||
explicit InstanceSettingsPage(MinecraftInstancePtr instance, QWidget* parent = nullptr)
|
||||
: MinecraftSettingsWidget(std::move(instance), parent)
|
||||
{
|
||||
connect(APPLICATION, &Application::globalSettingsAboutToOpen, this, &InstanceSettingsPage::saveSettings);
|
||||
connect(APPLICATION, &Application::globalSettingsClosed, this, &InstanceSettingsPage::loadSettings);
|
||||
|
@ -347,13 +347,18 @@ void ManagedPackPage::onUpdateTaskCompleted(bool did_succeed) const
|
||||
if (m_instance_window != nullptr)
|
||||
m_instance_window->close();
|
||||
|
||||
CustomMessageBox::selectable(nullptr, tr("Update Successful"), tr("The instance updated to pack version %1 successfully.").arg(m_inst->getManagedPackVersionName()), QMessageBox::Information)
|
||||
->show();
|
||||
CustomMessageBox::selectable(nullptr, tr("Update Successful"),
|
||||
tr("The instance updated to pack version %1 successfully.").arg(m_inst->getManagedPackVersionName()),
|
||||
QMessageBox::Information)
|
||||
->show();
|
||||
} else {
|
||||
CustomMessageBox::selectable(nullptr, tr("Update Failed"), tr("The instance failed to update to pack version %1. Please check launcher logs for more information.").arg(m_inst->getManagedPackVersionName()), QMessageBox::Critical)
|
||||
->show();
|
||||
CustomMessageBox::selectable(
|
||||
nullptr, tr("Update Failed"),
|
||||
tr("The instance failed to update to pack version %1. Please check launcher logs for more information.")
|
||||
.arg(m_inst->getManagedPackVersionName()),
|
||||
QMessageBox::Critical)
|
||||
->show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ModrinthManagedPackPage::update()
|
||||
|
@ -1,21 +1,22 @@
|
||||
#include <QObject>
|
||||
#include <QTcpSocket>
|
||||
#include <qtconcurrentrun.h>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <qtconcurrentrun.h>
|
||||
#include <QObject>
|
||||
#include <QTcpSocket>
|
||||
|
||||
#include <Exception.h>
|
||||
#include "McClient.h"
|
||||
#include "Json.h"
|
||||
#include "McClient.h"
|
||||
|
||||
// 7 first bits
|
||||
#define SEGMENT_BITS 0x7F
|
||||
// last bit
|
||||
#define CONTINUE_BIT 0x80
|
||||
|
||||
McClient::McClient(QObject *parent, QString domain, QString ip, short port): QObject(parent), m_domain(domain), m_ip(ip), m_port(port) {}
|
||||
McClient::McClient(QObject* parent, QString domain, QString ip, short port) : QObject(parent), m_domain(domain), m_ip(ip), m_port(port) {}
|
||||
|
||||
void McClient::getStatusData() {
|
||||
void McClient::getStatusData()
|
||||
{
|
||||
qDebug() << "Connecting to socket..";
|
||||
|
||||
connect(&m_socket, &QTcpSocket::connected, this, [this]() {
|
||||
@ -25,28 +26,28 @@ void McClient::getStatusData() {
|
||||
connect(&m_socket, &QTcpSocket::readyRead, this, &McClient::readRawResponse);
|
||||
});
|
||||
|
||||
connect(&m_socket, &QTcpSocket::errorOccurred, this, [this]() {
|
||||
emitFail("Socket disconnected: " + m_socket.errorString());
|
||||
});
|
||||
connect(&m_socket, &QTcpSocket::errorOccurred, this, [this]() { emitFail("Socket disconnected: " + m_socket.errorString()); });
|
||||
|
||||
m_socket.connectToHost(m_ip, m_port);
|
||||
}
|
||||
|
||||
void McClient::sendRequest() {
|
||||
void McClient::sendRequest()
|
||||
{
|
||||
QByteArray data;
|
||||
writeVarInt(data, 0x00); // packet ID
|
||||
writeVarInt(data, 763); // hardcoded protocol version (763 = 1.20.1)
|
||||
writeVarInt(data, m_domain.size()); // server address length
|
||||
writeString(data, m_domain.toStdString()); // server address
|
||||
writeFixedInt(data, m_port, 2); // server port
|
||||
writeVarInt(data, 0x01); // next state
|
||||
writePacketToSocket(data); // send handshake packet
|
||||
writeVarInt(data, 0x00); // packet ID
|
||||
writeVarInt(data, 763); // hardcoded protocol version (763 = 1.20.1)
|
||||
writeVarInt(data, m_domain.size()); // server address length
|
||||
writeString(data, m_domain.toStdString()); // server address
|
||||
writeFixedInt(data, m_port, 2); // server port
|
||||
writeVarInt(data, 0x01); // next state
|
||||
writePacketToSocket(data); // send handshake packet
|
||||
|
||||
writeVarInt(data, 0x00); // packet ID
|
||||
writePacketToSocket(data); // send status packet
|
||||
writeVarInt(data, 0x00); // packet ID
|
||||
writePacketToSocket(data); // send status packet
|
||||
}
|
||||
|
||||
void McClient::readRawResponse() {
|
||||
void McClient::readRawResponse()
|
||||
{
|
||||
if (m_responseReadState == 2) {
|
||||
return;
|
||||
}
|
||||
@ -59,25 +60,24 @@ void McClient::readRawResponse() {
|
||||
|
||||
if (m_responseReadState == 1 && m_resp.size() >= m_wantedRespLength) {
|
||||
if (m_resp.size() > m_wantedRespLength) {
|
||||
qDebug() << "Warning: Packet length doesn't match actual packet size (" << m_wantedRespLength << " expected vs " << m_resp.size() << " received)";
|
||||
qDebug() << "Warning: Packet length doesn't match actual packet size (" << m_wantedRespLength << " expected vs "
|
||||
<< m_resp.size() << " received)";
|
||||
}
|
||||
parseResponse();
|
||||
m_responseReadState = 2;
|
||||
}
|
||||
}
|
||||
|
||||
void McClient::parseResponse() {
|
||||
void McClient::parseResponse()
|
||||
{
|
||||
qDebug() << "Received response successfully";
|
||||
|
||||
int packetID = readVarInt(m_resp);
|
||||
if (packetID != 0x00) {
|
||||
throw Exception(
|
||||
QString("Packet ID doesn't match expected value (0x00 vs 0x%1)")
|
||||
.arg(packetID, 0, 16)
|
||||
);
|
||||
throw Exception(QString("Packet ID doesn't match expected value (0x00 vs 0x%1)").arg(packetID, 0, 16));
|
||||
}
|
||||
|
||||
Q_UNUSED(readVarInt(m_resp)); // json length
|
||||
Q_UNUSED(readVarInt(m_resp)); // json length
|
||||
|
||||
// 'resp' should now be the JSON string
|
||||
QJsonDocument doc = QJsonDocument::fromJson(m_resp);
|
||||
@ -85,8 +85,9 @@ void McClient::parseResponse() {
|
||||
}
|
||||
|
||||
// From https://wiki.vg/Protocol#VarInt_and_VarLong
|
||||
void McClient::writeVarInt(QByteArray &data, int value) {
|
||||
while ((value & ~SEGMENT_BITS)) { // check if the value is too big to fit in 7 bits
|
||||
void McClient::writeVarInt(QByteArray& data, int value)
|
||||
{
|
||||
while ((value & ~SEGMENT_BITS)) { // check if the value is too big to fit in 7 bits
|
||||
// Write 7 bits
|
||||
data.append((value & SEGMENT_BITS) | CONTINUE_BIT);
|
||||
|
||||
@ -98,7 +99,8 @@ void McClient::writeVarInt(QByteArray &data, int value) {
|
||||
}
|
||||
|
||||
// From https://wiki.vg/Protocol#VarInt_and_VarLong
|
||||
int McClient::readVarInt(QByteArray &data) {
|
||||
int McClient::readVarInt(QByteArray& data)
|
||||
{
|
||||
int value = 0;
|
||||
int position = 0;
|
||||
char currentByte;
|
||||
@ -107,17 +109,20 @@ int McClient::readVarInt(QByteArray &data) {
|
||||
currentByte = readByte(data);
|
||||
value |= (currentByte & SEGMENT_BITS) << position;
|
||||
|
||||
if ((currentByte & CONTINUE_BIT) == 0) break;
|
||||
if ((currentByte & CONTINUE_BIT) == 0)
|
||||
break;
|
||||
|
||||
position += 7;
|
||||
}
|
||||
|
||||
if (position >= 32) throw Exception("VarInt is too big");
|
||||
if (position >= 32)
|
||||
throw Exception("VarInt is too big");
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
char McClient::readByte(QByteArray &data) {
|
||||
char McClient::readByte(QByteArray& data)
|
||||
{
|
||||
if (data.isEmpty()) {
|
||||
throw Exception("No more bytes to read");
|
||||
}
|
||||
@ -128,17 +133,20 @@ char McClient::readByte(QByteArray &data) {
|
||||
}
|
||||
|
||||
// write number with specified size in big endian format
|
||||
void McClient::writeFixedInt(QByteArray &data, int value, int size) {
|
||||
void McClient::writeFixedInt(QByteArray& data, int value, int size)
|
||||
{
|
||||
for (int i = size - 1; i >= 0; i--) {
|
||||
data.append((value >> (i * 8)) & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
void McClient::writeString(QByteArray &data, const std::string &value) {
|
||||
void McClient::writeString(QByteArray& data, const std::string& value)
|
||||
{
|
||||
data.append(value.c_str());
|
||||
}
|
||||
|
||||
void McClient::writePacketToSocket(QByteArray &data) {
|
||||
void McClient::writePacketToSocket(QByteArray& data)
|
||||
{
|
||||
// we prefix the packet with its length
|
||||
QByteArray dataWithSize;
|
||||
writeVarInt(dataWithSize, data.size());
|
||||
@ -151,14 +159,15 @@ void McClient::writePacketToSocket(QByteArray &data) {
|
||||
data.clear();
|
||||
}
|
||||
|
||||
|
||||
void McClient::emitFail(QString error) {
|
||||
void McClient::emitFail(QString error)
|
||||
{
|
||||
qDebug() << "Minecraft server ping for status error:" << error;
|
||||
emit failed(error);
|
||||
emit finished();
|
||||
}
|
||||
|
||||
void McClient::emitSucceed(QJsonObject data) {
|
||||
void McClient::emitSucceed(QJsonObject data)
|
||||
{
|
||||
emit succeeded(data);
|
||||
emit finished();
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include <QObject>
|
||||
#include <QTcpSocket>
|
||||
#include <QFuture>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QFuture>
|
||||
#include <QObject>
|
||||
#include <QTcpSocket>
|
||||
|
||||
#include <Exception.h>
|
||||
|
||||
@ -22,29 +22,30 @@ class McClient : public QObject {
|
||||
unsigned m_wantedRespLength = 0;
|
||||
QByteArray m_resp;
|
||||
|
||||
public:
|
||||
explicit McClient(QObject *parent, QString domain, QString ip, short port);
|
||||
public:
|
||||
explicit McClient(QObject* parent, QString domain, QString ip, short port);
|
||||
//! Read status data of the server, and calls the succeeded() signal with the parsed JSON data
|
||||
void getStatusData();
|
||||
private:
|
||||
|
||||
private:
|
||||
void sendRequest();
|
||||
//! Accumulate data until we have a full response, then call parseResponse() once
|
||||
void readRawResponse();
|
||||
void parseResponse();
|
||||
|
||||
void writeVarInt(QByteArray &data, int value);
|
||||
int readVarInt(QByteArray &data);
|
||||
char readByte(QByteArray &data);
|
||||
void writeVarInt(QByteArray& data, int value);
|
||||
int readVarInt(QByteArray& data);
|
||||
char readByte(QByteArray& data);
|
||||
//! write number with specified size in big endian format
|
||||
void writeFixedInt(QByteArray &data, int value, int size);
|
||||
void writeString(QByteArray &data, const std::string &value);
|
||||
void writeFixedInt(QByteArray& data, int value, int size);
|
||||
void writeString(QByteArray& data, const std::string& value);
|
||||
|
||||
void writePacketToSocket(QByteArray &data);
|
||||
void writePacketToSocket(QByteArray& data);
|
||||
|
||||
void emitFail(QString error);
|
||||
void emitSucceed(QJsonObject data);
|
||||
|
||||
signals:
|
||||
signals:
|
||||
void succeeded(QJsonObject data);
|
||||
void failed(QString error);
|
||||
void finished();
|
||||
|
@ -1,23 +1,25 @@
|
||||
#include <QObject>
|
||||
#include <QDnsLookup>
|
||||
#include <QtNetwork/qtcpsocket.h>
|
||||
#include <QDnsLookup>
|
||||
#include <QHostInfo>
|
||||
#include <QObject>
|
||||
|
||||
#include "McResolver.h"
|
||||
|
||||
McResolver::McResolver(QObject *parent, QString domain, int port): QObject(parent), m_constrDomain(domain), m_constrPort(port) {}
|
||||
McResolver::McResolver(QObject* parent, QString domain, int port) : QObject(parent), m_constrDomain(domain), m_constrPort(port) {}
|
||||
|
||||
void McResolver::ping() {
|
||||
void McResolver::ping()
|
||||
{
|
||||
pingWithDomainSRV(m_constrDomain, m_constrPort);
|
||||
}
|
||||
|
||||
void McResolver::pingWithDomainSRV(QString domain, int port) {
|
||||
QDnsLookup *lookup = new QDnsLookup(this);
|
||||
void McResolver::pingWithDomainSRV(QString domain, int port)
|
||||
{
|
||||
QDnsLookup* lookup = new QDnsLookup(this);
|
||||
lookup->setName(QString("_minecraft._tcp.%1").arg(domain));
|
||||
lookup->setType(QDnsLookup::SRV);
|
||||
|
||||
connect(lookup, &QDnsLookup::finished, this, [this, domain, port]() {
|
||||
QDnsLookup *lookup = qobject_cast<QDnsLookup *>(sender());
|
||||
QDnsLookup* lookup = qobject_cast<QDnsLookup*>(sender());
|
||||
|
||||
lookup->deleteLater();
|
||||
|
||||
@ -43,8 +45,9 @@ void McResolver::pingWithDomainSRV(QString domain, int port) {
|
||||
lookup->lookup();
|
||||
}
|
||||
|
||||
void McResolver::pingWithDomainA(QString domain, int port) {
|
||||
QHostInfo::lookupHost(domain, this, [this, port](const QHostInfo &hostInfo){
|
||||
void McResolver::pingWithDomainA(QString domain, int port)
|
||||
{
|
||||
QHostInfo::lookupHost(domain, this, [this, port](const QHostInfo& hostInfo) {
|
||||
if (hostInfo.error() != QHostInfo::NoError) {
|
||||
emitFail("A record lookup failed");
|
||||
return;
|
||||
@ -61,13 +64,15 @@ void McResolver::pingWithDomainA(QString domain, int port) {
|
||||
});
|
||||
}
|
||||
|
||||
void McResolver::emitFail(QString error) {
|
||||
void McResolver::emitFail(QString error)
|
||||
{
|
||||
qDebug() << "DNS resolver error:" << error;
|
||||
emit failed(error);
|
||||
emit finished();
|
||||
}
|
||||
|
||||
void McResolver::emitSucceed(QString ip, int port) {
|
||||
void McResolver::emitSucceed(QString ip, int port)
|
||||
{
|
||||
emit succeeded(ip, port);
|
||||
emit finished();
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include <QtNetwork/qtcpsocket.h>
|
||||
#include <QDnsLookup>
|
||||
#include <QHostInfo>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QDnsLookup>
|
||||
#include <QtNetwork/qtcpsocket.h>
|
||||
#include <QHostInfo>
|
||||
|
||||
// resolve the IP and port of a Minecraft server
|
||||
class McResolver : public QObject {
|
||||
@ -11,17 +11,17 @@ class McResolver : public QObject {
|
||||
QString m_constrDomain;
|
||||
int m_constrPort;
|
||||
|
||||
public:
|
||||
explicit McResolver(QObject *parent, QString domain, int port);
|
||||
public:
|
||||
explicit McResolver(QObject* parent, QString domain, int port);
|
||||
void ping();
|
||||
|
||||
private:
|
||||
private:
|
||||
void pingWithDomainSRV(QString domain, int port);
|
||||
void pingWithDomainA(QString domain, int port);
|
||||
void emitFail(QString error);
|
||||
void emitSucceed(QString ip, int port);
|
||||
|
||||
signals:
|
||||
signals:
|
||||
void succeeded(QString ip, int port);
|
||||
void failed(QString error);
|
||||
void finished();
|
||||
|
@ -1,47 +1,41 @@
|
||||
#include <QFutureWatcher>
|
||||
|
||||
#include "ServerPingTask.h"
|
||||
#include "McResolver.h"
|
||||
#include "McClient.h"
|
||||
#include <Json.h>
|
||||
#include "McClient.h"
|
||||
#include "McResolver.h"
|
||||
#include "ServerPingTask.h"
|
||||
|
||||
unsigned getOnlinePlayers(QJsonObject data) {
|
||||
unsigned getOnlinePlayers(QJsonObject data)
|
||||
{
|
||||
return Json::requireInteger(Json::requireObject(data, "players"), "online");
|
||||
}
|
||||
|
||||
void ServerPingTask::executeTask() {
|
||||
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);
|
||||
McResolver* resolver = new McResolver(nullptr, m_domain, m_port);
|
||||
QObject::connect(resolver, &McResolver::succeeded, this, [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);
|
||||
McClient* client = new McClient(nullptr, m_domain, ip, port);
|
||||
|
||||
QObject::connect(client, &McClient::succeeded, this, [this](QJsonObject data) {
|
||||
m_outputOnlinePlayers = getOnlinePlayers(data);
|
||||
qDebug() << "Online players: " << m_outputOnlinePlayers;
|
||||
emitSucceeded();
|
||||
});
|
||||
QObject::connect(client, &McClient::failed, this, [this](QString error) {
|
||||
emitFailed(error);
|
||||
});
|
||||
QObject::connect(client, &McClient::failed, this, [this](QString error) { emitFailed(error); });
|
||||
|
||||
// Delete McClient object when done
|
||||
QObject::connect(client, &McClient::finished, this, [this, client]() {
|
||||
client->deleteLater();
|
||||
});
|
||||
QObject::connect(client, &McClient::finished, this, [this, client]() { client->deleteLater(); });
|
||||
client->getStatusData();
|
||||
});
|
||||
QObject::connect(resolver, &McResolver::failed, this, [this](QString error) {
|
||||
emitFailed(error);
|
||||
});
|
||||
QObject::connect(resolver, &McResolver::failed, this, [this](QString error) { emitFailed(error); });
|
||||
|
||||
// Delete McResolver object when done
|
||||
QObject::connect(resolver, &McResolver::finished, [resolver]() {
|
||||
resolver->deleteLater();
|
||||
});
|
||||
QObject::connect(resolver, &McResolver::finished, [resolver]() { resolver->deleteLater(); });
|
||||
resolver->ping();
|
||||
}
|
@ -5,18 +5,17 @@
|
||||
|
||||
#include <tasks/Task.h>
|
||||
|
||||
|
||||
class ServerPingTask : public Task {
|
||||
Q_OBJECT
|
||||
public:
|
||||
public:
|
||||
explicit ServerPingTask(QString domain, int port) : Task(), m_domain(domain), m_port(port) {}
|
||||
~ServerPingTask() override = default;
|
||||
int m_outputOnlinePlayers = -1;
|
||||
|
||||
private:
|
||||
private:
|
||||
QString m_domain;
|
||||
int m_port;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
virtual void executeTask() override;
|
||||
};
|
||||
|
@ -18,7 +18,8 @@
|
||||
|
||||
#include "HintOverrideProxyStyle.h"
|
||||
|
||||
HintOverrideProxyStyle::HintOverrideProxyStyle(QStyle* style) : QProxyStyle(style) {
|
||||
HintOverrideProxyStyle::HintOverrideProxyStyle(QStyle* style) : QProxyStyle(style)
|
||||
{
|
||||
setObjectName(style->objectName());
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user