Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NOISSUE Centralize Mojang URLs #5481

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion buildconfig/BuildConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ class Config

QString RESOURCE_BASE = "https://resources.download.minecraft.net/";
QString LIBRARY_BASE = "https://libraries.minecraft.net/";
QString AUTH_BASE = "https://authserver.mojang.com/";
QString API_BASE = "https://api.minecraftservices.com";
QString AUTH_BASE = "https://authserver.mojang.com";
QString SESSION_BASE = "https://sessionserver.mojang.com";
QString TEXTURE_BASE = "http://textures.minecraft.net";
QString IMGUR_BASE_URL = "https://api.imgur.com/3/";
QString FMLLIBS_BASE_URL = "https://files.multimc.org/fmllibs/";
QString TRANSLATIONS_BASE_URL = "https://files.multimc.org/translations/";
Expand Down
3 changes: 2 additions & 1 deletion launcher/LaunchController.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "LaunchController.h"
#include "minecraft/auth/AccountList.h"
#include "Application.h"
#include "BuildConfig.h"

#include "ui/MainWindow.h"
#include "ui/InstanceWindow.h"
Expand Down Expand Up @@ -345,7 +346,7 @@ void LaunchController::launchInstance()
online_mode = "online";

// Prepend Server Status
QStringList servers = {"authserver.mojang.com", "session.minecraft.net", "textures.minecraft.net", "api.mojang.com"};
QStringList servers = {QUrl(BuildConfig.AUTH_BASE).host(), QUrl(BuildConfig.SESSION_BASE).host(), QUrl(BuildConfig.TEXTURE_BASE).host(), QUrl(BuildConfig.API_BASE).host()};
QString resolved_servers = "";
QHostInfo host_info;

Expand Down
8 changes: 5 additions & 3 deletions launcher/minecraft/auth/Parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <QJsonArray>
#include <QDebug>

#include "BuildConfig.h"

namespace Parsers {

bool getDateTime(QJsonValue value, QDateTime & out) {
Expand Down Expand Up @@ -256,7 +258,7 @@ bool parseForcedMigrationResponse(QByteArray & data, bool& result) {
QJsonParseError jsonError;
QJsonDocument doc = QJsonDocument::fromJson(data, &jsonError);
if(jsonError.error) {
qWarning() << "Failed to parse response from https://api.minecraftservices.com/rollout/v1/msamigrationforced as JSON: " << jsonError.errorString();
qWarning() << "Failed to parse response from " << BuildConfig.API_BASE << "/rollout/v1/msamigrationforced as JSON: " << jsonError.errorString();
return false;
}

Expand Down Expand Up @@ -286,7 +288,7 @@ bool parseRolloutResponse(QByteArray & data, bool& result) {
QJsonParseError jsonError;
QJsonDocument doc = QJsonDocument::fromJson(data, &jsonError);
if(jsonError.error) {
qWarning() << "Failed to parse response from https://api.minecraftservices.com/rollout/v1/msamigration as JSON: " << jsonError.errorString();
qWarning() << "Failed to parse response from " << BuildConfig.API_BASE << "/rollout/v1/msamigration as JSON: " << jsonError.errorString();
return false;
}

Expand Down Expand Up @@ -315,7 +317,7 @@ bool parseMojangResponse(QByteArray & data, Katabasis::Token &output) {
#endif
QJsonDocument doc = QJsonDocument::fromJson(data, &jsonError);
if(jsonError.error) {
qWarning() << "Failed to parse response from api.minecraftservices.com/launcher/login as JSON: " << jsonError.errorString();
qWarning() << "Failed to parse response from " << BuildConfig.API_BASE << "/launcher/login as JSON: " << jsonError.errorString();
return false;
}

Expand Down
5 changes: 3 additions & 2 deletions launcher/minecraft/auth/Yggdrasil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <QDebug>

#include "Application.h"
#include "BuildConfig.h"

Yggdrasil::Yggdrasil(AccountData *data, QObject *parent)
: AccountTask(data, parent)
Expand Down Expand Up @@ -84,7 +85,7 @@ void Yggdrasil::refresh() {
req.insert("requestUser", false);
QJsonDocument doc(req);

QUrl reqUrl("https://authserver.mojang.com/refresh");
QUrl reqUrl(QString("%1/refresh").arg(BuildConfig.AUTH_BASE));
QByteArray requestData = doc.toJson();

sendRequest(reqUrl, requestData);
Expand Down Expand Up @@ -129,7 +130,7 @@ void Yggdrasil::login(QString password) {

QJsonDocument doc(req);

QUrl reqUrl("https://authserver.mojang.com/authenticate");
QUrl reqUrl(QString("%1/authenticate").arg(BuildConfig.AUTH_BASE));
QNetworkRequest netRequest(reqUrl);
QByteArray requestData = doc.toJson();

Expand Down
4 changes: 3 additions & 1 deletion launcher/minecraft/auth/steps/EntitlementsStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "minecraft/auth/AuthRequest.h"
#include "minecraft/auth/Parsers.h"

#include "BuildConfig.h"

EntitlementsStep::EntitlementsStep(AccountData* data) : AuthStep(data) {}

EntitlementsStep::~EntitlementsStep() noexcept = default;
Expand All @@ -18,7 +20,7 @@ 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;
auto url = QString("%1/entitlements/license?requestId=%2").arg(BuildConfig.API_BASE).arg(m_entitlementsRequestId);
QNetworkRequest request = QNetworkRequest(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
request.setRawHeader("Accept", "application/json");
Expand Down
4 changes: 3 additions & 1 deletion launcher/minecraft/auth/steps/ForcedMigrationStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "minecraft/auth/AuthRequest.h"
#include "minecraft/auth/Parsers.h"

#include "BuildConfig.h"

ForcedMigrationStep::ForcedMigrationStep(AccountData* data) : AuthStep(data) {

}
Expand All @@ -16,7 +18,7 @@ QString ForcedMigrationStep::describe() {
}

void ForcedMigrationStep::perform() {
auto url = QUrl("https://api.minecraftservices.com/rollout/v1/msamigrationforced");
auto url = QString("%1/rollout/v1/msamigrationforced").arg(BuildConfig.API_BASE);
QNetworkRequest request = QNetworkRequest(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
request.setRawHeader("Authorization", QString("Bearer %1").arg(m_data->yggdrasilToken.token).toUtf8());
Expand Down
4 changes: 3 additions & 1 deletion launcher/minecraft/auth/steps/LauncherLoginStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "minecraft/auth/Parsers.h"
#include "minecraft/auth/AccountTask.h"

#include "BuildConfig.h"

LauncherLoginStep::LauncherLoginStep(AccountData* data) : AuthStep(data) {

}
Expand All @@ -17,7 +19,7 @@ QString LauncherLoginStep::describe() {
}

void LauncherLoginStep::perform() {
auto requestURL = "https://api.minecraftservices.com/launcher/login";
auto requestURL = QString("%1/launcher/login").arg(BuildConfig.API_BASE);
auto uhs = m_data->mojangservicesToken.extra["uhs"].toString();
auto xToken = m_data->mojangservicesToken.token;

Expand Down
4 changes: 3 additions & 1 deletion launcher/minecraft/auth/steps/MigrationEligibilityStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "minecraft/auth/AuthRequest.h"
#include "minecraft/auth/Parsers.h"

#include "BuildConfig.h"

MigrationEligibilityStep::MigrationEligibilityStep(AccountData* data) : AuthStep(data) {

}
Expand All @@ -16,7 +18,7 @@ QString MigrationEligibilityStep::describe() {
}

void MigrationEligibilityStep::perform() {
auto url = QUrl("https://api.minecraftservices.com/rollout/v1/msamigration");
auto url = QString("%1/rollout/v1/msamigration").arg(BuildConfig.API_BASE);
QNetworkRequest request = QNetworkRequest(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
request.setRawHeader("Authorization", QString("Bearer %1").arg(m_data->yggdrasilToken.token).toUtf8());
Expand Down
4 changes: 3 additions & 1 deletion launcher/minecraft/auth/steps/MinecraftProfileStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "minecraft/auth/AuthRequest.h"
#include "minecraft/auth/Parsers.h"

#include "BuildConfig.h"

MinecraftProfileStep::MinecraftProfileStep(AccountData* data) : AuthStep(data) {

}
Expand All @@ -17,7 +19,7 @@ QString MinecraftProfileStep::describe() {


void MinecraftProfileStep::perform() {
auto url = QUrl("https://api.minecraftservices.com/minecraft/profile");
auto url = QString("%1/minecraft/profile").arg(BuildConfig.API_BASE);
QNetworkRequest request = QNetworkRequest(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
request.setRawHeader("Authorization", QString("Bearer %1").arg(m_data->yggdrasilToken.token).toUtf8());
Expand Down
5 changes: 3 additions & 2 deletions launcher/minecraft/services/CapeChange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
#include <QHttpMultiPart>

#include "Application.h"
#include "BuildConfig.h"

CapeChange::CapeChange(QObject *parent, QString token, QString cape)
: Task(parent), m_capeId(cape), m_token(token)
{
}

void CapeChange::setCape(QString& cape) {
QNetworkRequest request(QUrl("https://api.minecraftservices.com/minecraft/profile/capes/active"));
QNetworkRequest request(QString("%1/minecraft/profile/capes/active").arg(BuildConfig.API_BASE));
auto requestString = QString("{\"capeId\":\"%1\"}").arg(m_capeId);
request.setRawHeader("Authorization", QString("Bearer %1").arg(m_token).toLocal8Bit());
QNetworkReply *rep = APPLICATION->network()->put(request, requestString.toUtf8());
Expand All @@ -25,7 +26,7 @@ void CapeChange::setCape(QString& cape) {
}

void CapeChange::clearCape() {
QNetworkRequest request(QUrl("https://api.minecraftservices.com/minecraft/profile/capes/active"));
QNetworkRequest request(QString("%1/minecraft/profile/capes/active").arg(BuildConfig.API_BASE));
auto requestString = QString("{\"capeId\":\"%1\"}").arg(m_capeId);
request.setRawHeader("Authorization", QString("Bearer %1").arg(m_token).toLocal8Bit());
QNetworkReply *rep = APPLICATION->network()->deleteResource(request);
Expand Down
3 changes: 2 additions & 1 deletion launcher/minecraft/services/SkinDelete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QHttpMultiPart>

#include "Application.h"
#include "BuildConfig.h"

SkinDelete::SkinDelete(QObject *parent, QString token)
: Task(parent), m_token(token)
Expand All @@ -12,7 +13,7 @@ SkinDelete::SkinDelete(QObject *parent, QString token)

void SkinDelete::executeTask()
{
QNetworkRequest request(QUrl("https://api.minecraftservices.com/minecraft/profile/skins/active"));
QNetworkRequest request(QString("%1/minecraft/profile/skins/active").arg(BuildConfig.API_BASE));
request.setRawHeader("Authorization", QString("Bearer %1").arg(m_token).toLocal8Bit());
QNetworkReply *rep = APPLICATION->network()->deleteResource(request);
m_reply = shared_qobject_ptr<QNetworkReply>(rep);
Expand Down
3 changes: 2 additions & 1 deletion launcher/minecraft/services/SkinUpload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QHttpMultiPart>

#include "Application.h"
#include "BuildConfig.h"

QByteArray getVariant(SkinUpload::Model model) {
switch (model) {
Expand All @@ -23,7 +24,7 @@ SkinUpload::SkinUpload(QObject *parent, QString token, QByteArray skin, SkinUplo

void SkinUpload::executeTask()
{
QNetworkRequest request(QUrl("https://api.minecraftservices.com/minecraft/profile/skins"));
QNetworkRequest request(QString("%1/minecraft/profile/skins").arg(BuildConfig.API_BASE));
request.setRawHeader("Authorization", QString("Bearer %1").arg(m_token).toLocal8Bit());
QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);

Expand Down
5 changes: 3 additions & 2 deletions launcher/ui/dialogs/ProfileSetupDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "minecraft/auth/AuthRequest.h"
#include "minecraft/auth/Parsers.h"

#include "BuildConfig.h"

ProfileSetupDialog::ProfileSetupDialog(MinecraftAccountPtr accountToSetup, QWidget *parent)
: QDialog(parent), m_accountToSetup(accountToSetup), ui(new Ui::ProfileSetupDialog)
Expand Down Expand Up @@ -134,7 +135,7 @@ void ProfileSetupDialog::checkName(const QString &name) {

auto token = m_accountToSetup->accessToken();

auto url = QString("https://api.minecraftservices.com/minecraft/profile/name/%1/available").arg(name);
auto url = QString("%1/minecraft/profile/name/%2/available").arg(BuildConfig.API_BASE).arg(name);
QNetworkRequest request = QNetworkRequest(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
request.setRawHeader("Accept", "application/json");
Expand Down Expand Up @@ -183,7 +184,7 @@ void ProfileSetupDialog::setupProfile(const QString &profileName) {

auto token = m_accountToSetup->accessToken();

auto url = QString("https://api.minecraftservices.com/minecraft/profile");
auto url = QString("%1/minecraft/profile");
QNetworkRequest request = QNetworkRequest(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
request.setRawHeader("Accept", "application/json");
Expand Down