Removed AuthRequest and NetAction
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
f15981d786
commit
3336f8107c
@ -126,7 +126,6 @@ set(NET_SOURCES
|
||||
net/MetaCacheSink.h
|
||||
net/Logging.h
|
||||
net/Logging.cpp
|
||||
net/NetAction.h
|
||||
net/NetJob.cpp
|
||||
net/NetJob.h
|
||||
net/NetUtils.h
|
||||
@ -212,8 +211,6 @@ set(MINECRAFT_SOURCES
|
||||
minecraft/auth/AccountList.h
|
||||
minecraft/auth/AccountTask.cpp
|
||||
minecraft/auth/AccountTask.h
|
||||
minecraft/auth/AuthRequest.cpp
|
||||
minecraft/auth/AuthRequest.h
|
||||
minecraft/auth/AuthSession.cpp
|
||||
minecraft/auth/AuthSession.h
|
||||
minecraft/auth/AuthStep.cpp
|
||||
@ -624,7 +621,6 @@ set(PRISMUPDATER_SOURCES
|
||||
net/HttpMetaCache.h
|
||||
net/Logging.h
|
||||
net/Logging.cpp
|
||||
net/NetAction.h
|
||||
net/NetRequest.cpp
|
||||
net/NetRequest.h
|
||||
net/NetJob.cpp
|
||||
|
@ -3,8 +3,6 @@
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
|
||||
InstanceCreationTask::InstanceCreationTask() = default;
|
||||
|
||||
void InstanceCreationTask::executeTask()
|
||||
{
|
||||
setAbortable(true);
|
||||
|
@ -6,7 +6,7 @@
|
||||
class InstanceCreationTask : public InstanceTask {
|
||||
Q_OBJECT
|
||||
public:
|
||||
InstanceCreationTask();
|
||||
InstanceCreationTask() = default;
|
||||
virtual ~InstanceCreationTask() = default;
|
||||
|
||||
protected:
|
||||
|
@ -51,6 +51,7 @@
|
||||
#include "net/Download.h"
|
||||
|
||||
#include "Application.h"
|
||||
#include "net/NetRequest.h"
|
||||
|
||||
namespace {
|
||||
QSet<QString> collectPathsFromDir(QString dirPath)
|
||||
@ -276,7 +277,7 @@ bool reconstructAssets(QString assetsId, QString resourcesFolder)
|
||||
|
||||
} // namespace AssetsUtils
|
||||
|
||||
NetAction::Ptr AssetObject::getDownloadAction()
|
||||
Net::NetRequest::Ptr AssetObject::getDownloadAction()
|
||||
{
|
||||
QFileInfo objectFile(getLocalPath());
|
||||
if ((!objectFile.isFile()) || (objectFile.size() != size)) {
|
||||
|
@ -17,14 +17,14 @@
|
||||
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
#include "net/NetAction.h"
|
||||
#include "net/NetJob.h"
|
||||
#include "net/NetRequest.h"
|
||||
|
||||
struct AssetObject {
|
||||
QString getRelPath();
|
||||
QUrl getUrl();
|
||||
QString getLocalPath();
|
||||
NetAction::Ptr getDownloadAction();
|
||||
Net::NetRequest::Ptr getDownloadAction();
|
||||
|
||||
QString hash;
|
||||
qint64 size;
|
||||
|
@ -35,6 +35,7 @@
|
||||
|
||||
#include "Library.h"
|
||||
#include "MinecraftInstance.h"
|
||||
#include "net/NetRequest.h"
|
||||
|
||||
#include <BuildConfig.h>
|
||||
#include <FileSystem.h>
|
||||
@ -74,12 +75,12 @@ void Library::getApplicableFiles(const RuntimeContext& runtimeContext,
|
||||
}
|
||||
}
|
||||
|
||||
QList<NetAction::Ptr> Library::getDownloads(const RuntimeContext& runtimeContext,
|
||||
QList<Net::NetRequest::Ptr> Library::getDownloads(const RuntimeContext& runtimeContext,
|
||||
class HttpMetaCache* cache,
|
||||
QStringList& failedLocalFiles,
|
||||
const QString& overridePath) const
|
||||
{
|
||||
QList<NetAction::Ptr> out;
|
||||
QList<Net::NetRequest::Ptr> out;
|
||||
bool stale = isAlwaysStale();
|
||||
bool local = isLocal();
|
||||
|
||||
|
@ -34,7 +34,6 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <net/NetAction.h>
|
||||
#include <QDir>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
@ -48,6 +47,7 @@
|
||||
#include "MojangDownloadInfo.h"
|
||||
#include "Rule.h"
|
||||
#include "RuntimeContext.h"
|
||||
#include "net/NetRequest.h"
|
||||
|
||||
class Library;
|
||||
class MinecraftInstance;
|
||||
@ -144,7 +144,7 @@ class Library {
|
||||
bool isForge() const;
|
||||
|
||||
// Get a list of downloads for this library
|
||||
QList<NetAction::Ptr> getDownloads(const RuntimeContext& runtimeContext,
|
||||
QList<Net::NetRequest::Ptr> getDownloads(const RuntimeContext& runtimeContext,
|
||||
class HttpMetaCache* cache,
|
||||
QStringList& failedLocalFiles,
|
||||
const QString& overridePath) const;
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "AccountList.h"
|
||||
#include "AccountData.h"
|
||||
#include "AccountTask.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
@ -639,8 +640,8 @@ void AccountList::tryNext()
|
||||
if (account->internalId() == accountId) {
|
||||
m_currentTask = account->refresh();
|
||||
if (m_currentTask) {
|
||||
connect(m_currentTask.get(), &AccountTask::succeeded, this, &AccountList::authSucceeded);
|
||||
connect(m_currentTask.get(), &AccountTask::failed, this, &AccountList::authFailed);
|
||||
connect(m_currentTask.get(), &Task::succeeded, this, &AccountList::authSucceeded);
|
||||
connect(m_currentTask.get(), &Task::failed, this, &AccountList::authFailed);
|
||||
m_currentTask->start();
|
||||
qDebug() << "RefreshSchedule: Processing account " << account->accountDisplayString() << " with internal ID "
|
||||
<< accountId;
|
||||
|
@ -1,175 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
*
|
||||
* Copyright 2013-2021 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QDebug>
|
||||
#include <QTimer>
|
||||
#include <QUrlQuery>
|
||||
|
||||
#include "Application.h"
|
||||
#include "AuthRequest.h"
|
||||
#include "katabasis/Globals.h"
|
||||
|
||||
AuthRequest::AuthRequest(QObject* parent) : QObject(parent) {}
|
||||
|
||||
AuthRequest::~AuthRequest() {}
|
||||
|
||||
void AuthRequest::get(const QNetworkRequest& req, int timeout /* = 60*1000*/)
|
||||
{
|
||||
setup(req, QNetworkAccessManager::GetOperation);
|
||||
reply_ = APPLICATION->network()->get(request_);
|
||||
status_ = Requesting;
|
||||
timedReplies_.add(new Katabasis::Reply(reply_, timeout));
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) // QNetworkReply::errorOccurred added in 5.15
|
||||
connect(reply_, &QNetworkReply::errorOccurred, this, &AuthRequest::onRequestError);
|
||||
#else // &QNetworkReply::error SIGNAL depricated
|
||||
connect(reply_, QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error), this, &AuthRequest::onRequestError);
|
||||
#endif
|
||||
connect(reply_, &QNetworkReply::finished, this, &AuthRequest::onRequestFinished);
|
||||
connect(reply_, &QNetworkReply::sslErrors, this, &AuthRequest::onSslErrors);
|
||||
}
|
||||
|
||||
void AuthRequest::post(const QNetworkRequest& req, const QByteArray& data, int timeout /* = 60*1000*/)
|
||||
{
|
||||
setup(req, QNetworkAccessManager::PostOperation);
|
||||
data_ = data;
|
||||
status_ = Requesting;
|
||||
reply_ = APPLICATION->network()->post(request_, data_);
|
||||
timedReplies_.add(new Katabasis::Reply(reply_, timeout));
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) // QNetworkReply::errorOccurred added in 5.15
|
||||
connect(reply_, &QNetworkReply::errorOccurred, this, &AuthRequest::onRequestError);
|
||||
#else // &QNetworkReply::error SIGNAL depricated
|
||||
connect(reply_, QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error), this, &AuthRequest::onRequestError);
|
||||
#endif
|
||||
connect(reply_, &QNetworkReply::finished, this, &AuthRequest::onRequestFinished);
|
||||
connect(reply_, &QNetworkReply::sslErrors, this, &AuthRequest::onSslErrors);
|
||||
connect(reply_, &QNetworkReply::uploadProgress, this, &AuthRequest::onUploadProgress);
|
||||
}
|
||||
|
||||
void AuthRequest::onRequestFinished()
|
||||
{
|
||||
if (status_ == Idle) {
|
||||
return;
|
||||
}
|
||||
if (reply_ != qobject_cast<QNetworkReply*>(sender())) {
|
||||
return;
|
||||
}
|
||||
httpStatus_ = reply_->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
finish();
|
||||
}
|
||||
|
||||
void AuthRequest::onRequestError(QNetworkReply::NetworkError error)
|
||||
{
|
||||
qWarning() << "AuthRequest::onRequestError: Error" << (int)error;
|
||||
if (status_ == Idle) {
|
||||
return;
|
||||
}
|
||||
if (reply_ != qobject_cast<QNetworkReply*>(sender())) {
|
||||
return;
|
||||
}
|
||||
errorString_ = reply_->errorString();
|
||||
httpStatus_ = reply_->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
error_ = error;
|
||||
qWarning() << "AuthRequest::onRequestError: Error string: " << errorString_;
|
||||
qWarning() << "AuthRequest::onRequestError: HTTP status" << httpStatus_
|
||||
<< reply_->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
|
||||
|
||||
// QTimer::singleShot(10, this, SLOT(finish()));
|
||||
}
|
||||
|
||||
void AuthRequest::onSslErrors(QList<QSslError> errors)
|
||||
{
|
||||
int i = 1;
|
||||
for (auto error : errors) {
|
||||
qCritical() << "LOGIN SSL Error #" << i << " : " << error.errorString();
|
||||
auto cert = error.certificate();
|
||||
qCritical() << "Certificate in question:\n" << cert.toText();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void AuthRequest::onUploadProgress(qint64 uploaded, qint64 total)
|
||||
{
|
||||
if (status_ == Idle) {
|
||||
qWarning() << "AuthRequest::onUploadProgress: No pending request";
|
||||
return;
|
||||
}
|
||||
if (reply_ != qobject_cast<QNetworkReply*>(sender())) {
|
||||
return;
|
||||
}
|
||||
// Restart timeout because request in progress
|
||||
Katabasis::Reply* o2Reply = timedReplies_.find(reply_);
|
||||
if (o2Reply) {
|
||||
o2Reply->start();
|
||||
}
|
||||
emit uploadProgress(uploaded, total);
|
||||
}
|
||||
|
||||
void AuthRequest::setup(const QNetworkRequest& req, QNetworkAccessManager::Operation operation, const QByteArray& verb)
|
||||
{
|
||||
request_ = req;
|
||||
operation_ = operation;
|
||||
url_ = req.url();
|
||||
|
||||
QUrl url = url_;
|
||||
request_.setUrl(url);
|
||||
|
||||
if (!verb.isEmpty()) {
|
||||
request_.setRawHeader(Katabasis::HTTP_HTTP_HEADER, verb);
|
||||
}
|
||||
|
||||
status_ = Requesting;
|
||||
error_ = QNetworkReply::NoError;
|
||||
errorString_.clear();
|
||||
httpStatus_ = 0;
|
||||
}
|
||||
|
||||
void AuthRequest::finish()
|
||||
{
|
||||
QByteArray data;
|
||||
if (status_ == Idle) {
|
||||
qWarning() << "AuthRequest::finish: No pending request";
|
||||
return;
|
||||
}
|
||||
data = reply_->readAll();
|
||||
status_ = Idle;
|
||||
timedReplies_.remove(reply_);
|
||||
reply_->disconnect(this);
|
||||
reply_->deleteLater();
|
||||
QList<QNetworkReply::RawHeaderPair> headers = reply_->rawHeaderPairs();
|
||||
emit finished(error_, data, headers);
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
#pragma once
|
||||
#include <QByteArray>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
|
||||
#include "katabasis/Reply.h"
|
||||
|
||||
/// Makes authentication requests.
|
||||
class AuthRequest : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AuthRequest(QObject* parent = 0);
|
||||
~AuthRequest();
|
||||
|
||||
public slots:
|
||||
void get(const QNetworkRequest& req, int timeout = 60 * 1000);
|
||||
void post(const QNetworkRequest& req, const QByteArray& data, int timeout = 60 * 1000);
|
||||
|
||||
signals:
|
||||
|
||||
/// Emitted when a request has been completed or failed.
|
||||
void finished(QNetworkReply::NetworkError error, QByteArray data, QList<QNetworkReply::RawHeaderPair> headers);
|
||||
|
||||
/// Emitted when an upload has progressed.
|
||||
void uploadProgress(qint64 bytesSent, qint64 bytesTotal);
|
||||
|
||||
protected slots:
|
||||
|
||||
/// Handle request finished.
|
||||
void onRequestFinished();
|
||||
|
||||
/// Handle request error.
|
||||
void onRequestError(QNetworkReply::NetworkError error);
|
||||
|
||||
/// Handle ssl errors.
|
||||
void onSslErrors(QList<QSslError> errors);
|
||||
|
||||
/// Finish the request, emit finished() signal.
|
||||
void finish();
|
||||
|
||||
/// Handle upload progress.
|
||||
void onUploadProgress(qint64 uploaded, qint64 total);
|
||||
|
||||
public:
|
||||
QNetworkReply::NetworkError error_;
|
||||
int httpStatus_ = 0;
|
||||
QString errorString_;
|
||||
|
||||
protected:
|
||||
void setup(const QNetworkRequest& request, QNetworkAccessManager::Operation operation, const QByteArray& verb = QByteArray());
|
||||
|
||||
enum Status { Idle, Requesting, ReRequesting };
|
||||
|
||||
QNetworkRequest request_;
|
||||
QByteArray data_;
|
||||
QNetworkReply* reply_;
|
||||
Status status_;
|
||||
QNetworkAccessManager::Operation operation_;
|
||||
QUrl url_;
|
||||
Katabasis::ReplyList timedReplies_;
|
||||
|
||||
QTimer* timer_;
|
||||
};
|
@ -1,5 +1,3 @@
|
||||
#include "AuthStep.h"
|
||||
|
||||
AuthStep::AuthStep(AccountData* data) : QObject(nullptr), m_data(data) {}
|
||||
|
||||
AuthStep::~AuthStep() noexcept = default;
|
||||
|
@ -15,13 +15,12 @@ class AuthStep : public QObject {
|
||||
|
||||
public:
|
||||
explicit AuthStep(AccountData* data);
|
||||
virtual ~AuthStep() noexcept;
|
||||
virtual ~AuthStep() noexcept = default;
|
||||
|
||||
virtual QString describe() = 0;
|
||||
|
||||
public slots:
|
||||
virtual void perform() = 0;
|
||||
virtual void rehydrate() = 0;
|
||||
|
||||
signals:
|
||||
void finished(AccountTaskState resultingState, QString message);
|
||||
|
@ -153,7 +153,7 @@ shared_qobject_ptr<AccountTask> MinecraftAccount::refresh()
|
||||
if (data.type == AccountType::MSA) {
|
||||
m_currentTask.reset(new MSASilent(&data));
|
||||
} else {
|
||||
m_currentTask.reset(new OfflineRefresh(&data));
|
||||
m_currentTask.reset(new OfflineLogin(&data));
|
||||
}
|
||||
|
||||
connect(m_currentTask.get(), &Task::succeeded, this, &MinecraftAccount::authSucceeded);
|
||||
|
@ -2,11 +2,6 @@
|
||||
|
||||
#include "minecraft/auth/steps/OfflineStep.h"
|
||||
|
||||
OfflineRefresh::OfflineRefresh(AccountData* data, QObject* parent) : AuthFlow(data, parent)
|
||||
{
|
||||
m_steps.append(makeShared<OfflineStep>(m_data));
|
||||
}
|
||||
|
||||
OfflineLogin::OfflineLogin(AccountData* data, QObject* parent) : AuthFlow(data, parent)
|
||||
{
|
||||
m_steps.append(makeShared<OfflineStep>(m_data));
|
||||
|
@ -1,12 +1,6 @@
|
||||
#pragma once
|
||||
#include "AuthFlow.h"
|
||||
|
||||
class OfflineRefresh : public AuthFlow {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit OfflineRefresh(AccountData* data, QObject* parent = 0);
|
||||
};
|
||||
|
||||
class OfflineLogin : public AuthFlow {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -1,16 +1,20 @@
|
||||
#include "EntitlementsStep.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QNetworkRequest>
|
||||
#include <QUrl>
|
||||
#include <QUuid>
|
||||
#include <memory>
|
||||
|
||||
#include "Application.h"
|
||||
#include "Logging.h"
|
||||
#include "minecraft/auth/AuthRequest.h"
|
||||
#include "minecraft/auth/Parsers.h"
|
||||
#include "net/Download.h"
|
||||
#include "net/StaticHeaderProxy.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
EntitlementsStep::EntitlementsStep(AccountData* data) : AuthStep(data) {}
|
||||
|
||||
EntitlementsStep::~EntitlementsStep() noexcept = default;
|
||||
|
||||
QString EntitlementsStep::describe()
|
||||
{
|
||||
return tr("Determining game ownership.");
|
||||
@ -19,35 +23,31 @@ QString EntitlementsStep::describe()
|
||||
void EntitlementsStep::perform()
|
||||
{
|
||||
auto uuid = QUuid::createUuid();
|
||||
m_entitlementsRequestId = uuid.toString().remove('{').remove('}');
|
||||
auto url = "https://api.minecraftservices.com/entitlements/license?requestId=" + m_entitlementsRequestId;
|
||||
QNetworkRequest request = QNetworkRequest(url);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
request.setRawHeader("Accept", "application/json");
|
||||
request.setRawHeader("Authorization", QString("Bearer %1").arg(m_data->yggdrasilToken.token).toUtf8());
|
||||
AuthRequest* requestor = new AuthRequest(this);
|
||||
connect(requestor, &AuthRequest::finished, this, &EntitlementsStep::onRequestDone);
|
||||
requestor->get(request);
|
||||
m_entitlements_request_id = uuid.toString().remove('{').remove('}');
|
||||
|
||||
QUrl url("https://api.minecraftservices.com/entitlements/license?requestId=" + m_entitlements_request_id);
|
||||
auto headers = QList<Net::HeaderPair>{ { "Content-Type", "application/json" },
|
||||
{ "Accept", "application/json" },
|
||||
{ "Authorization", QString("Bearer %1").arg(m_data->yggdrasilToken.token).toUtf8() } };
|
||||
|
||||
m_response.reset(new QByteArray());
|
||||
m_task = Net::Download::makeByteArray(url, m_response);
|
||||
m_task->addHeaderProxy(new Net::StaticHeaderProxy(headers));
|
||||
|
||||
connect(m_task.get(), &Task::finished, this, &EntitlementsStep::onRequestDone);
|
||||
|
||||
m_task->setNetwork(APPLICATION->network());
|
||||
m_task->start();
|
||||
qDebug() << "Getting entitlements...";
|
||||
}
|
||||
|
||||
void EntitlementsStep::rehydrate()
|
||||
void EntitlementsStep::onRequestDone()
|
||||
{
|
||||
// NOOP, for now. We only save bools and there's nothing to check.
|
||||
}
|
||||
|
||||
void EntitlementsStep::onRequestDone([[maybe_unused]] QNetworkReply::NetworkError error,
|
||||
QByteArray data,
|
||||
[[maybe_unused]] QList<QNetworkReply::RawHeaderPair> headers)
|
||||
{
|
||||
auto requestor = qobject_cast<AuthRequest*>(QObject::sender());
|
||||
requestor->deleteLater();
|
||||
|
||||
qCDebug(authCredentials()) << data;
|
||||
qCDebug(authCredentials()) << *m_response;
|
||||
|
||||
// TODO: check presence of same entitlementsRequestId?
|
||||
// TODO: validate JWTs?
|
||||
Parsers::parseMinecraftEntitlements(data, m_data->minecraftEntitlement);
|
||||
Parsers::parseMinecraftEntitlements(*m_response, m_data->minecraftEntitlement);
|
||||
|
||||
emit finished(AccountTaskState::STATE_WORKING, tr("Got entitlements"));
|
||||
}
|
||||
|
@ -1,24 +1,26 @@
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
#include <memory>
|
||||
|
||||
#include "QObjectPtr.h"
|
||||
#include "minecraft/auth/AuthStep.h"
|
||||
#include "net/Download.h"
|
||||
|
||||
class EntitlementsStep : public AuthStep {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit EntitlementsStep(AccountData* data);
|
||||
virtual ~EntitlementsStep() noexcept;
|
||||
virtual ~EntitlementsStep() noexcept = default;
|
||||
|
||||
void perform() override;
|
||||
void rehydrate() override;
|
||||
|
||||
QString describe() override;
|
||||
|
||||
private slots:
|
||||
void onRequestDone(QNetworkReply::NetworkError, QByteArray, QList<QNetworkReply::RawHeaderPair>);
|
||||
void onRequestDone();
|
||||
|
||||
private:
|
||||
QString m_entitlementsRequestId;
|
||||
QString m_entitlements_request_id;
|
||||
std::shared_ptr<QByteArray> m_response;
|
||||
Net::Download::Ptr m_task;
|
||||
};
|
||||
|
@ -3,13 +3,10 @@
|
||||
|
||||
#include <QNetworkRequest>
|
||||
|
||||
#include "minecraft/auth/AuthRequest.h"
|
||||
#include "minecraft/auth/Parsers.h"
|
||||
#include "Application.h"
|
||||
|
||||
GetSkinStep::GetSkinStep(AccountData* data) : AuthStep(data) {}
|
||||
|
||||
GetSkinStep::~GetSkinStep() noexcept = default;
|
||||
|
||||
QString GetSkinStep::describe()
|
||||
{
|
||||
return tr("Getting skin.");
|
||||
@ -17,25 +14,20 @@ QString GetSkinStep::describe()
|
||||
|
||||
void GetSkinStep::perform()
|
||||
{
|
||||
auto url = QUrl(m_data->minecraftProfile.skin.url);
|
||||
QNetworkRequest request = QNetworkRequest(url);
|
||||
AuthRequest* requestor = new AuthRequest(this);
|
||||
connect(requestor, &AuthRequest::finished, this, &GetSkinStep::onRequestDone);
|
||||
requestor->get(request);
|
||||
QUrl url(m_data->minecraftProfile.skin.url);
|
||||
|
||||
m_response.reset(new QByteArray());
|
||||
m_task = Net::Download::makeByteArray(url, m_response);
|
||||
|
||||
connect(m_task.get(), &Task::finished, this, &GetSkinStep::onRequestDone);
|
||||
|
||||
m_task->setNetwork(APPLICATION->network());
|
||||
m_task->start();
|
||||
}
|
||||
|
||||
void GetSkinStep::rehydrate()
|
||||
void GetSkinStep::onRequestDone()
|
||||
{
|
||||
// NOOP, for now.
|
||||
}
|
||||
|
||||
void GetSkinStep::onRequestDone(QNetworkReply::NetworkError error, QByteArray data, QList<QNetworkReply::RawHeaderPair> headers)
|
||||
{
|
||||
auto requestor = qobject_cast<AuthRequest*>(QObject::sender());
|
||||
requestor->deleteLater();
|
||||
|
||||
if (error == QNetworkReply::NoError) {
|
||||
m_data->minecraftProfile.skin.data = data;
|
||||
}
|
||||
if (m_task->error() == QNetworkReply::NoError)
|
||||
m_data->minecraftProfile.skin.data = *m_response;
|
||||
emit finished(AccountTaskState::STATE_SUCCEEDED, tr("Got skin"));
|
||||
}
|
||||
|
@ -1,21 +1,25 @@
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
#include <memory>
|
||||
|
||||
#include "QObjectPtr.h"
|
||||
#include "minecraft/auth/AuthStep.h"
|
||||
#include "net/Download.h"
|
||||
|
||||
class GetSkinStep : public AuthStep {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit GetSkinStep(AccountData* data);
|
||||
virtual ~GetSkinStep() noexcept;
|
||||
virtual ~GetSkinStep() noexcept = default;
|
||||
|
||||
void perform() override;
|
||||
void rehydrate() override;
|
||||
|
||||
QString describe() override;
|
||||
|
||||
private slots:
|
||||
void onRequestDone(QNetworkReply::NetworkError, QByteArray, QList<QNetworkReply::RawHeaderPair>);
|
||||
void onRequestDone();
|
||||
|
||||
private:
|
||||
std::shared_ptr<QByteArray> m_response;
|
||||
Net::Download::Ptr m_task;
|
||||
};
|
||||
|
@ -1,17 +1,18 @@
|
||||
#include "LauncherLoginStep.h"
|
||||
|
||||
#include <QNetworkRequest>
|
||||
#include <QUrl>
|
||||
|
||||
#include "Application.h"
|
||||
#include "Logging.h"
|
||||
#include "minecraft/auth/AccountTask.h"
|
||||
#include "minecraft/auth/AuthRequest.h"
|
||||
#include "minecraft/auth/Parsers.h"
|
||||
#include "net/NetUtils.h"
|
||||
#include "net/StaticHeaderProxy.h"
|
||||
#include "net/Upload.h"
|
||||
|
||||
LauncherLoginStep::LauncherLoginStep(AccountData* data) : AuthStep(data) {}
|
||||
|
||||
LauncherLoginStep::~LauncherLoginStep() noexcept = default;
|
||||
|
||||
QString LauncherLoginStep::describe()
|
||||
{
|
||||
return tr("Accessing Mojang services.");
|
||||
@ -19,7 +20,7 @@ QString LauncherLoginStep::describe()
|
||||
|
||||
void LauncherLoginStep::perform()
|
||||
{
|
||||
auto requestURL = "https://api.minecraftservices.com/launcher/login";
|
||||
QUrl url("https://api.minecraftservices.com/launcher/login");
|
||||
auto uhs = m_data->mojangservicesToken.extra["uhs"].toString();
|
||||
auto xToken = m_data->mojangservicesToken.token;
|
||||
|
||||
@ -31,40 +32,37 @@ void LauncherLoginStep::perform()
|
||||
)XXX";
|
||||
auto requestBody = mc_auth_template.arg(uhs, xToken);
|
||||
|
||||
QNetworkRequest request = QNetworkRequest(QUrl(requestURL));
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
request.setRawHeader("Accept", "application/json");
|
||||
AuthRequest* requestor = new AuthRequest(this);
|
||||
connect(requestor, &AuthRequest::finished, this, &LauncherLoginStep::onRequestDone);
|
||||
requestor->post(request, requestBody.toUtf8());
|
||||
auto headers = QList<Net::HeaderPair>{
|
||||
{ "Content-Type", "application/json" },
|
||||
{ "Accept", "application/json" },
|
||||
};
|
||||
|
||||
m_response.reset(new QByteArray());
|
||||
m_task = Net::Upload::makeByteArray(url, m_response, requestBody.toUtf8());
|
||||
m_task->addHeaderProxy(new Net::StaticHeaderProxy(headers));
|
||||
|
||||
connect(m_task.get(), &Task::finished, this, &LauncherLoginStep::onRequestDone);
|
||||
|
||||
m_task->setNetwork(APPLICATION->network());
|
||||
m_task->start();
|
||||
qDebug() << "Getting Minecraft access token...";
|
||||
}
|
||||
|
||||
void LauncherLoginStep::rehydrate()
|
||||
void LauncherLoginStep::onRequestDone()
|
||||
{
|
||||
// TODO: check the token validity
|
||||
}
|
||||
|
||||
void LauncherLoginStep::onRequestDone(QNetworkReply::NetworkError error, QByteArray data, QList<QNetworkReply::RawHeaderPair> headers)
|
||||
{
|
||||
auto requestor = qobject_cast<AuthRequest*>(QObject::sender());
|
||||
requestor->deleteLater();
|
||||
|
||||
qCDebug(authCredentials()) << data;
|
||||
if (error != QNetworkReply::NoError) {
|
||||
qWarning() << "Reply error:" << error;
|
||||
qCDebug(authCredentials()) << data;
|
||||
if (Net::isApplicationError(error)) {
|
||||
emit finished(AccountTaskState::STATE_FAILED_SOFT, tr("Failed to get Minecraft access token: %1").arg(requestor->errorString_));
|
||||
qCDebug(authCredentials()) << *m_response;
|
||||
if (m_task->error() != QNetworkReply::NoError) {
|
||||
qWarning() << "Reply error:" << m_task->error();
|
||||
if (Net::isApplicationError(m_task->error())) {
|
||||
emit finished(AccountTaskState::STATE_FAILED_SOFT, tr("Failed to get Minecraft access token: %1").arg(m_task->errorString()));
|
||||
} else {
|
||||
emit finished(AccountTaskState::STATE_OFFLINE, tr("Failed to get Minecraft access token: %1").arg(requestor->errorString_));
|
||||
emit finished(AccountTaskState::STATE_OFFLINE, tr("Failed to get Minecraft access token: %1").arg(m_task->errorString()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Parsers::parseMojangResponse(data, m_data->yggdrasilToken)) {
|
||||
if (!Parsers::parseMojangResponse(*m_response, m_data->yggdrasilToken)) {
|
||||
qWarning() << "Could not parse login_with_xbox response...";
|
||||
qCDebug(authCredentials()) << data;
|
||||
emit finished(AccountTaskState::STATE_FAILED_SOFT, tr("Failed to parse the Minecraft access token response."));
|
||||
return;
|
||||
}
|
||||
|
@ -1,21 +1,25 @@
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
#include <memory>
|
||||
|
||||
#include "QObjectPtr.h"
|
||||
#include "minecraft/auth/AuthStep.h"
|
||||
#include "net/Upload.h"
|
||||
|
||||
class LauncherLoginStep : public AuthStep {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LauncherLoginStep(AccountData* data);
|
||||
virtual ~LauncherLoginStep() noexcept;
|
||||
virtual ~LauncherLoginStep() noexcept = default;
|
||||
|
||||
void perform() override;
|
||||
void rehydrate() override;
|
||||
|
||||
QString describe() override;
|
||||
|
||||
private slots:
|
||||
void onRequestDone(QNetworkReply::NetworkError, QByteArray, QList<QNetworkReply::RawHeaderPair>);
|
||||
void onRequestDone();
|
||||
|
||||
private:
|
||||
std::shared_ptr<QByteArray> m_response;
|
||||
Net::Upload::Ptr m_task;
|
||||
};
|
||||
|
@ -37,10 +37,6 @@
|
||||
|
||||
#include <QNetworkRequest>
|
||||
|
||||
#include "BuildConfig.h"
|
||||
#include "minecraft/auth/AuthRequest.h"
|
||||
#include "minecraft/auth/Parsers.h"
|
||||
|
||||
#include "Application.h"
|
||||
#include "Logging.h"
|
||||
|
||||
@ -63,27 +59,11 @@ MSAStep::MSAStep(AccountData* data, Action action) : AuthStep(data), m_action(ac
|
||||
connect(m_oauth2, &OAuth2::showVerificationUriAndCode, this, &MSAStep::showVerificationUriAndCode);
|
||||
}
|
||||
|
||||
MSAStep::~MSAStep() noexcept = default;
|
||||
|
||||
QString MSAStep::describe()
|
||||
{
|
||||
return tr("Logging in with Microsoft account.");
|
||||
}
|
||||
|
||||
void MSAStep::rehydrate()
|
||||
{
|
||||
switch (m_action) {
|
||||
case Refresh: {
|
||||
// TODO: check the tokens and see if they are old (older than a day)
|
||||
return;
|
||||
}
|
||||
case Login: {
|
||||
// NOOP
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MSAStep::perform()
|
||||
{
|
||||
switch (m_action) {
|
||||
|
@ -48,10 +48,9 @@ class MSAStep : public AuthStep {
|
||||
|
||||
public:
|
||||
explicit MSAStep(AccountData* data, Action action);
|
||||
virtual ~MSAStep() noexcept;
|
||||
virtual ~MSAStep() noexcept = default;
|
||||
|
||||
void perform() override;
|
||||
void rehydrate() override;
|
||||
|
||||
QString describe() override;
|
||||
|
||||
|
@ -2,15 +2,13 @@
|
||||
|
||||
#include <QNetworkRequest>
|
||||
|
||||
#include "Logging.h"
|
||||
#include "minecraft/auth/AuthRequest.h"
|
||||
#include "Application.h"
|
||||
#include "minecraft/auth/Parsers.h"
|
||||
#include "net/NetUtils.h"
|
||||
#include "net/StaticHeaderProxy.h"
|
||||
|
||||
MinecraftProfileStep::MinecraftProfileStep(AccountData* data) : AuthStep(data) {}
|
||||
|
||||
MinecraftProfileStep::~MinecraftProfileStep() noexcept = default;
|
||||
|
||||
QString MinecraftProfileStep::describe()
|
||||
{
|
||||
return tr("Fetching the Minecraft profile.");
|
||||
@ -18,52 +16,47 @@ QString MinecraftProfileStep::describe()
|
||||
|
||||
void MinecraftProfileStep::perform()
|
||||
{
|
||||
auto url = QUrl("https://api.minecraftservices.com/minecraft/profile");
|
||||
QNetworkRequest request = QNetworkRequest(url);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
request.setRawHeader("Authorization", QString("Bearer %1").arg(m_data->yggdrasilToken.token).toUtf8());
|
||||
QUrl url("https://api.minecraftservices.com/minecraft/profile");
|
||||
auto headers = QList<Net::HeaderPair>{ { "Content-Type", "application/json" },
|
||||
{ "Accept", "application/json" },
|
||||
{ "Authorization", QString("Bearer %1").arg(m_data->yggdrasilToken.token).toUtf8() } };
|
||||
|
||||
AuthRequest* requestor = new AuthRequest(this);
|
||||
connect(requestor, &AuthRequest::finished, this, &MinecraftProfileStep::onRequestDone);
|
||||
requestor->get(request);
|
||||
m_response.reset(new QByteArray());
|
||||
m_task = Net::Download::makeByteArray(url, m_response);
|
||||
m_task->addHeaderProxy(new Net::StaticHeaderProxy(headers));
|
||||
|
||||
connect(m_task.get(), &Task::finished, this, &MinecraftProfileStep::onRequestDone);
|
||||
|
||||
m_task->setNetwork(APPLICATION->network());
|
||||
m_task->start();
|
||||
}
|
||||
|
||||
void MinecraftProfileStep::rehydrate()
|
||||
void MinecraftProfileStep::onRequestDone()
|
||||
{
|
||||
// NOOP, for now. We only save bools and there's nothing to check.
|
||||
}
|
||||
|
||||
void MinecraftProfileStep::onRequestDone(QNetworkReply::NetworkError error, QByteArray data, QList<QNetworkReply::RawHeaderPair> headers)
|
||||
{
|
||||
auto requestor = qobject_cast<AuthRequest*>(QObject::sender());
|
||||
requestor->deleteLater();
|
||||
|
||||
qCDebug(authCredentials()) << data;
|
||||
if (error == QNetworkReply::ContentNotFoundError) {
|
||||
if (m_task->error() == QNetworkReply::ContentNotFoundError) {
|
||||
// NOTE: Succeed even if we do not have a profile. This is a valid account state.
|
||||
m_data->minecraftProfile = MinecraftProfile();
|
||||
emit finished(AccountTaskState::STATE_SUCCEEDED, tr("Account has no Minecraft profile."));
|
||||
return;
|
||||
}
|
||||
if (error != QNetworkReply::NoError) {
|
||||
if (m_task->error() != QNetworkReply::NoError) {
|
||||
qWarning() << "Error getting profile:";
|
||||
qWarning() << " HTTP Status: " << requestor->httpStatus_;
|
||||
qWarning() << " Internal error no.: " << error;
|
||||
qWarning() << " Error string: " << requestor->errorString_;
|
||||
qWarning() << " HTTP Status: " << m_task->replyStatusCode();
|
||||
qWarning() << " Internal error no.: " << m_task->error();
|
||||
qWarning() << " Error string: " << m_task->errorString();
|
||||
|
||||
qWarning() << " Response:";
|
||||
qWarning() << QString::fromUtf8(data);
|
||||
qWarning() << QString::fromUtf8(*m_response);
|
||||
|
||||
if (Net::isApplicationError(error)) {
|
||||
if (Net::isApplicationError(m_task->error())) {
|
||||
emit finished(AccountTaskState::STATE_FAILED_SOFT,
|
||||
tr("Minecraft Java profile acquisition failed: %1").arg(requestor->errorString_));
|
||||
tr("Minecraft Java profile acquisition failed: %1").arg(m_task->errorString()));
|
||||
} else {
|
||||
emit finished(AccountTaskState::STATE_OFFLINE,
|
||||
tr("Minecraft Java profile acquisition failed: %1").arg(requestor->errorString_));
|
||||
emit finished(AccountTaskState::STATE_OFFLINE, tr("Minecraft Java profile acquisition failed: %1").arg(m_task->errorString()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!Parsers::parseMinecraftProfile(data, m_data->minecraftProfile)) {
|
||||
if (!Parsers::parseMinecraftProfile(*m_response, m_data->minecraftProfile)) {
|
||||
m_data->minecraftProfile = MinecraftProfile();
|
||||
emit finished(AccountTaskState::STATE_FAILED_SOFT, tr("Minecraft Java profile response could not be parsed"));
|
||||
return;
|
||||
|
@ -1,21 +1,25 @@
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
#include <memory>
|
||||
|
||||
#include "QObjectPtr.h"
|
||||
#include "minecraft/auth/AuthStep.h"
|
||||
#include "net/Download.h"
|
||||
|
||||
class MinecraftProfileStep : public AuthStep {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MinecraftProfileStep(AccountData* data);
|
||||
virtual ~MinecraftProfileStep() noexcept;
|
||||
virtual ~MinecraftProfileStep() noexcept = default;
|
||||
|
||||
void perform() override;
|
||||
void rehydrate() override;
|
||||
|
||||
QString describe() override;
|
||||
|
||||
private slots:
|
||||
void onRequestDone(QNetworkReply::NetworkError, QByteArray, QList<QNetworkReply::RawHeaderPair>);
|
||||
void onRequestDone();
|
||||
|
||||
private:
|
||||
std::shared_ptr<QByteArray> m_response;
|
||||
Net::Download::Ptr m_task;
|
||||
};
|
||||
|
@ -1,20 +1,12 @@
|
||||
#include "OfflineStep.h"
|
||||
|
||||
#include "Application.h"
|
||||
|
||||
OfflineStep::OfflineStep(AccountData* data) : AuthStep(data) {}
|
||||
OfflineStep::~OfflineStep() noexcept = default;
|
||||
|
||||
QString OfflineStep::describe()
|
||||
{
|
||||
return tr("Creating offline account.");
|
||||
}
|
||||
|
||||
void OfflineStep::rehydrate()
|
||||
{
|
||||
// NOOP
|
||||
}
|
||||
|
||||
void OfflineStep::perform()
|
||||
{
|
||||
emit finished(AccountTaskState::STATE_WORKING, tr("Created offline account."));
|
||||
|
@ -1,19 +1,15 @@
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
|
||||
#include "QObjectPtr.h"
|
||||
#include "minecraft/auth/AuthStep.h"
|
||||
|
||||
#include <katabasis/DeviceFlow.h>
|
||||
|
||||
class OfflineStep : public AuthStep {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit OfflineStep(AccountData* data);
|
||||
virtual ~OfflineStep() noexcept;
|
||||
virtual ~OfflineStep() noexcept = default;
|
||||
|
||||
void perform() override;
|
||||
void rehydrate() override;
|
||||
|
||||
QString describe() override;
|
||||
};
|
||||
|
@ -4,27 +4,22 @@
|
||||
#include <QJsonParseError>
|
||||
#include <QNetworkRequest>
|
||||
|
||||
#include "Application.h"
|
||||
#include "Logging.h"
|
||||
#include "minecraft/auth/AuthRequest.h"
|
||||
#include "minecraft/auth/Parsers.h"
|
||||
#include "net/NetUtils.h"
|
||||
#include "net/StaticHeaderProxy.h"
|
||||
#include "net/Upload.h"
|
||||
|
||||
XboxAuthorizationStep::XboxAuthorizationStep(AccountData* data, Katabasis::Token* token, QString relyingParty, QString authorizationKind)
|
||||
: AuthStep(data), m_token(token), m_relyingParty(relyingParty), m_authorizationKind(authorizationKind)
|
||||
{}
|
||||
|
||||
XboxAuthorizationStep::~XboxAuthorizationStep() noexcept = default;
|
||||
|
||||
QString XboxAuthorizationStep::describe()
|
||||
{
|
||||
return tr("Getting authorization to access %1 services.").arg(m_authorizationKind);
|
||||
}
|
||||
|
||||
void XboxAuthorizationStep::rehydrate()
|
||||
{
|
||||
// FIXME: check if the tokens are good?
|
||||
}
|
||||
|
||||
void XboxAuthorizationStep::perform()
|
||||
{
|
||||
QString xbox_auth_template = R"XXX(
|
||||
@ -41,40 +36,44 @@ void XboxAuthorizationStep::perform()
|
||||
)XXX";
|
||||
auto xbox_auth_data = xbox_auth_template.arg(m_data->userToken.token, m_relyingParty);
|
||||
// http://xboxlive.com
|
||||
QNetworkRequest request = QNetworkRequest(QUrl("https://xsts.auth.xboxlive.com/xsts/authorize"));
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
request.setRawHeader("Accept", "application/json");
|
||||
AuthRequest* requestor = new AuthRequest(this);
|
||||
connect(requestor, &AuthRequest::finished, this, &XboxAuthorizationStep::onRequestDone);
|
||||
requestor->post(request, xbox_auth_data.toUtf8());
|
||||
QUrl url("https://xsts.auth.xboxlive.com/xsts/authorize");
|
||||
auto headers = QList<Net::HeaderPair>{
|
||||
{ "Content-Type", "application/json" },
|
||||
{ "Accept", "application/json" },
|
||||
};
|
||||
m_response.reset(new QByteArray());
|
||||
m_task = Net::Upload::makeByteArray(url, m_response, xbox_auth_data.toUtf8());
|
||||
m_task->addHeaderProxy(new Net::StaticHeaderProxy(headers));
|
||||
|
||||
connect(m_task.get(), &Task::finished, this, &XboxAuthorizationStep::onRequestDone);
|
||||
|
||||
m_task->setNetwork(APPLICATION->network());
|
||||
m_task->start();
|
||||
qDebug() << "Getting authorization token for " << m_relyingParty;
|
||||
}
|
||||
|
||||
void XboxAuthorizationStep::onRequestDone(QNetworkReply::NetworkError error, QByteArray data, QList<QNetworkReply::RawHeaderPair> headers)
|
||||
void XboxAuthorizationStep::onRequestDone()
|
||||
{
|
||||
auto requestor = qobject_cast<AuthRequest*>(QObject::sender());
|
||||
requestor->deleteLater();
|
||||
|
||||
qCDebug(authCredentials()) << data;
|
||||
if (error != QNetworkReply::NoError) {
|
||||
qWarning() << "Reply error:" << error;
|
||||
if (Net::isApplicationError(error)) {
|
||||
if (!processSTSError(error, data, headers)) {
|
||||
qCDebug(authCredentials()) << *m_response;
|
||||
if (m_task->error() != QNetworkReply::NoError) {
|
||||
qWarning() << "Reply error:" << m_task->error();
|
||||
if (Net::isApplicationError(m_task->error())) {
|
||||
if (!processSTSError()) {
|
||||
emit finished(AccountTaskState::STATE_FAILED_SOFT,
|
||||
tr("Failed to get authorization for %1 services. Error %2.").arg(m_authorizationKind, error));
|
||||
tr("Failed to get authorization for %1 services. Error %2.").arg(m_authorizationKind, m_task->error()));
|
||||
} else {
|
||||
emit finished(AccountTaskState::STATE_FAILED_SOFT,
|
||||
tr("Unknown STS error for %1 services: %2").arg(m_authorizationKind, requestor->errorString_));
|
||||
tr("Unknown STS error for %1 services: %2").arg(m_authorizationKind, m_task->errorString()));
|
||||
}
|
||||
} else {
|
||||
emit finished(AccountTaskState::STATE_OFFLINE,
|
||||
tr("Failed to get authorization for %1 services: %2").arg(m_authorizationKind, requestor->errorString_));
|
||||
tr("Failed to get authorization for %1 services: %2").arg(m_authorizationKind, m_task->errorString()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Katabasis::Token temp;
|
||||
if (!Parsers::parseXTokenResponse(data, temp, m_authorizationKind)) {
|
||||
if (!Parsers::parseXTokenResponse(*m_response, temp, m_authorizationKind)) {
|
||||
emit finished(AccountTaskState::STATE_FAILED_SOFT,
|
||||
tr("Could not parse authorization response for access to %1 services.").arg(m_authorizationKind));
|
||||
return;
|
||||
@ -91,11 +90,11 @@ void XboxAuthorizationStep::onRequestDone(QNetworkReply::NetworkError error, QBy
|
||||
emit finished(AccountTaskState::STATE_WORKING, tr("Got authorization to access %1").arg(m_relyingParty));
|
||||
}
|
||||
|
||||
bool XboxAuthorizationStep::processSTSError(QNetworkReply::NetworkError error, QByteArray data, QList<QNetworkReply::RawHeaderPair> headers)
|
||||
bool XboxAuthorizationStep::processSTSError()
|
||||
{
|
||||
if (error == QNetworkReply::AuthenticationRequiredError) {
|
||||
if (m_task->error() == QNetworkReply::AuthenticationRequiredError) {
|
||||
QJsonParseError jsonError;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(data, &jsonError);
|
||||
QJsonDocument doc = QJsonDocument::fromJson(*m_response, &jsonError);
|
||||
if (jsonError.error) {
|
||||
qWarning() << "Cannot parse error XSTS response as JSON: " << jsonError.errorString();
|
||||
emit finished(AccountTaskState::STATE_FAILED_SOFT,
|
||||
|
@ -1,29 +1,32 @@
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
#include <memory>
|
||||
|
||||
#include "QObjectPtr.h"
|
||||
#include "minecraft/auth/AuthStep.h"
|
||||
#include "net/Upload.h"
|
||||
|
||||
class XboxAuthorizationStep : public AuthStep {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit XboxAuthorizationStep(AccountData* data, Katabasis::Token* token, QString relyingParty, QString authorizationKind);
|
||||
virtual ~XboxAuthorizationStep() noexcept;
|
||||
virtual ~XboxAuthorizationStep() noexcept = default;
|
||||
|
||||
void perform() override;
|
||||
void rehydrate() override;
|
||||
|
||||
QString describe() override;
|
||||
|
||||
private:
|
||||
bool processSTSError(QNetworkReply::NetworkError error, QByteArray data, QList<QNetworkReply::RawHeaderPair> headers);
|
||||
bool processSTSError();
|
||||
|
||||
private slots:
|
||||
void onRequestDone(QNetworkReply::NetworkError, QByteArray, QList<QNetworkReply::RawHeaderPair>);
|
||||
void onRequestDone();
|
||||
|
||||
private:
|
||||
Katabasis::Token* m_token;
|
||||
QString m_relyingParty;
|
||||
QString m_authorizationKind;
|
||||
|
||||
std::shared_ptr<QByteArray> m_response;
|
||||
Net::Upload::Ptr m_task;
|
||||
};
|
||||
|
@ -3,28 +3,21 @@
|
||||
#include <QNetworkRequest>
|
||||
#include <QUrlQuery>
|
||||
|
||||
#include "Application.h"
|
||||
#include "Logging.h"
|
||||
#include "minecraft/auth/AuthRequest.h"
|
||||
#include "minecraft/auth/Parsers.h"
|
||||
#include "net/NetUtils.h"
|
||||
#include "net/StaticHeaderProxy.h"
|
||||
|
||||
XboxProfileStep::XboxProfileStep(AccountData* data) : AuthStep(data) {}
|
||||
|
||||
XboxProfileStep::~XboxProfileStep() noexcept = default;
|
||||
|
||||
QString XboxProfileStep::describe()
|
||||
{
|
||||
return tr("Fetching Xbox profile.");
|
||||
}
|
||||
|
||||
void XboxProfileStep::rehydrate()
|
||||
{
|
||||
// NOOP, for now. We only save bools and there's nothing to check.
|
||||
}
|
||||
|
||||
void XboxProfileStep::perform()
|
||||
{
|
||||
auto url = QUrl("https://profile.xboxlive.com/users/me/profile/settings");
|
||||
QUrl url("https://profile.xboxlive.com/users/me/profile/settings");
|
||||
QUrlQuery q;
|
||||
q.addQueryItem("settings",
|
||||
"GameDisplayName,AppDisplayName,AppDisplayPicRaw,GameDisplayPicRaw,"
|
||||
@ -33,36 +26,38 @@ void XboxProfileStep::perform()
|
||||
"PreferredColor,Location,Bio,Watermarks,"
|
||||
"RealName,RealNameOverride,IsQuarantined");
|
||||
url.setQuery(q);
|
||||
auto headers = QList<Net::HeaderPair>{
|
||||
{ "Content-Type", "application/json" },
|
||||
{ "Accept", "application/json" },
|
||||
{ "x-xbl-contract-version", "3" },
|
||||
{ "Authorization", QString("XBL3.0 x=%1;%2").arg(m_data->userToken.extra["uhs"].toString(), m_data->xboxApiToken.token).toUtf8() }
|
||||
};
|
||||
|
||||
QNetworkRequest request = QNetworkRequest(url);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
request.setRawHeader("Accept", "application/json");
|
||||
request.setRawHeader("x-xbl-contract-version", "3");
|
||||
request.setRawHeader("Authorization",
|
||||
QString("XBL3.0 x=%1;%2").arg(m_data->userToken.extra["uhs"].toString(), m_data->xboxApiToken.token).toUtf8());
|
||||
AuthRequest* requestor = new AuthRequest(this);
|
||||
connect(requestor, &AuthRequest::finished, this, &XboxProfileStep::onRequestDone);
|
||||
requestor->get(request);
|
||||
m_response.reset(new QByteArray());
|
||||
m_task = Net::Download::makeByteArray(url, m_response);
|
||||
m_task->addHeaderProxy(new Net::StaticHeaderProxy(headers));
|
||||
|
||||
connect(m_task.get(), &Task::finished, this, &XboxProfileStep::onRequestDone);
|
||||
|
||||
m_task->setNetwork(APPLICATION->network());
|
||||
m_task->start();
|
||||
qDebug() << "Getting Xbox profile...";
|
||||
}
|
||||
|
||||
void XboxProfileStep::onRequestDone(QNetworkReply::NetworkError error, QByteArray data, QList<QNetworkReply::RawHeaderPair> headers)
|
||||
void XboxProfileStep::onRequestDone()
|
||||
{
|
||||
auto requestor = qobject_cast<AuthRequest*>(QObject::sender());
|
||||
requestor->deleteLater();
|
||||
|
||||
if (error != QNetworkReply::NoError) {
|
||||
qWarning() << "Reply error:" << error;
|
||||
qCDebug(authCredentials()) << data;
|
||||
if (Net::isApplicationError(error)) {
|
||||
emit finished(AccountTaskState::STATE_FAILED_SOFT, tr("Failed to retrieve the Xbox profile: %1").arg(requestor->errorString_));
|
||||
if (m_task->error() != QNetworkReply::NoError) {
|
||||
qWarning() << "Reply error:" << m_task->error();
|
||||
qCDebug(authCredentials()) << *m_response;
|
||||
if (Net::isApplicationError(m_task->error())) {
|
||||
emit finished(AccountTaskState::STATE_FAILED_SOFT, tr("Failed to retrieve the Xbox profile: %1").arg(m_task->errorString()));
|
||||
} else {
|
||||
emit finished(AccountTaskState::STATE_OFFLINE, tr("Failed to retrieve the Xbox profile: %1").arg(requestor->errorString_));
|
||||
emit finished(AccountTaskState::STATE_OFFLINE, tr("Failed to retrieve the Xbox profile: %1").arg(m_task->errorString()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
qCDebug(authCredentials()) << "XBox profile: " << data;
|
||||
qCDebug(authCredentials()) << "XBox profile: " << *m_response;
|
||||
|
||||
emit finished(AccountTaskState::STATE_WORKING, tr("Got Xbox profile"));
|
||||
}
|
||||
|
@ -1,21 +1,25 @@
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
#include <memory>
|
||||
|
||||
#include "QObjectPtr.h"
|
||||
#include "minecraft/auth/AuthStep.h"
|
||||
#include "net/Download.h"
|
||||
|
||||
class XboxProfileStep : public AuthStep {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit XboxProfileStep(AccountData* data);
|
||||
virtual ~XboxProfileStep() noexcept;
|
||||
virtual ~XboxProfileStep() noexcept = default;
|
||||
|
||||
void perform() override;
|
||||
void rehydrate() override;
|
||||
|
||||
QString describe() override;
|
||||
|
||||
private slots:
|
||||
void onRequestDone(QNetworkReply::NetworkError, QByteArray, QList<QNetworkReply::RawHeaderPair>);
|
||||
void onRequestDone();
|
||||
|
||||
private:
|
||||
std::shared_ptr<QByteArray> m_response;
|
||||
Net::Download::Ptr m_task;
|
||||
};
|
||||
|
@ -2,24 +2,18 @@
|
||||
|
||||
#include <QNetworkRequest>
|
||||
|
||||
#include "minecraft/auth/AuthRequest.h"
|
||||
#include "Application.h"
|
||||
#include "minecraft/auth/Parsers.h"
|
||||
#include "net/NetUtils.h"
|
||||
#include "net/StaticHeaderProxy.h"
|
||||
|
||||
XboxUserStep::XboxUserStep(AccountData* data) : AuthStep(data) {}
|
||||
|
||||
XboxUserStep::~XboxUserStep() noexcept = default;
|
||||
|
||||
QString XboxUserStep::describe()
|
||||
{
|
||||
return tr("Logging in as an Xbox user.");
|
||||
}
|
||||
|
||||
void XboxUserStep::rehydrate()
|
||||
{
|
||||
// NOOP, for now. We only save bools and there's nothing to check.
|
||||
}
|
||||
|
||||
void XboxUserStep::perform()
|
||||
{
|
||||
QString xbox_auth_template = R"XXX(
|
||||
@ -35,36 +29,39 @@ void XboxUserStep::perform()
|
||||
)XXX";
|
||||
auto xbox_auth_data = xbox_auth_template.arg(m_data->msaToken.token);
|
||||
|
||||
QNetworkRequest request = QNetworkRequest(QUrl("https://user.auth.xboxlive.com/user/authenticate"));
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
request.setRawHeader("Accept", "application/json");
|
||||
QUrl url("https://user.auth.xboxlive.com/user/authenticate");
|
||||
auto headers = QList<Net::HeaderPair>{
|
||||
{ "Content-Type", "application/json" },
|
||||
{ "Accept", "application/json" },
|
||||
// set contract-version header (prevent err 400 bad-request?)
|
||||
// https://learn.microsoft.com/en-us/gaming/gdk/_content/gc/reference/live/rest/additional/httpstandardheaders
|
||||
request.setRawHeader("x-xbl-contract-version", "1");
|
||||
{ "x-xbl-contract-version", "1" }
|
||||
};
|
||||
m_response.reset(new QByteArray());
|
||||
m_task = Net::Upload::makeByteArray(url, m_response, xbox_auth_data.toUtf8());
|
||||
m_task->addHeaderProxy(new Net::StaticHeaderProxy(headers));
|
||||
|
||||
auto* requestor = new AuthRequest(this);
|
||||
connect(requestor, &AuthRequest::finished, this, &XboxUserStep::onRequestDone);
|
||||
requestor->post(request, xbox_auth_data.toUtf8());
|
||||
connect(m_task.get(), &Task::finished, this, &XboxUserStep::onRequestDone);
|
||||
|
||||
m_task->setNetwork(APPLICATION->network());
|
||||
m_task->start();
|
||||
qDebug() << "First layer of XBox auth ... commencing.";
|
||||
}
|
||||
|
||||
void XboxUserStep::onRequestDone(QNetworkReply::NetworkError error, QByteArray data, QList<QNetworkReply::RawHeaderPair> headers)
|
||||
void XboxUserStep::onRequestDone()
|
||||
{
|
||||
auto requestor = qobject_cast<AuthRequest*>(QObject::sender());
|
||||
requestor->deleteLater();
|
||||
|
||||
if (error != QNetworkReply::NoError) {
|
||||
qWarning() << "Reply error:" << error;
|
||||
if (Net::isApplicationError(error)) {
|
||||
emit finished(AccountTaskState::STATE_FAILED_SOFT, tr("XBox user authentication failed: %1").arg(requestor->errorString_));
|
||||
if (m_task->error() != QNetworkReply::NoError) {
|
||||
qWarning() << "Reply error:" << m_task->error();
|
||||
if (Net::isApplicationError(m_task->error())) {
|
||||
emit finished(AccountTaskState::STATE_FAILED_SOFT, tr("XBox user authentication failed: %1").arg(m_task->errorString()));
|
||||
} else {
|
||||
emit finished(AccountTaskState::STATE_OFFLINE, tr("XBox user authentication failed: %1").arg(requestor->errorString_));
|
||||
emit finished(AccountTaskState::STATE_OFFLINE, tr("XBox user authentication failed: %1").arg(m_task->errorString()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Katabasis::Token temp;
|
||||
if (!Parsers::parseXTokenResponse(data, temp, "UToken")) {
|
||||
if (!Parsers::parseXTokenResponse(*m_response, temp, "UToken")) {
|
||||
qWarning() << "Could not parse user authentication response...";
|
||||
emit finished(AccountTaskState::STATE_FAILED_SOFT, tr("XBox user authentication response could not be understood."));
|
||||
return;
|
||||
|
@ -1,21 +1,25 @@
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
#include <memory>
|
||||
|
||||
#include "QObjectPtr.h"
|
||||
#include "minecraft/auth/AuthStep.h"
|
||||
#include "net/Upload.h"
|
||||
|
||||
class XboxUserStep : public AuthStep {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit XboxUserStep(AccountData* data);
|
||||
virtual ~XboxUserStep() noexcept;
|
||||
virtual ~XboxUserStep() noexcept = default;
|
||||
|
||||
void perform() override;
|
||||
void rehydrate() override;
|
||||
|
||||
QString describe() override;
|
||||
|
||||
private slots:
|
||||
void onRequestDone(QNetworkReply::NetworkError, QByteArray, QList<QNetworkReply::RawHeaderPair>);
|
||||
void onRequestDone();
|
||||
|
||||
private:
|
||||
std::shared_ptr<QByteArray> m_response;
|
||||
Net::Upload::Ptr m_task;
|
||||
};
|
||||
|
@ -45,8 +45,8 @@ Task::Ptr NetworkResourceAPI::searchProjects(SearchArgs&& args, SearchCallbacks&
|
||||
|
||||
QObject::connect(netJob.get(), &NetJob::failed, [netJob, callbacks](const QString& reason) {
|
||||
int network_error_code = -1;
|
||||
if (auto* failed_action = netJob->getFailedActions().at(0); failed_action && failed_action->m_reply)
|
||||
network_error_code = failed_action->m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
if (auto* failed_action = netJob->getFailedActions().at(0); failed_action)
|
||||
network_error_code = failed_action->replyStatusCode();
|
||||
|
||||
callbacks.on_fail(reason, network_error_code);
|
||||
});
|
||||
@ -104,8 +104,8 @@ Task::Ptr NetworkResourceAPI::getProjectVersions(VersionSearchArgs&& args, Versi
|
||||
});
|
||||
QObject::connect(netJob.get(), &NetJob::failed, [netJob, callbacks](const QString& reason) {
|
||||
int network_error_code = -1;
|
||||
if (auto* failed_action = netJob->getFailedActions().at(0); failed_action && failed_action->m_reply)
|
||||
network_error_code = failed_action->m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
if (auto* failed_action = netJob->getFailedActions().at(0); failed_action)
|
||||
network_error_code = failed_action->replyStatusCode();
|
||||
|
||||
callbacks.on_fail(reason, network_error_code);
|
||||
});
|
||||
@ -155,8 +155,8 @@ Task::Ptr NetworkResourceAPI::getDependencyVersion(DependencySearchArgs&& args,
|
||||
});
|
||||
QObject::connect(netJob.get(), &NetJob::failed, [netJob, callbacks](const QString& reason) {
|
||||
int network_error_code = -1;
|
||||
if (auto* failed_action = netJob->getFailedActions().at(0); failed_action && failed_action->m_reply)
|
||||
network_error_code = failed_action->m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
if (auto* failed_action = netJob->getFailedActions().at(0); failed_action)
|
||||
network_error_code = failed_action->replyStatusCode();
|
||||
|
||||
callbacks.on_fail(reason, network_error_code);
|
||||
});
|
||||
|
@ -261,7 +261,7 @@ bool ModrinthCreationTask::createInstance()
|
||||
// FIXME: This really needs to be put into a ConcurrentTask of
|
||||
// MultipleOptionsTask's , once those exist :)
|
||||
auto param = dl.toWeakRef();
|
||||
connect(dl.get(), &NetAction::failed, [this, &file, file_path, param] {
|
||||
connect(dl.get(), &Task::failed, [this, &file, file_path, param] {
|
||||
auto ndl = Net::ApiDownload::makeFile(file.downloads.dequeue(), file_path);
|
||||
ndl->addValidator(new Net::ChecksumValidator(file.hashAlgorithm, file.hash));
|
||||
m_files_job->addNetAction(ndl);
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "ByteArraySink.h"
|
||||
#include "ChecksumValidator.h"
|
||||
#include "MetaCacheSink.h"
|
||||
#include "net/NetAction.h"
|
||||
|
||||
namespace Net {
|
||||
|
||||
|
@ -19,9 +19,6 @@
|
||||
|
||||
#include "net/ApiUpload.h"
|
||||
#include "ByteArraySink.h"
|
||||
#include "ChecksumValidator.h"
|
||||
#include "MetaCacheSink.h"
|
||||
#include "net/NetAction.h"
|
||||
|
||||
namespace Net {
|
||||
|
||||
|
@ -47,8 +47,6 @@
|
||||
#include "ChecksumValidator.h"
|
||||
#include "MetaCacheSink.h"
|
||||
|
||||
#include "net/NetAction.h"
|
||||
|
||||
namespace Net {
|
||||
|
||||
#if defined(LAUNCHER_APPLICATION)
|
||||
|
@ -1,100 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
|
||||
* Copyright (C) 2023 Rachel Powers <508861+Ryex@users.noreply.github.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
*
|
||||
* Copyright 2013-2021 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QNetworkReply>
|
||||
#include <QUrl>
|
||||
|
||||
#include "QObjectPtr.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
#include "HeaderProxy.h"
|
||||
|
||||
class NetAction : public Task {
|
||||
Q_OBJECT
|
||||
protected:
|
||||
explicit NetAction() : Task() {}
|
||||
|
||||
public:
|
||||
using Ptr = shared_qobject_ptr<NetAction>;
|
||||
|
||||
virtual ~NetAction() = default;
|
||||
|
||||
QUrl url() { return m_url; }
|
||||
|
||||
void setNetwork(shared_qobject_ptr<QNetworkAccessManager> network) { m_network = network; }
|
||||
|
||||
void addHeaderProxy(Net::HeaderProxy* proxy) { m_headerProxies.push_back(std::shared_ptr<Net::HeaderProxy>(proxy)); }
|
||||
virtual void init() = 0;
|
||||
|
||||
protected slots:
|
||||
virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal) = 0;
|
||||
virtual void downloadError(QNetworkReply::NetworkError error) = 0;
|
||||
virtual void downloadFinished() = 0;
|
||||
virtual void downloadReadyRead() = 0;
|
||||
|
||||
virtual void sslErrors(const QList<QSslError>& errors)
|
||||
{
|
||||
int i = 1;
|
||||
for (auto error : errors) {
|
||||
qCritical() << "Network SSL Error #" << i << " : " << error.errorString();
|
||||
auto cert = error.certificate();
|
||||
qCritical() << "Certificate in question:\n" << cert.toText();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public slots:
|
||||
void startAction(shared_qobject_ptr<QNetworkAccessManager> network)
|
||||
{
|
||||
m_network = network;
|
||||
executeTask();
|
||||
}
|
||||
|
||||
protected:
|
||||
void executeTask() override {}
|
||||
|
||||
public:
|
||||
shared_qobject_ptr<QNetworkAccessManager> m_network;
|
||||
|
||||
/// the network reply
|
||||
unique_qobject_ptr<QNetworkReply> m_reply;
|
||||
|
||||
/// source URL
|
||||
QUrl m_url;
|
||||
std::vector<std::shared_ptr<Net::HeaderProxy>> m_headerProxies;
|
||||
};
|
@ -36,6 +36,7 @@
|
||||
*/
|
||||
|
||||
#include "NetJob.h"
|
||||
#include "net/NetRequest.h"
|
||||
#include "tasks/ConcurrentTask.h"
|
||||
#if defined(LAUNCHER_APPLICATION)
|
||||
#include "Application.h"
|
||||
@ -48,7 +49,7 @@ NetJob::NetJob(QString job_name, shared_qobject_ptr<QNetworkAccessManager> netwo
|
||||
#endif
|
||||
}
|
||||
|
||||
auto NetJob::addNetAction(NetAction::Ptr action) -> bool
|
||||
auto NetJob::addNetAction(Net::NetRequest::Ptr action) -> bool
|
||||
{
|
||||
action->setNetwork(m_network);
|
||||
|
||||
@ -111,11 +112,11 @@ auto NetJob::abort() -> bool
|
||||
return fullyAborted;
|
||||
}
|
||||
|
||||
auto NetJob::getFailedActions() -> QList<NetAction*>
|
||||
auto NetJob::getFailedActions() -> QList<Net::NetRequest*>
|
||||
{
|
||||
QList<NetAction*> failed;
|
||||
QList<Net::NetRequest*> failed;
|
||||
for (auto index : m_failed) {
|
||||
failed.push_back(dynamic_cast<NetAction*>(index.get()));
|
||||
failed.push_back(dynamic_cast<Net::NetRequest*>(index.get()));
|
||||
}
|
||||
return failed;
|
||||
}
|
||||
@ -124,7 +125,7 @@ auto NetJob::getFailedFiles() -> QList<QString>
|
||||
{
|
||||
QList<QString> failed;
|
||||
for (auto index : m_failed) {
|
||||
failed.append(static_cast<NetAction*>(index.get())->url().toString());
|
||||
failed.append(static_cast<Net::NetRequest*>(index.get())->url().toString());
|
||||
}
|
||||
return failed;
|
||||
}
|
||||
|
@ -39,7 +39,7 @@
|
||||
#include <QtNetwork>
|
||||
|
||||
#include <QObject>
|
||||
#include "NetAction.h"
|
||||
#include "net/NetRequest.h"
|
||||
#include "tasks/ConcurrentTask.h"
|
||||
|
||||
// Those are included so that they are also included by anyone using NetJob
|
||||
@ -58,9 +58,9 @@ class NetJob : public ConcurrentTask {
|
||||
auto size() const -> int;
|
||||
|
||||
auto canAbort() const -> bool override;
|
||||
auto addNetAction(NetAction::Ptr action) -> bool;
|
||||
auto addNetAction(Net::NetRequest::Ptr action) -> bool;
|
||||
|
||||
auto getFailedActions() -> QList<NetAction*>;
|
||||
auto getFailedActions() -> QList<Net::NetRequest*>;
|
||||
auto getFailedFiles() -> QList<QString>;
|
||||
|
||||
public slots:
|
||||
|
@ -37,6 +37,7 @@
|
||||
*/
|
||||
|
||||
#include "NetRequest.h"
|
||||
#include <qnetworkreply.h>
|
||||
#include <QUrl>
|
||||
|
||||
#include <QDateTime>
|
||||
@ -48,8 +49,6 @@
|
||||
#endif
|
||||
#include "BuildConfig.h"
|
||||
|
||||
#include "net/NetAction.h"
|
||||
|
||||
#include "MMCTime.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
@ -105,20 +104,18 @@ void NetRequest::executeTask()
|
||||
for (auto& header_proxy : m_headerProxies) {
|
||||
header_proxy->writeHeaders(request);
|
||||
}
|
||||
// TODO remove duplication
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
||||
request.setTransferTimeout();
|
||||
#endif
|
||||
request.setTransferTimeout(QNetworkRequest::DefaultTransferTimeoutConstant);
|
||||
|
||||
m_last_progress_time = m_clock.now();
|
||||
m_last_progress_bytes = 0;
|
||||
|
||||
QNetworkReply* rep = getReply(request);
|
||||
auto rep = getReply(request);
|
||||
if (rep == nullptr) // it failed
|
||||
return;
|
||||
m_reply.reset(rep);
|
||||
connect(rep, &QNetworkReply::downloadProgress, this, &NetRequest::downloadProgress);
|
||||
connect(rep, &QNetworkReply::uploadProgress, this, &NetRequest::onProgress);
|
||||
connect(rep, &QNetworkReply::downloadProgress, this, &NetRequest::onProgress);
|
||||
connect(rep, &QNetworkReply::finished, this, &NetRequest::downloadFinished);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) // QNetworkReply::errorOccurred added in 5.15
|
||||
connect(rep, &QNetworkReply::errorOccurred, this, &NetRequest::downloadError);
|
||||
@ -129,7 +126,7 @@ void NetRequest::executeTask()
|
||||
connect(rep, &QNetworkReply::readyRead, this, &NetRequest::downloadReadyRead);
|
||||
}
|
||||
|
||||
void NetRequest::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
|
||||
void NetRequest::onProgress(qint64 bytesReceived, qint64 bytesTotal)
|
||||
{
|
||||
auto now = m_clock.now();
|
||||
auto elapsed = now - m_last_progress_time;
|
||||
@ -237,7 +234,7 @@ auto NetRequest::handleRedirect() -> bool
|
||||
|
||||
m_url = QUrl(redirect.toString());
|
||||
qCDebug(logCat) << getUid().toString() << "Following redirect to " << m_url.toString();
|
||||
startAction(m_network);
|
||||
executeTask();
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -334,4 +331,23 @@ auto NetRequest::abort() -> bool
|
||||
return true;
|
||||
}
|
||||
|
||||
int NetRequest::replyStatusCode() const
|
||||
{
|
||||
return m_reply ? m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() : -1;
|
||||
}
|
||||
|
||||
QNetworkReply::NetworkError NetRequest::error() const
|
||||
{
|
||||
return m_reply ? m_reply->error() : QNetworkReply::NoError;
|
||||
}
|
||||
|
||||
QUrl NetRequest::url() const
|
||||
{
|
||||
return m_url;
|
||||
}
|
||||
|
||||
QString NetRequest::errorString() const
|
||||
{
|
||||
return m_reply ? m_reply->errorString() : "";
|
||||
}
|
||||
} // namespace Net
|
||||
|
@ -39,20 +39,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <qloggingcategory.h>
|
||||
#include <QNetworkReply>
|
||||
#include <QUrl>
|
||||
#include <chrono>
|
||||
|
||||
#include "NetAction.h"
|
||||
#include "HeaderProxy.h"
|
||||
#include "Sink.h"
|
||||
#include "Validator.h"
|
||||
|
||||
#include "QObjectPtr.h"
|
||||
#include "net/Logging.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
namespace Net {
|
||||
class NetRequest : public NetAction {
|
||||
class NetRequest : public Task {
|
||||
Q_OBJECT
|
||||
protected:
|
||||
explicit NetRequest() : NetAction() {}
|
||||
explicit NetRequest() : Task() {}
|
||||
|
||||
public:
|
||||
using Ptr = shared_qobject_ptr<class NetRequest>;
|
||||
@ -61,26 +64,30 @@ class NetRequest : public NetAction {
|
||||
|
||||
public:
|
||||
~NetRequest() override = default;
|
||||
|
||||
void init() override {}
|
||||
|
||||
public:
|
||||
void addValidator(Validator* v);
|
||||
auto abort() -> bool override;
|
||||
auto canAbort() const -> bool override { return true; }
|
||||
|
||||
void setNetwork(shared_qobject_ptr<QNetworkAccessManager> network) { m_network = network; }
|
||||
void addHeaderProxy(Net::HeaderProxy* proxy) { m_headerProxies.push_back(std::shared_ptr<Net::HeaderProxy>(proxy)); }
|
||||
|
||||
virtual void init() {}
|
||||
|
||||
QUrl url() const;
|
||||
int replyStatusCode() const;
|
||||
QNetworkReply::NetworkError error() const;
|
||||
QString errorString() const;
|
||||
|
||||
private:
|
||||
auto handleRedirect() -> bool;
|
||||
virtual QNetworkReply* getReply(QNetworkRequest&) = 0;
|
||||
|
||||
protected slots:
|
||||
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal) override;
|
||||
void downloadError(QNetworkReply::NetworkError error) override;
|
||||
void sslErrors(const QList<QSslError>& errors) override;
|
||||
void downloadFinished() override;
|
||||
void downloadReadyRead() override;
|
||||
|
||||
public slots:
|
||||
void onProgress(qint64 bytesReceived, qint64 bytesTotal);
|
||||
void downloadError(QNetworkReply::NetworkError error);
|
||||
void sslErrors(const QList<QSslError>& errors);
|
||||
void downloadFinished();
|
||||
void downloadReadyRead();
|
||||
void executeTask() override;
|
||||
|
||||
protected:
|
||||
@ -93,6 +100,15 @@ class NetRequest : public NetAction {
|
||||
std::chrono::steady_clock m_clock;
|
||||
std::chrono::time_point<std::chrono::steady_clock> m_last_progress_time;
|
||||
qint64 m_last_progress_bytes;
|
||||
|
||||
shared_qobject_ptr<QNetworkAccessManager> m_network;
|
||||
|
||||
/// the network reply
|
||||
unique_qobject_ptr<QNetworkReply> m_reply;
|
||||
|
||||
/// source URL
|
||||
QUrl m_url;
|
||||
std::vector<std::shared_ptr<Net::HeaderProxy>> m_headerProxies;
|
||||
};
|
||||
} // namespace Net
|
||||
|
||||
|
@ -35,9 +35,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "net/NetAction.h"
|
||||
|
||||
#include "Validator.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
namespace Net {
|
||||
class Sink {
|
||||
|
@ -34,7 +34,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "net/NetAction.h"
|
||||
#include <QNetworkReply>
|
||||
|
||||
namespace Net {
|
||||
class Validator {
|
||||
|
@ -45,8 +45,9 @@
|
||||
#include "ui/dialogs/ProgressDialog.h"
|
||||
|
||||
#include <Application.h>
|
||||
#include "minecraft/auth/AuthRequest.h"
|
||||
#include "minecraft/auth/Parsers.h"
|
||||
#include "net/StaticHeaderProxy.h"
|
||||
#include "net/Upload.h"
|
||||
|
||||
ProfileSetupDialog::ProfileSetupDialog(MinecraftAccountPtr accountToSetup, QWidget* parent)
|
||||
: QDialog(parent), m_accountToSetup(accountToSetup), ui(new Ui::ProfileSetupDialog)
|
||||
@ -150,28 +151,27 @@ void ProfileSetupDialog::checkName(const QString& name)
|
||||
currentCheck = name;
|
||||
isChecking = true;
|
||||
|
||||
auto token = m_accountToSetup->accessToken();
|
||||
QUrl url(QString("https://api.minecraftservices.com/minecraft/profile/name/%1/available").arg(name));
|
||||
auto headers = QList<Net::HeaderPair>{ { "Content-Type", "application/json" },
|
||||
{ "Accept", "application/json" },
|
||||
{ "Authorization", QString("Bearer %1").arg(m_accountToSetup->accessToken()).toUtf8() } };
|
||||
|
||||
auto url = QString("https://api.minecraftservices.com/minecraft/profile/name/%1/available").arg(name);
|
||||
QNetworkRequest request = QNetworkRequest(url);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
request.setRawHeader("Accept", "application/json");
|
||||
request.setRawHeader("Authorization", QString("Bearer %1").arg(token).toUtf8());
|
||||
m_check_response.reset(new QByteArray());
|
||||
if (m_check_task)
|
||||
disconnect(m_check_task.get(), nullptr, this, nullptr);
|
||||
m_check_task = Net::Download::makeByteArray(url, m_check_response);
|
||||
m_check_task->addHeaderProxy(new Net::StaticHeaderProxy(headers));
|
||||
|
||||
AuthRequest* requestor = new AuthRequest(this);
|
||||
connect(requestor, &AuthRequest::finished, this, &ProfileSetupDialog::checkFinished);
|
||||
requestor->get(request);
|
||||
connect(m_check_task.get(), &Task::finished, this, &ProfileSetupDialog::checkFinished);
|
||||
|
||||
m_check_task->setNetwork(APPLICATION->network());
|
||||
m_check_task->start();
|
||||
}
|
||||
|
||||
void ProfileSetupDialog::checkFinished(QNetworkReply::NetworkError error,
|
||||
QByteArray profileData,
|
||||
[[maybe_unused]] QList<QNetworkReply::RawHeaderPair> headers)
|
||||
void ProfileSetupDialog::checkFinished()
|
||||
{
|
||||
auto requestor = qobject_cast<AuthRequest*>(QObject::sender());
|
||||
requestor->deleteLater();
|
||||
|
||||
if (error == QNetworkReply::NoError) {
|
||||
auto doc = QJsonDocument::fromJson(profileData);
|
||||
if (m_check_task->error() == QNetworkReply::NoError) {
|
||||
auto doc = QJsonDocument::fromJson(*m_check_response);
|
||||
auto root = doc.object();
|
||||
auto statusValue = root.value("status").toString("INVALID");
|
||||
if (statusValue == "AVAILABLE") {
|
||||
@ -195,20 +195,22 @@ void ProfileSetupDialog::setupProfile(const QString& profileName)
|
||||
return;
|
||||
}
|
||||
|
||||
auto token = m_accountToSetup->accessToken();
|
||||
|
||||
auto url = QString("https://api.minecraftservices.com/minecraft/profile");
|
||||
QNetworkRequest request = QNetworkRequest(url);
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
request.setRawHeader("Accept", "application/json");
|
||||
request.setRawHeader("Authorization", QString("Bearer %1").arg(token).toUtf8());
|
||||
|
||||
QString payloadTemplate("{\"profileName\":\"%1\"}");
|
||||
auto profileData = payloadTemplate.arg(profileName).toUtf8();
|
||||
|
||||
AuthRequest* requestor = new AuthRequest(this);
|
||||
connect(requestor, &AuthRequest::finished, this, &ProfileSetupDialog::setupProfileFinished);
|
||||
requestor->post(request, profileData);
|
||||
QUrl url("https://api.minecraftservices.com/minecraft/profile");
|
||||
auto headers = QList<Net::HeaderPair>{ { "Content-Type", "application/json" },
|
||||
{ "Accept", "application/json" },
|
||||
{ "Authorization", QString("Bearer %1").arg(m_accountToSetup->accessToken()).toUtf8() } };
|
||||
|
||||
m_profile_response.reset(new QByteArray());
|
||||
m_profile_task = Net::Upload::makeByteArray(url, m_profile_response, payloadTemplate.arg(profileName).toUtf8());
|
||||
m_profile_task->addHeaderProxy(new Net::StaticHeaderProxy(headers));
|
||||
|
||||
connect(m_profile_task.get(), &Task::finished, this, &ProfileSetupDialog::setupProfileFinished);
|
||||
|
||||
m_profile_task->setNetwork(APPLICATION->network());
|
||||
m_profile_task->start();
|
||||
|
||||
isWorking = true;
|
||||
|
||||
auto button = ui->buttonBox->button(QDialogButtonBox::Cancel);
|
||||
@ -244,22 +246,17 @@ struct MojangError {
|
||||
|
||||
} // namespace
|
||||
|
||||
void ProfileSetupDialog::setupProfileFinished(QNetworkReply::NetworkError error,
|
||||
QByteArray errorData,
|
||||
[[maybe_unused]] QList<QNetworkReply::RawHeaderPair> headers)
|
||||
void ProfileSetupDialog::setupProfileFinished()
|
||||
{
|
||||
auto requestor = qobject_cast<AuthRequest*>(QObject::sender());
|
||||
requestor->deleteLater();
|
||||
|
||||
isWorking = false;
|
||||
if (error == QNetworkReply::NoError) {
|
||||
if (m_profile_task->error() == QNetworkReply::NoError) {
|
||||
/*
|
||||
* data contains the profile in the response
|
||||
* ... we could parse it and update the account, but let's just return back to the normal login flow instead...
|
||||
*/
|
||||
accept();
|
||||
} else {
|
||||
auto parsedError = MojangError::fromJSON(errorData);
|
||||
auto parsedError = MojangError::fromJSON(*m_profile_response);
|
||||
ui->errorLabel->setVisible(true);
|
||||
ui->errorLabel->setText(tr("The server returned the following error:") + "\n\n" + parsedError.errorMessage);
|
||||
qDebug() << parsedError.rawError;
|
||||
|
@ -22,6 +22,8 @@
|
||||
|
||||
#include <minecraft/auth/MinecraftAccount.h>
|
||||
#include <memory>
|
||||
#include "net/Download.h"
|
||||
#include "net/Upload.h"
|
||||
|
||||
namespace Ui {
|
||||
class ProfileSetupDialog;
|
||||
@ -40,10 +42,10 @@ class ProfileSetupDialog : public QDialog {
|
||||
void on_buttonBox_rejected();
|
||||
|
||||
void nameEdited(const QString& name);
|
||||
void checkFinished(QNetworkReply::NetworkError error, QByteArray data, QList<QNetworkReply::RawHeaderPair> headers);
|
||||
void startCheck();
|
||||
|
||||
void setupProfileFinished(QNetworkReply::NetworkError error, QByteArray data, QList<QNetworkReply::RawHeaderPair> headers);
|
||||
void checkFinished();
|
||||
void setupProfileFinished();
|
||||
|
||||
protected:
|
||||
void scheduleCheck(const QString& name);
|
||||
@ -67,4 +69,10 @@ class ProfileSetupDialog : public QDialog {
|
||||
QString currentCheck;
|
||||
|
||||
QTimer checkStartTimer;
|
||||
|
||||
std::shared_ptr<QByteArray> m_check_response;
|
||||
Net::Download::Ptr m_check_task;
|
||||
|
||||
std::shared_ptr<QByteArray> m_profile_response;
|
||||
Net::Upload::Ptr m_profile_task;
|
||||
};
|
||||
|
@ -331,7 +331,7 @@ std::optional<QIcon> ResourceModel::getIcon(QModelIndex& index, const QUrl& url)
|
||||
auto icon_fetch_action = Net::ApiDownload::makeCached(url, cache_entry);
|
||||
|
||||
auto full_file_path = cache_entry->getFullPath();
|
||||
connect(icon_fetch_action.get(), &NetAction::succeeded, this, [=] {
|
||||
connect(icon_fetch_action.get(), &Task::succeeded, this, [=] {
|
||||
auto icon = QIcon(full_file_path);
|
||||
QPixmapCache::insert(url.toString(), icon.pixmap(icon.actualSize({ 64, 64 })));
|
||||
|
||||
@ -339,7 +339,7 @@ std::optional<QIcon> ResourceModel::getIcon(QModelIndex& index, const QUrl& url)
|
||||
|
||||
emit dataChanged(index, index, { Qt::DecorationRole });
|
||||
});
|
||||
connect(icon_fetch_action.get(), &NetAction::failed, this, [=] {
|
||||
connect(icon_fetch_action.get(), &Task::failed, this, [=] {
|
||||
m_currently_running_icon_actions.remove(url);
|
||||
m_failed_icon_actions.insert(url);
|
||||
});
|
||||
|
@ -352,10 +352,10 @@ void ModpackListModel::searchRequestForOneSucceeded(QJsonDocument& doc)
|
||||
void ModpackListModel::searchRequestFailed(QString reason)
|
||||
{
|
||||
auto failed_action = dynamic_cast<NetJob*>(jobPtr.get())->getFailedActions().at(0);
|
||||
if (!failed_action->m_reply) {
|
||||
if (failed_action->replyStatusCode() == -1) {
|
||||
// Network error
|
||||
QMessageBox::critical(nullptr, tr("Error"), tr("A network error occurred. Could not load modpacks."));
|
||||
} else if (failed_action->m_reply && failed_action->m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 409) {
|
||||
} else if (failed_action->replyStatusCode() == 409) {
|
||||
// 409 Gone, notify user to update
|
||||
QMessageBox::critical(nullptr, tr("Error"),
|
||||
//: %1 refers to the launcher itself
|
||||
|
@ -95,8 +95,8 @@ class LibraryTest : public QObject {
|
||||
auto downloads = test.getDownloads(r, cache.get(), failedFiles, QString());
|
||||
QCOMPARE(downloads.size(), 1);
|
||||
QCOMPARE(failedFiles, {});
|
||||
NetAction::Ptr dl = downloads[0];
|
||||
QCOMPARE(dl->m_url, QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion.jar"));
|
||||
Net::NetRequest::Ptr dl = downloads[0];
|
||||
QCOMPARE(dl->url(), QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion.jar"));
|
||||
}
|
||||
void test_legacy_url_local_broken()
|
||||
{
|
||||
@ -147,7 +147,7 @@ class LibraryTest : public QObject {
|
||||
QCOMPARE(dls.size(), 1);
|
||||
QCOMPARE(failedFiles, {});
|
||||
auto dl = dls[0];
|
||||
QCOMPARE(dl->m_url, QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion-linux.jar"));
|
||||
QCOMPARE(dl->url(), QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion-linux.jar"));
|
||||
}
|
||||
}
|
||||
void test_legacy_native_arch()
|
||||
@ -170,8 +170,8 @@ class LibraryTest : public QObject {
|
||||
auto dls = test.getDownloads(r, cache.get(), failedFiles, QString());
|
||||
QCOMPARE(dls.size(), 2);
|
||||
QCOMPARE(failedFiles, {});
|
||||
QCOMPARE(dls[0]->m_url, QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion-linux-32.jar"));
|
||||
QCOMPARE(dls[1]->m_url, QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion-linux-64.jar"));
|
||||
QCOMPARE(dls[0]->url(), QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion-linux-32.jar"));
|
||||
QCOMPARE(dls[1]->url(), QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion-linux-64.jar"));
|
||||
}
|
||||
r.system = "windows";
|
||||
{
|
||||
@ -185,8 +185,8 @@ class LibraryTest : public QObject {
|
||||
auto dls = test.getDownloads(r, cache.get(), failedFiles, QString());
|
||||
QCOMPARE(dls.size(), 2);
|
||||
QCOMPARE(failedFiles, {});
|
||||
QCOMPARE(dls[0]->m_url, QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion-windows-32.jar"));
|
||||
QCOMPARE(dls[1]->m_url, QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion-windows-64.jar"));
|
||||
QCOMPARE(dls[0]->url(), QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion-windows-32.jar"));
|
||||
QCOMPARE(dls[1]->url(), QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion-windows-64.jar"));
|
||||
}
|
||||
r.system = "osx";
|
||||
{
|
||||
@ -200,8 +200,8 @@ class LibraryTest : public QObject {
|
||||
auto dls = test.getDownloads(r, cache.get(), failedFiles, QString());
|
||||
QCOMPARE(dls.size(), 2);
|
||||
QCOMPARE(failedFiles, {});
|
||||
QCOMPARE(dls[0]->m_url, QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion-osx-32.jar"));
|
||||
QCOMPARE(dls[1]->m_url, QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion-osx-64.jar"));
|
||||
QCOMPARE(dls[0]->url(), QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion-osx-32.jar"));
|
||||
QCOMPARE(dls[1]->url(), QUrl("file://foo/bar/test/package/testname/testversion/testname-testversion-osx-64.jar"));
|
||||
}
|
||||
}
|
||||
void test_legacy_native_arch_local_override()
|
||||
@ -244,7 +244,7 @@ class LibraryTest : public QObject {
|
||||
auto dls = test->getDownloads(r, cache.get(), failedFiles, QString());
|
||||
QCOMPARE(dls.size(), 1);
|
||||
QCOMPARE(failedFiles, {});
|
||||
QCOMPARE(dls[0]->m_url, QUrl("https://libraries.minecraft.net/com/paulscode/codecwav/20101023/codecwav-20101023.jar"));
|
||||
QCOMPARE(dls[0]->url(), QUrl("https://libraries.minecraft.net/com/paulscode/codecwav/20101023/codecwav-20101023.jar"));
|
||||
}
|
||||
r.system = "osx";
|
||||
test->setHint("local");
|
||||
@ -300,7 +300,7 @@ class LibraryTest : public QObject {
|
||||
auto dls = test->getDownloads(r, cache.get(), failedFiles, QString());
|
||||
QCOMPARE(dls.size(), 1);
|
||||
QCOMPARE(failedFiles, {});
|
||||
QCOMPARE(dls[0]->m_url, QUrl("https://libraries.minecraft.net/org/lwjgl/lwjgl/lwjgl-platform/2.9.4-nightly-20150209/"
|
||||
QCOMPARE(dls[0]->url(), QUrl("https://libraries.minecraft.net/org/lwjgl/lwjgl/lwjgl-platform/2.9.4-nightly-20150209/"
|
||||
"lwjgl-platform-2.9.4-nightly-20150209-natives-osx.jar"));
|
||||
}
|
||||
void test_onenine_native_arch()
|
||||
@ -317,9 +317,9 @@ class LibraryTest : public QObject {
|
||||
auto dls = test->getDownloads(r, cache.get(), failedFiles, QString());
|
||||
QCOMPARE(dls.size(), 2);
|
||||
QCOMPARE(failedFiles, {});
|
||||
QCOMPARE(dls[0]->m_url,
|
||||
QCOMPARE(dls[0]->url(),
|
||||
QUrl("https://libraries.minecraft.net/tv/twitch/twitch-platform/5.16/twitch-platform-5.16-natives-windows-32.jar"));
|
||||
QCOMPARE(dls[1]->m_url,
|
||||
QCOMPARE(dls[1]->url(),
|
||||
QUrl("https://libraries.minecraft.net/tv/twitch/twitch-platform/5.16/twitch-platform-5.16-natives-windows-64.jar"));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user