From ebbfaf871395cf83e6b3c121aa42c5e5f3f7833c Mon Sep 17 00:00:00 2001 From: 0xf8 <0xf8.dev@proton.me> Date: Wed, 21 Jun 2023 13:23:24 -0400 Subject: [PATCH] Add custom login support --- launcher/CMakeLists.txt | 3 +++ launcher/minecraft/auth/AccountData.cpp | 8 ++++++++ launcher/minecraft/auth/MinecraftAccount.cpp | 1 + launcher/minecraft/auth/steps/CustomProfileStep.cpp | 2 ++ launcher/minecraft/auth/steps/CustomStep.cpp | 5 +++-- launcher/ui/dialogs/CustomLoginDialog.cpp | 2 +- launcher/ui/pages/global/AccountListPage.cpp | 4 ++-- 7 files changed, 20 insertions(+), 5 deletions(-) diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index eea16924..c9f59882 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -931,6 +931,8 @@ SET(LAUNCHER_SOURCES ui/dialogs/ProfileSetupDialog.h ui/dialogs/CopyInstanceDialog.cpp ui/dialogs/CopyInstanceDialog.h + ui/dialogs/CustomLoginDialog.cpp + ui/dialogs/CustomLoginDialog.h ui/dialogs/CustomMessageBox.cpp ui/dialogs/CustomMessageBox.h ui/dialogs/EditAccountDialog.cpp @@ -1094,6 +1096,7 @@ qt_wrap_ui(LAUNCHER_UI ui/dialogs/MSALoginDialog.ui ui/dialogs/OfflineLoginDialog.ui ui/dialogs/ElybyLoginDialog.ui + ui/dialogs/CustomLoginDialog.ui ui/dialogs/AboutDialog.ui ui/dialogs/LoginDialog.ui ui/dialogs/EditAccountDialog.ui diff --git a/launcher/minecraft/auth/AccountData.cpp b/launcher/minecraft/auth/AccountData.cpp index 066118be..5c5333c2 100644 --- a/launcher/minecraft/auth/AccountData.cpp +++ b/launcher/minecraft/auth/AccountData.cpp @@ -377,6 +377,13 @@ bool AccountData::resumeStateFromV3(QJsonObject data) { mojangservicesToken = tokenFromJSONV3(data, "xrp-mc"); } + if(type == AccountType::Custom) { + auto urlV = data.value("url"); + if (urlV.isString()) { + customUrl = urlV.toString(); + } + } + yggdrasilToken = tokenFromJSONV3(data, "ygg"); minecraftProfile = profileFromJSONV3(data, "profile"); if(!entitlementFromJSONV3(data, minecraftEntitlement)) { @@ -418,6 +425,7 @@ QJsonObject AccountData::saveState() const { } else if (type == AccountType::Custom) { output["type"] = "Custom"; + output["url"] = customUrl; } tokenToJSONV3(output, yggdrasilToken, "ygg"); diff --git a/launcher/minecraft/auth/MinecraftAccount.cpp b/launcher/minecraft/auth/MinecraftAccount.cpp index d8b14317..748424d9 100644 --- a/launcher/minecraft/auth/MinecraftAccount.cpp +++ b/launcher/minecraft/auth/MinecraftAccount.cpp @@ -128,6 +128,7 @@ MinecraftAccountPtr MinecraftAccount::createCustom(const QString &username, cons account->data.yggdrasilToken.extra["clientToken"] = QUuid::createUuid().toString().remove(QRegularExpression("[{}-]")); account->data.minecraftEntitlement.ownsMinecraft = true; account->data.minecraftEntitlement.canPlayMinecraft = true; + account->data.customUrl = url; return account; } diff --git a/launcher/minecraft/auth/steps/CustomProfileStep.cpp b/launcher/minecraft/auth/steps/CustomProfileStep.cpp index d7cd8cbd..c9b994a6 100644 --- a/launcher/minecraft/auth/steps/CustomProfileStep.cpp +++ b/launcher/minecraft/auth/steps/CustomProfileStep.cpp @@ -24,6 +24,8 @@ void CustomProfileStep::perform() { // m_data-> + qWarning() << "Url: " << m_data->customUrl; + QUrl url = QUrl(m_data->customUrl + "/session/profile/" + m_data->minecraftProfile.id); QNetworkRequest req = QNetworkRequest(url); AuthRequest *request = new AuthRequest(this); diff --git a/launcher/minecraft/auth/steps/CustomStep.cpp b/launcher/minecraft/auth/steps/CustomStep.cpp index 3592a41e..f697c022 100644 --- a/launcher/minecraft/auth/steps/CustomStep.cpp +++ b/launcher/minecraft/auth/steps/CustomStep.cpp @@ -23,11 +23,12 @@ void CustomStep::rehydrate() { } void CustomStep::perform() { + qWarning() << "url: " << m_url << " / " << m_data->customUrl; if(m_password.size()) { m_yggdrasil->login(m_password, m_url + "/auth/"); } else { - m_yggdrasil->refresh(m_url + "/auth/"); + m_yggdrasil->refresh(m_data->customUrl + "/auth/"); } } @@ -50,7 +51,7 @@ void CustomStep::onAuthFailed() { // NOTE: soft error in the first step means 'offline' if(state == AccountTaskState::STATE_FAILED_SOFT) { state = AccountTaskState::STATE_OFFLINE; - errorMessage = tr("Custom user authentication ended with a network error. Is MutliFactor Auth current?"); + errorMessage = tr("Custom user authentication ended with a network error. Is MutliFactor Auth correct?"); } emit finished(state, errorMessage); } diff --git a/launcher/ui/dialogs/CustomLoginDialog.cpp b/launcher/ui/dialogs/CustomLoginDialog.cpp index 2789143b..121062eb 100644 --- a/launcher/ui/dialogs/CustomLoginDialog.cpp +++ b/launcher/ui/dialogs/CustomLoginDialog.cpp @@ -42,7 +42,7 @@ void CustomLoginDialog::accept() ui->progressBar->setVisible(true); // Setup the login task and start it - m_account = MinecraftAccount::createCustom(ui->userTextBox->text()); + m_account = MinecraftAccount::createCustom(ui->userTextBox->text(), ui->urlTextBox->text()); if (ui->mfaTextBox->text().length() > 0) { m_loginTask = m_account->loginCustom(ui->passTextBox->text() + ':' + ui->mfaTextBox->text(), ui->urlTextBox->text()); } diff --git a/launcher/ui/pages/global/AccountListPage.cpp b/launcher/ui/pages/global/AccountListPage.cpp index e3587dab..f3806967 100644 --- a/launcher/ui/pages/global/AccountListPage.cpp +++ b/launcher/ui/pages/global/AccountListPage.cpp @@ -231,7 +231,7 @@ void AccountListPage::on_actionAddCustom_triggered() { m_accounts->addAccount(account); if (m_accounts->count() == 1) { - m_account->setDefaultAccount(account); + m_accounts->setDefaultAccount(account); } } } @@ -280,7 +280,7 @@ void AccountListPage::updateButtonStates() bool accountIsReady = false; bool accountIsOnline = false; bool accountIsElyby = false; - bool AccountIsCustom = false; + bool accountIsCustom = false; if (hasSelection) { QModelIndex selected = selection.first();