From 14981321d42cf7380f12215776b52c1da66685b0 Mon Sep 17 00:00:00 2001 From: Neptune Date: Fri, 8 Mar 2024 17:46:26 -0500 Subject: [PATCH] UltimMC: Fix ely.by auth --- launcher/CMakeLists.txt | 2 ++ launcher/minecraft/auth/AccountData.cpp | 8 +++--- launcher/minecraft/auth/MinecraftAccount.cpp | 19 +++++++++++--- launcher/minecraft/auth/MinecraftAccount.h | 2 ++ launcher/minecraft/auth/flows/Elyby.cpp | 21 ++++++++++++++++ launcher/minecraft/auth/flows/Elyby.h | 26 ++++++++++++++++++++ launcher/ui/dialogs/LoginDialog.cpp | 23 +++-------------- launcher/ui/dialogs/LoginDialog.h | 2 -- launcher/ui/dialogs/LoginDialog.ui | 3 --- launcher/ui/pages/global/AccountListPage.cpp | 6 ++--- launcher/ui/pages/global/AccountListPage.ui | 4 +-- 11 files changed, 78 insertions(+), 38 deletions(-) create mode 100644 launcher/minecraft/auth/flows/Elyby.cpp create mode 100644 launcher/minecraft/auth/flows/Elyby.h diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index b10b2d7fc0..42a681bf6f 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -233,6 +233,8 @@ set(MINECRAFT_SOURCES minecraft/auth/flows/MSA.h minecraft/auth/flows/Local.cpp minecraft/auth/flows/Local.h + minecraft/auth/flows/Elyby.cpp + minecraft/auth/flows/Elyby.h minecraft/auth/steps/EntitlementsStep.cpp minecraft/auth/steps/EntitlementsStep.h diff --git a/launcher/minecraft/auth/AccountData.cpp b/launcher/minecraft/auth/AccountData.cpp index a3b9cfaa17..3aeaa20a8d 100644 --- a/launcher/minecraft/auth/AccountData.cpp +++ b/launcher/minecraft/auth/AccountData.cpp @@ -388,7 +388,7 @@ QJsonObject AccountData::saveState() const { } QString AccountData::userName() const { - if(type != AccountType::Mojang) { + if(type != AccountType::Mojang && type != AccountType::Elyby) { return QString(); } return yggdrasilToken.extra["userName"].toString(); @@ -399,14 +399,14 @@ QString AccountData::accessToken() const { } QString AccountData::clientToken() const { - if(type != AccountType::Mojang) { + if(type != AccountType::Mojang && type != AccountType::Elyby) { return QString(); } return yggdrasilToken.extra["clientToken"].toString(); } void AccountData::setClientToken(QString clientToken) { - if(type != AccountType::Mojang) { + if(type != AccountType::Mojang && type != AccountType::Elyby) { return; } yggdrasilToken.extra["clientToken"] = clientToken; @@ -420,7 +420,7 @@ void AccountData::generateClientTokenIfMissing() { } void AccountData::invalidateClientToken() { - if(type != AccountType::Mojang) { + if(type != AccountType::Mojang && type != AccountType::Elyby) { return; } yggdrasilToken.extra["clientToken"] = QUuid::createUuid().toString().remove(QRegExp("[{-}]")); diff --git a/launcher/minecraft/auth/MinecraftAccount.cpp b/launcher/minecraft/auth/MinecraftAccount.cpp index 13e429ba38..075c9e1aff 100644 --- a/launcher/minecraft/auth/MinecraftAccount.cpp +++ b/launcher/minecraft/auth/MinecraftAccount.cpp @@ -32,6 +32,7 @@ #include "flows/MSA.h" #include "flows/Mojang.h" #include "flows/Local.h" +#include "flows/Elyby.h" MinecraftAccount::MinecraftAccount(QObject* parent) : QObject(parent) { data.internalId = QUuid::createUuid().toString().remove(QRegExp("[{}-]")); @@ -95,7 +96,6 @@ MinecraftAccountPtr MinecraftAccount::createLocal(const QString &username) account->data.yggdrasilToken.extra["userName"] = username; account->data.yggdrasilToken.extra["clientToken"] = QUuid::createUuid().toString().remove(QRegExp("[{}-]")); account->data.minecraftProfile.id = uuidFromUsername(username).toString().remove(QRegExp("[{}-]")); - account->data.minecraftProfile.id = account->data.internalId; account->data.minecraftProfile.name = username; account->data.minecraftProfile.validity = Katabasis::Validity::Certain; account->data.minecraftEntitlement.ownsMinecraft = true; @@ -109,13 +109,11 @@ MinecraftAccountPtr MinecraftAccount::createElyby(const QString &username) account->data.type = AccountType::Elyby; account->data.yggdrasilToken.extra["userName"] = username; account->data.yggdrasilToken.extra["clientToken"] = QUuid::createUuid().toString().remove(QRegExp("[{}-]")); - account->data.minecraftProfile.id = account->data.internalId; + account->data.minecraftProfile.id = uuidFromUsername(username).toString().remove(QRegExp("[{}-]")); account->data.minecraftProfile.name = username; account->data.minecraftProfile.validity = Katabasis::Validity::Certain; - account->data.validity_ = Katabasis::Validity::Certain; account->data.minecraftEntitlement.ownsMinecraft = true; account->data.minecraftEntitlement.canPlayMinecraft = true; - account->data.minecraftEntitlement.validity = Katabasis::Validity::Certain; return account; } @@ -180,6 +178,16 @@ shared_qobject_ptr MinecraftAccount::loginLocal() { return m_currentTask; } +shared_qobject_ptr MinecraftAccount::loginElyby(QString password) { + Q_ASSERT(m_currentTask.get() == nullptr); + + m_currentTask.reset(new ElybyLogin(&data, password)); + connect(m_currentTask.get(), SIGNAL(succeeded()), SLOT(authSucceeded())); + connect(m_currentTask.get(), SIGNAL(failed(QString)), SLOT(authFailed(QString))); + emit activityChanged(true); + return m_currentTask; +} + shared_qobject_ptr MinecraftAccount::refresh() { if(m_currentTask) { return m_currentTask; @@ -194,6 +202,9 @@ shared_qobject_ptr MinecraftAccount::refresh() { else if (data.type == AccountType::Local) { m_currentTask.reset(new LocalRefresh(&data)); } + else if (data.type == AccountType::Elyby) { + m_currentTask.reset(new ElybyRefresh(&data)); + } connect(m_currentTask.get(), SIGNAL(succeeded()), SLOT(authSucceeded())); connect(m_currentTask.get(), SIGNAL(failed(QString)), SLOT(authFailed(QString))); diff --git a/launcher/minecraft/auth/MinecraftAccount.h b/launcher/minecraft/auth/MinecraftAccount.h index 2bb2af057c..a82f14ea5e 100644 --- a/launcher/minecraft/auth/MinecraftAccount.h +++ b/launcher/minecraft/auth/MinecraftAccount.h @@ -98,6 +98,8 @@ class MinecraftAccount : shared_qobject_ptr loginLocal(); + shared_qobject_ptr loginElyby(QString password); + shared_qobject_ptr refresh(); shared_qobject_ptr currentTask(); diff --git a/launcher/minecraft/auth/flows/Elyby.cpp b/launcher/minecraft/auth/flows/Elyby.cpp new file mode 100644 index 0000000000..24ce24abea --- /dev/null +++ b/launcher/minecraft/auth/flows/Elyby.cpp @@ -0,0 +1,21 @@ +#include "Elyby.h" + +#include "minecraft/auth/steps/YggdrasilStep.h" +#include "minecraft/auth/steps/GetSkinStep.h" + +ElybyRefresh::ElybyRefresh( + AccountData *data, + QObject *parent +) : AuthFlow(data, parent) { + m_steps.append(new YggdrasilStep(m_data, QString())); + m_steps.append(new GetSkinStep(m_data)); +} + +ElybyLogin::ElybyLogin( + AccountData *data, + QString password, + QObject *parent +): AuthFlow(data, parent), m_password(password) { + m_steps.append(new YggdrasilStep(m_data, m_password)); + m_steps.append(new GetSkinStep(m_data)); +} diff --git a/launcher/minecraft/auth/flows/Elyby.h b/launcher/minecraft/auth/flows/Elyby.h new file mode 100644 index 0000000000..beec3e62a2 --- /dev/null +++ b/launcher/minecraft/auth/flows/Elyby.h @@ -0,0 +1,26 @@ +#pragma once +#include "AuthFlow.h" + +class ElybyRefresh : public AuthFlow +{ + Q_OBJECT +public: + explicit ElybyRefresh( + AccountData *data, + QObject *parent = 0 + ); +}; + +class ElybyLogin : public AuthFlow +{ + Q_OBJECT +public: + explicit ElybyLogin( + AccountData *data, + QString password, + QObject *parent = 0 + ); + +private: + QString m_password; +}; diff --git a/launcher/ui/dialogs/LoginDialog.cpp b/launcher/ui/dialogs/LoginDialog.cpp index a63c155564..f72c58b0a8 100644 --- a/launcher/ui/dialogs/LoginDialog.cpp +++ b/launcher/ui/dialogs/LoginDialog.cpp @@ -27,18 +27,6 @@ LoginDialog::LoginDialog(QWidget *parent) : QDialog(parent), ui(new Ui::LoginDia ui->progressBar->setVisible(false); ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); - for(auto provider: AuthProviders::getAll()) { - auto providerId = provider->id(); - // Exclude Microsoft and Local accounts from here... - if (providerId != "MSA" && providerId != "local") { - QRadioButton *button = new QRadioButton(provider->displayName()); - m_radioButtons[providerId] = button; - ui->radioLayout->addWidget(button); - } - } - m_radioButtons["elyby"]->setChecked(true); - adjustSize(); - connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); } @@ -54,16 +42,11 @@ void LoginDialog::accept() setUserInputsEnabled(false); ui->progressBar->setVisible(true); - m_account = MinecraftAccount::createFromUsername(ui->userTextBox->text()); - for(auto providerId: m_radioButtons.keys()){ - if(m_radioButtons[providerId]->isChecked()) { - m_account->setProvider(AuthProviders::lookup(providerId)); - break; - } - } + m_account = MinecraftAccount::createElyby(ui->userTextBox->text()); + m_account->setProvider(AuthProviders::lookup("elyby")); // Setup the login task and start it - m_loginTask = m_account->login(ui->passTextBox->text()); + m_loginTask = m_account->loginElyby(ui->passTextBox->text()); connect(m_loginTask.get(), &Task::failed, this, &LoginDialog::onTaskFailed); connect(m_loginTask.get(), &Task::succeeded, this, &LoginDialog::onTaskSucceeded); connect(m_loginTask.get(), &Task::status, this, &LoginDialog::onTaskStatus); diff --git a/launcher/ui/dialogs/LoginDialog.h b/launcher/ui/dialogs/LoginDialog.h index 8ecc66f573..f8101ff572 100644 --- a/launcher/ui/dialogs/LoginDialog.h +++ b/launcher/ui/dialogs/LoginDialog.h @@ -16,7 +16,6 @@ #pragma once #include -#include #include #include "minecraft/auth/MinecraftAccount.h" @@ -56,6 +55,5 @@ protected private: Ui::LoginDialog *ui; MinecraftAccountPtr m_account; - QMap m_radioButtons; Task::Ptr m_loginTask; }; diff --git a/launcher/ui/dialogs/LoginDialog.ui b/launcher/ui/dialogs/LoginDialog.ui index 489c49f6c7..8fa4a45d25 100644 --- a/launcher/ui/dialogs/LoginDialog.ui +++ b/launcher/ui/dialogs/LoginDialog.ui @@ -60,9 +60,6 @@ - - - diff --git a/launcher/ui/pages/global/AccountListPage.cpp b/launcher/ui/pages/global/AccountListPage.cpp index 8fb39a39f2..46c2cf1ad8 100644 --- a/launcher/ui/pages/global/AccountListPage.cpp +++ b/launcher/ui/pages/global/AccountListPage.cpp @@ -47,7 +47,7 @@ AccountListPage::AccountListPage(QWidget *parent) ui->listView->setEmptyString(tr( "Welcome!\n" "If you're new here, you can click the \"Add Local\" button to add your local account.\n" - "Or click the \"Add Premium\" button to add your Ely.by or Mojang account." + "Or click the \"Add Ely.by\" button to add your Ely.by account." )); ui->listView->setEmptyMode(VersionListView::String); ui->listView->setContextMenuPolicy(Qt::CustomContextMenu); @@ -161,7 +161,7 @@ void AccountListPage::on_actionAddMicrosoft_triggered() } MinecraftAccountPtr account = MSALoginDialog::newAccount( this, - tr("Please enter your account email and password to add your account.") + tr("Please enter your Mojang account email and password to add your account.") ); if (account) @@ -227,7 +227,7 @@ void AccountListPage::updateButtonStates() ui->actionSetDefault->setEnabled(accountIsReady); ui->actionUploadSkin->setEnabled(accountIsReady && accountIsOnline); ui->actionDeleteSkin->setEnabled(accountIsReady && accountIsOnline); - ui->actionRefresh->setEnabled(accountIsReady && accountIsOnline); + ui->actionRefresh->setEnabled(accountIsReady); if(m_accounts->defaultAccount().get() == nullptr) { ui->actionNoDefault->setEnabled(false); diff --git a/launcher/ui/pages/global/AccountListPage.ui b/launcher/ui/pages/global/AccountListPage.ui index a955ddd31b..3fefeff538 100644 --- a/launcher/ui/pages/global/AccountListPage.ui +++ b/launcher/ui/pages/global/AccountListPage.ui @@ -53,8 +53,8 @@ false - + @@ -70,7 +70,7 @@ - Add Premium + Add Ely.by