From 7166d68736e17573b2bd04d78d5a8a61433f5948 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Tue, 31 Oct 2023 00:45:18 +0200 Subject: [PATCH 1/5] fixed account refresh after sleep Signed-off-by: Trial97 --- launcher/LaunchController.cpp | 41 ++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/launcher/LaunchController.cpp b/launcher/LaunchController.cpp index 9fb385777..8844ae105 100644 --- a/launcher/LaunchController.cpp +++ b/launcher/LaunchController.cpp @@ -36,12 +36,14 @@ #include "LaunchController.h" #include "Application.h" +#include "minecraft/auth/AccountData.h" #include "minecraft/auth/AccountList.h" #include "ui/InstanceWindow.h" #include "ui/MainWindow.h" #include "ui/dialogs/CustomMessageBox.h" #include "ui/dialogs/EditAccountDialog.h" +#include "ui/dialogs/MSALoginDialog.h" #include "ui/dialogs/ProfileSelectDialog.h" #include "ui/dialogs/ProfileSetupDialog.h" #include "ui/dialogs/ProgressDialog.h" @@ -154,6 +156,12 @@ void LaunchController::login() return; } } + if (!m_accountToUse->isOffline() && m_accountToUse->accountState() == AccountState::Offline && tries == 0) { + // Force account refresh on the account used to launch the instance updating the AccountState + // only on first try and if it is not meant to be offline + auto accounts = APPLICATION->accounts(); + accounts->requestRefresh(m_accountToUse->internalId()); + } tries++; m_session = std::make_shared(); m_session->wants_online = m_online; @@ -249,17 +257,30 @@ void LaunchController::login() progDialog.execWithTask(task.get()); continue; } - // FIXME: this is missing - the meaning is that the account is queued for refresh and we should wait for that - /* - case AccountState::Queued: { - return; - } - */ case AccountState::Expired: { - auto errorString = tr("The account has expired and needs to be logged into manually again."); - QMessageBox::warning(m_parentWidget, tr("Account refresh failed"), errorString, QMessageBox::StandardButton::Ok, - QMessageBox::StandardButton::Ok); - emitFailed(errorString); + auto errorString = tr("The account has expired and needs to be logged into manually. Press OK to log in again."); + auto button = QMessageBox::warning(m_parentWidget, tr("Account refresh failed"), errorString, + QMessageBox::StandardButton::Ok | QMessageBox::StandardButton::Cancel, + QMessageBox::StandardButton::Ok); + if (button == QMessageBox::StandardButton::Ok) { + auto accounts = APPLICATION->accounts(); + bool isDefault = accounts->defaultAccount() == m_accountToUse; + accounts->removeAccount(accounts->index(accounts->findAccountByProfileId(m_accountToUse->profileId()))); + if (m_accountToUse->isMSA()) { + auto newAccount = MSALoginDialog::newAccount( + m_parentWidget, tr("Please enter your Mojang account email and password to add your account.")); + accounts->addAccount(newAccount); + if (isDefault) { + accounts->setDefaultAccount(newAccount); + } + m_accountToUse = nullptr; + decideAccount(); + continue; + } + emitFailed(tr("Account expired and re-login attempt failed")); + } else { + emitFailed(errorString); + } return; } case AccountState::Disabled: { From 2863a691ef4687eefa47e8fbfd4e5f6e06cce877 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Tue, 31 Oct 2023 08:45:08 +0200 Subject: [PATCH 2/5] moved refresh out of the loop Signed-off-by: Trial97 --- launcher/LaunchController.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/launcher/LaunchController.cpp b/launcher/LaunchController.cpp index 8844ae105..2c76fee4f 100644 --- a/launcher/LaunchController.cpp +++ b/launcher/LaunchController.cpp @@ -145,6 +145,12 @@ void LaunchController::login() bool tryagain = true; unsigned int tries = 0; + if (!m_accountToUse->isOffline() && m_accountToUse->accountState() == AccountState::Offline) { + // Force account refresh on the account used to launch the instance updating the AccountState + // only on first try and if it is not meant to be offline + auto accounts = APPLICATION->accounts(); + accounts->requestRefresh(m_accountToUse->internalId()); + } while (tryagain) { if (tries > 0 && tries % 3 == 0) { auto result = @@ -156,12 +162,6 @@ void LaunchController::login() return; } } - if (!m_accountToUse->isOffline() && m_accountToUse->accountState() == AccountState::Offline && tries == 0) { - // Force account refresh on the account used to launch the instance updating the AccountState - // only on first try and if it is not meant to be offline - auto accounts = APPLICATION->accounts(); - accounts->requestRefresh(m_accountToUse->internalId()); - } tries++; m_session = std::make_shared(); m_session->wants_online = m_online; From ceb88a170e4851baa722761235736fb9d025fb31 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Thu, 23 Nov 2023 12:22:31 +0200 Subject: [PATCH 3/5] Extracted reauthenticateCurrentAccount as a separate function Signed-off-by: Trial97 --- launcher/LaunchController.cpp | 53 ++++++++++++++++++++--------------- launcher/LaunchController.h | 1 + 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/launcher/LaunchController.cpp b/launcher/LaunchController.cpp index 2c76fee4f..a72cc58b1 100644 --- a/launcher/LaunchController.cpp +++ b/launcher/LaunchController.cpp @@ -258,29 +258,8 @@ void LaunchController::login() continue; } case AccountState::Expired: { - auto errorString = tr("The account has expired and needs to be logged into manually. Press OK to log in again."); - auto button = QMessageBox::warning(m_parentWidget, tr("Account refresh failed"), errorString, - QMessageBox::StandardButton::Ok | QMessageBox::StandardButton::Cancel, - QMessageBox::StandardButton::Ok); - if (button == QMessageBox::StandardButton::Ok) { - auto accounts = APPLICATION->accounts(); - bool isDefault = accounts->defaultAccount() == m_accountToUse; - accounts->removeAccount(accounts->index(accounts->findAccountByProfileId(m_accountToUse->profileId()))); - if (m_accountToUse->isMSA()) { - auto newAccount = MSALoginDialog::newAccount( - m_parentWidget, tr("Please enter your Mojang account email and password to add your account.")); - accounts->addAccount(newAccount); - if (isDefault) { - accounts->setDefaultAccount(newAccount); - } - m_accountToUse = nullptr; - decideAccount(); - continue; - } - emitFailed(tr("Account expired and re-login attempt failed")); - } else { - emitFailed(errorString); - } + if (reauthenticateCurrentAccount()) + continue; return; } case AccountState::Disabled: { @@ -304,6 +283,34 @@ void LaunchController::login() emitFailed(tr("Failed to launch.")); } +bool LaunchController::reauthenticateCurrentAccount() +{ + auto button = + QMessageBox::warning(m_parentWidget, tr("Account refresh failed"), + tr("The account has expired and needs to be reauthenticated. Do you want to reauthenticate this account?"), + QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, QMessageBox::StandardButton::Yes); + if (button == QMessageBox::StandardButton::Yes) { + auto accounts = APPLICATION->accounts(); + bool isDefault = accounts->defaultAccount() == m_accountToUse; + accounts->removeAccount(accounts->index(accounts->findAccountByProfileId(m_accountToUse->profileId()))); + if (m_accountToUse->isMSA()) { + auto newAccount = + MSALoginDialog::newAccount(m_parentWidget, tr("Please enter your Mojang account email and password to add your account.")); + accounts->addAccount(newAccount); + if (isDefault) { + accounts->setDefaultAccount(newAccount); + } + m_accountToUse = nullptr; + decideAccount(); + return true; + } + emitFailed(tr("Account expired and re-login attempt failed")); + } else { + emitFailed(tr("The account has expired and needs to be reauthenticated")); + } + return false; +} + void LaunchController::launchInstance() { Q_ASSERT_X(m_instance != NULL, "launchInstance", "instance is NULL"); diff --git a/launcher/LaunchController.h b/launcher/LaunchController.h index f1c88afb7..33aedb063 100644 --- a/launcher/LaunchController.h +++ b/launcher/LaunchController.h @@ -74,6 +74,7 @@ class LaunchController : public Task { void login(); void launchInstance(); void decideAccount(); + bool reauthenticateCurrentAccount(); private slots: void readyForLaunch(); From 93454163618f4500732a079b7943db2fbe22fc66 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Thu, 23 Nov 2023 12:29:42 +0200 Subject: [PATCH 4/5] Fixed localization stuff Signed-off-by: Trial97 --- launcher/LaunchController.cpp | 5 ++--- launcher/minecraft/auth/AccountList.cpp | 2 -- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/launcher/LaunchController.cpp b/launcher/LaunchController.cpp index 271297d5c..3f3cf2e7e 100644 --- a/launcher/LaunchController.cpp +++ b/launcher/LaunchController.cpp @@ -42,7 +42,6 @@ #include "ui/InstanceWindow.h" #include "ui/MainWindow.h" #include "ui/dialogs/CustomMessageBox.h" -#include "ui/dialogs/EditAccountDialog.h" #include "ui/dialogs/MSALoginDialog.h" #include "ui/dialogs/ProfileSelectDialog.h" #include "ui/dialogs/ProfileSetupDialog.h" @@ -145,7 +144,7 @@ void LaunchController::login() bool tryagain = true; unsigned int tries = 0; - if (!m_accountToUse->isOffline() && m_accountToUse->accountState() == AccountState::Offline) { + if (m_accountToUse->accountType() != AccountType::Offline && m_accountToUse->accountState() == AccountState::Offline) { // Force account refresh on the account used to launch the instance updating the AccountState // only on first try and if it is not meant to be offline auto accounts = APPLICATION->accounts(); @@ -293,7 +292,7 @@ bool LaunchController::reauthenticateCurrentAccount() auto accounts = APPLICATION->accounts(); bool isDefault = accounts->defaultAccount() == m_accountToUse; accounts->removeAccount(accounts->index(accounts->findAccountByProfileId(m_accountToUse->profileId()))); - if (m_accountToUse->isMSA()) { + if (m_accountToUse->accountType() == AccountType::MSA) { auto newAccount = MSALoginDialog::newAccount(m_parentWidget, tr("Please enter your Mojang account email and password to add your account.")); accounts->addAccount(newAccount); diff --git a/launcher/minecraft/auth/AccountList.cpp b/launcher/minecraft/auth/AccountList.cpp index c3c09003c..68ebe3626 100644 --- a/launcher/minecraft/auth/AccountList.cpp +++ b/launcher/minecraft/auth/AccountList.cpp @@ -52,8 +52,6 @@ #include #include -#include - enum AccountListVersion { MojangMSA = 3 }; AccountList::AccountList(QObject* parent) : QAbstractListModel(parent) From 400b518bc21b8a56131384fd4a56988d31bceb9f Mon Sep 17 00:00:00 2001 From: Trial97 Date: Thu, 14 Dec 2023 00:02:15 +0200 Subject: [PATCH 5/5] Removed auto reauthenticate Signed-off-by: Trial97 --- launcher/LaunchController.cpp | 35 ++++------------------------------- launcher/LaunchController.h | 1 - 2 files changed, 4 insertions(+), 32 deletions(-) diff --git a/launcher/LaunchController.cpp b/launcher/LaunchController.cpp index 3f3cf2e7e..a30f99439 100644 --- a/launcher/LaunchController.cpp +++ b/launcher/LaunchController.cpp @@ -42,7 +42,6 @@ #include "ui/InstanceWindow.h" #include "ui/MainWindow.h" #include "ui/dialogs/CustomMessageBox.h" -#include "ui/dialogs/MSALoginDialog.h" #include "ui/dialogs/ProfileSelectDialog.h" #include "ui/dialogs/ProfileSetupDialog.h" #include "ui/dialogs/ProgressDialog.h" @@ -257,8 +256,10 @@ void LaunchController::login() continue; } case AccountState::Expired: { - if (reauthenticateCurrentAccount()) - continue; + auto errorString = tr("The account has expired and needs to be logged into manually again."); + QMessageBox::warning(m_parentWidget, tr("Account refresh failed"), errorString, QMessageBox::StandardButton::Ok, + QMessageBox::StandardButton::Ok); + emitFailed(errorString); return; } case AccountState::Disabled: { @@ -282,34 +283,6 @@ void LaunchController::login() emitFailed(tr("Failed to launch.")); } -bool LaunchController::reauthenticateCurrentAccount() -{ - auto button = - QMessageBox::warning(m_parentWidget, tr("Account refresh failed"), - tr("The account has expired and needs to be reauthenticated. Do you want to reauthenticate this account?"), - QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, QMessageBox::StandardButton::Yes); - if (button == QMessageBox::StandardButton::Yes) { - auto accounts = APPLICATION->accounts(); - bool isDefault = accounts->defaultAccount() == m_accountToUse; - accounts->removeAccount(accounts->index(accounts->findAccountByProfileId(m_accountToUse->profileId()))); - if (m_accountToUse->accountType() == AccountType::MSA) { - auto newAccount = - MSALoginDialog::newAccount(m_parentWidget, tr("Please enter your Mojang account email and password to add your account.")); - accounts->addAccount(newAccount); - if (isDefault) { - accounts->setDefaultAccount(newAccount); - } - m_accountToUse = nullptr; - decideAccount(); - return true; - } - emitFailed(tr("Account expired and re-login attempt failed")); - } else { - emitFailed(tr("The account has expired and needs to be reauthenticated")); - } - return false; -} - void LaunchController::launchInstance() { Q_ASSERT_X(m_instance != NULL, "launchInstance", "instance is NULL"); diff --git a/launcher/LaunchController.h b/launcher/LaunchController.h index 33aedb063..f1c88afb7 100644 --- a/launcher/LaunchController.h +++ b/launcher/LaunchController.h @@ -74,7 +74,6 @@ class LaunchController : public Task { void login(); void launchInstance(); void decideAccount(); - bool reauthenticateCurrentAccount(); private slots: void readyForLaunch();