diff options
Diffstat (limited to 'launcher')
-rw-r--r-- | launcher/Application.cpp | 67 | ||||
-rw-r--r-- | launcher/LaunchController.cpp | 12 | ||||
-rw-r--r-- | launcher/minecraft/auth/AccountData.cpp | 5 | ||||
-rw-r--r-- | launcher/minecraft/auth/AccountData.h | 2 | ||||
-rw-r--r-- | launcher/minecraft/auth/AccountList.cpp | 3 | ||||
-rw-r--r-- | launcher/minecraft/auth/AccountTask.cpp | 8 | ||||
-rw-r--r-- | launcher/minecraft/auth/AccountTask.h | 1 | ||||
-rw-r--r-- | launcher/minecraft/auth/MinecraftAccount.cpp | 3 | ||||
-rw-r--r-- | launcher/minecraft/auth/steps/MSAStep.cpp | 8 | ||||
-rw-r--r-- | launcher/minecraft/auth/steps/MSAStep.h | 1 | ||||
-rw-r--r-- | launcher/ui/MainWindow.cpp | 2 |
11 files changed, 62 insertions, 50 deletions
diff --git a/launcher/Application.cpp b/launcher/Application.cpp index a3d6216e..e33df252 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -192,27 +192,6 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) #endif startTime = QDateTime::currentDateTime(); -#ifdef Q_OS_LINUX - { - QFile osrelease("/proc/sys/kernel/osrelease"); - if (osrelease.open(QFile::ReadOnly | QFile::Text)) { - QTextStream in(&osrelease); - auto contents = in.readAll(); - if( - contents.contains("WSL", Qt::CaseInsensitive) || - contents.contains("Microsoft", Qt::CaseInsensitive) - ) { - showFatalErrorMessage( - "Unsupported system detected!", - "Linux-on-Windows distributions are not supported.\n\n" - "Please use the Windows binary when playing on Windows." - ); - return; - } - } - } -#endif - // Don't quit on hiding the last window this->setQuitOnLastWindowClosed(false); @@ -285,12 +264,21 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) return; } } + m_instanceIdToLaunch = args["launch"].toString(); m_serverToJoin = args["server"].toString(); m_profileToUse = args["profile"].toString(); m_liveCheck = args["alive"].toBool(); m_zipToImport = args["import"].toUrl(); + // error if --launch is missing with --server or --profile + if((!m_serverToJoin.isEmpty() || !m_profileToUse.isEmpty()) && m_instanceIdToLaunch.isEmpty()) + { + std::cerr << "--server and --profile can only be used in combination with --launch!" << std::endl; + m_status = Application::Failed; + return; + } + QString origcwdPath = QDir::currentPath(); QString binPath = applicationDirPath(); QString adjustedBy; @@ -359,20 +347,6 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) return; } - if(m_instanceIdToLaunch.isEmpty() && !m_serverToJoin.isEmpty()) - { - std::cerr << "--server can only be used in combination with --launch!" << std::endl; - m_status = Application::Failed; - return; - } - - if(m_instanceIdToLaunch.isEmpty() && !m_profileToUse.isEmpty()) - { - std::cerr << "--account can only be used in combination with --launch!" << std::endl; - m_status = Application::Failed; - return; - } - #if defined(Q_OS_MAC) // move user data to new location if on macOS and it still exists in Contents/MacOS QDir fi(applicationDirPath()); @@ -566,26 +540,23 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) qDebug() << "<> Paths set."; } - do // once + if(m_liveCheck) { - if(m_liveCheck) + QFile check(liveCheckFile); + if(check.open(QIODevice::WriteOnly | QIODevice::Truncate)) { - QFile check(liveCheckFile); - if(!check.open(QIODevice::WriteOnly | QIODevice::Truncate)) - { - qWarning() << "Could not open" << liveCheckFile << "for writing!"; - break; - } auto payload = appID.toString().toUtf8(); - if(check.write(payload) != payload.size()) + if(check.write(payload) == payload.size()) { + check.close(); + } else { qWarning() << "Could not write into" << liveCheckFile << "!"; - check.remove(); - break; + check.remove(); // also closes file! } - check.close(); + } else { + qWarning() << "Could not open" << liveCheckFile << "for writing!"; } - } while(false); + } // Initialize application settings { diff --git a/launcher/LaunchController.cpp b/launcher/LaunchController.cpp index 32fc99cb..40178b70 100644 --- a/launcher/LaunchController.cpp +++ b/launcher/LaunchController.cpp @@ -228,6 +228,18 @@ void LaunchController::login() { emitFailed(errorString); return; } + case AccountState::Disabled: { + auto errorString = tr("The launcher's client identification has changed. Please remove this account and add it again."); + QMessageBox::warning( + m_parentWidget, + tr("Client identification changed"), + errorString, + QMessageBox::StandardButton::Ok, + QMessageBox::StandardButton::Ok + ); + emitFailed(errorString); + return; + } case AccountState::Gone: { auto errorString = tr("The account no longer exists on the servers. It may have been migrated, in which case please add the new account you migrated this one to."); QMessageBox::warning( diff --git a/launcher/minecraft/auth/AccountData.cpp b/launcher/minecraft/auth/AccountData.cpp index 9b84fe1a..f791db14 100644 --- a/launcher/minecraft/auth/AccountData.cpp +++ b/launcher/minecraft/auth/AccountData.cpp @@ -327,6 +327,10 @@ bool AccountData::resumeStateFromV3(QJsonObject data) { } if(type == AccountType::MSA) { + auto clientIDV = data.value("msa-client-id"); + if (clientIDV.isString()) { + msaClientID = clientIDV.toString(); + } // leave msaClientID empty if it doesn't exist or isn't a string msaToken = tokenFromJSONV3(data, "msa"); userToken = tokenFromJSONV3(data, "utoken"); xboxApiToken = tokenFromJSONV3(data, "xrp-main"); @@ -360,6 +364,7 @@ QJsonObject AccountData::saveState() const { } else if (type == AccountType::MSA) { output["type"] = "MSA"; + output["msa-client-id"] = msaClientID; tokenToJSONV3(output, msaToken, "msa"); tokenToJSONV3(output, userToken, "utoken"); tokenToJSONV3(output, xboxApiToken, "xrp-main"); diff --git a/launcher/minecraft/auth/AccountData.h b/launcher/minecraft/auth/AccountData.h index 606c1ad1..6749a471 100644 --- a/launcher/minecraft/auth/AccountData.h +++ b/launcher/minecraft/auth/AccountData.h @@ -47,6 +47,7 @@ enum class AccountState { Offline, Working, Online, + Disabled, Errored, Expired, Gone @@ -81,6 +82,7 @@ struct AccountData { bool legacy = false; bool canMigrateToMSA = false; + QString msaClientID; Katabasis::Token msaToken; Katabasis::Token userToken; Katabasis::Token xboxApiToken; diff --git a/launcher/minecraft/auth/AccountList.cpp b/launcher/minecraft/auth/AccountList.cpp index 04470e1c..e404cdda 100644 --- a/launcher/minecraft/auth/AccountList.cpp +++ b/launcher/minecraft/auth/AccountList.cpp @@ -291,6 +291,9 @@ QVariant AccountList::data(const QModelIndex &index, int role) const case AccountState::Expired: { return tr("Expired", "Account status"); } + case AccountState::Disabled: { + return tr("Disabled", "Account status"); + } case AccountState::Gone: { return tr("Gone", "Account status"); } diff --git a/launcher/minecraft/auth/AccountTask.cpp b/launcher/minecraft/auth/AccountTask.cpp index 98d8d94d..321b350f 100644 --- a/launcher/minecraft/auth/AccountTask.cpp +++ b/launcher/minecraft/auth/AccountTask.cpp @@ -43,6 +43,8 @@ QString AccountTask::getStateMessage() const return tr("Authentication task succeeded."); case AccountTaskState::STATE_OFFLINE: return tr("Failed to contact the authentication server."); + case AccountTaskState::STATE_DISABLED: + return tr("Client ID has changed. New session needs to be created."); case AccountTaskState::STATE_FAILED_SOFT: return tr("Encountered an error during authentication."); case AccountTaskState::STATE_FAILED_HARD: @@ -78,6 +80,12 @@ bool AccountTask::changeState(AccountTaskState newState, QString reason) emitFailed(reason); return false; } + case AccountTaskState::STATE_DISABLED: { + m_data->errorString = reason; + m_data->accountState = AccountState::Disabled; + emitFailed(reason); + return false; + } case AccountTaskState::STATE_FAILED_SOFT: { m_data->errorString = reason; m_data->accountState = AccountState::Errored; diff --git a/launcher/minecraft/auth/AccountTask.h b/launcher/minecraft/auth/AccountTask.h index dac3f1b5..c2a5d86c 100644 --- a/launcher/minecraft/auth/AccountTask.h +++ b/launcher/minecraft/auth/AccountTask.h @@ -35,6 +35,7 @@ enum class AccountTaskState STATE_CREATED, STATE_WORKING, STATE_SUCCEEDED, + STATE_DISABLED, //!< MSA Client ID has changed. Tell user to reloginn STATE_FAILED_SOFT, //!< soft failure. authentication went through partially STATE_FAILED_HARD, //!< hard failure. main tokens are invalid STATE_FAILED_GONE, //!< hard failure. main tokens are invalid, and the account no longer exists diff --git a/launcher/minecraft/auth/MinecraftAccount.cpp b/launcher/minecraft/auth/MinecraftAccount.cpp index ffc81ed8..a604cadf 100644 --- a/launcher/minecraft/auth/MinecraftAccount.cpp +++ b/launcher/minecraft/auth/MinecraftAccount.cpp @@ -176,6 +176,9 @@ void MinecraftAccount::authFailed(QString reason) { switch (m_currentTask->taskState()) { case AccountTaskState::STATE_OFFLINE: + case AccountTaskState::STATE_DISABLED: { + // NOTE: user will need to fix this themselves. + } case AccountTaskState::STATE_FAILED_SOFT: { // NOTE: this doesn't do much. There was an error of some sort. } diff --git a/launcher/minecraft/auth/steps/MSAStep.cpp b/launcher/minecraft/auth/steps/MSAStep.cpp index 779aee43..207d9373 100644 --- a/launcher/minecraft/auth/steps/MSAStep.cpp +++ b/launcher/minecraft/auth/steps/MSAStep.cpp @@ -12,9 +12,10 @@ using OAuth2 = Katabasis::DeviceFlow; using Activity = Katabasis::Activity; MSAStep::MSAStep(AccountData* data, Action action) : AuthStep(data), m_action(action) { + m_clientId = APPLICATION->getMSAClientID(); OAuth2::Options opts; opts.scope = "XboxLive.signin offline_access"; - opts.clientIdentifier = APPLICATION->getMSAClientID(); + opts.clientIdentifier = m_clientId; opts.authorizationUrl = "https://login.microsoftonline.com/consumers/oauth2/v2.0/devicecode"; opts.accessTokenUrl = "https://login.microsoftonline.com/consumers/oauth2/v2.0/token"; @@ -48,6 +49,10 @@ void MSAStep::rehydrate() { void MSAStep::perform() { switch(m_action) { case Refresh: { + if (m_data->msaClientID != m_clientId) { + emit hideVerificationUriAndCode(); + emit finished(AccountTaskState::STATE_DISABLED, tr("Microsoft user authentication failed - client identification has changed.")); + } m_oauth2->refresh(); return; } @@ -57,6 +62,7 @@ void MSAStep::perform() { m_oauth2->setExtraRequestParams(extraOpts); *m_data = AccountData(); + m_data->msaClientID = m_clientId; m_oauth2->login(); return; } diff --git a/launcher/minecraft/auth/steps/MSAStep.h b/launcher/minecraft/auth/steps/MSAStep.h index 49ba3542..301e1465 100644 --- a/launcher/minecraft/auth/steps/MSAStep.h +++ b/launcher/minecraft/auth/steps/MSAStep.h @@ -29,4 +29,5 @@ private slots: private: Katabasis::DeviceFlow *m_oauth2 = nullptr; Action m_action; + QString m_clientId; }; diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 32b27afb..ad7227cc 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -588,7 +588,7 @@ public: actionExportInstance = TranslatedAction(MainWindow); actionExportInstance->setObjectName(QStringLiteral("actionExportInstance")); actionExportInstance.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Export Instance")); - // FIXME: missing tooltip + actionExportInstance.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Export the selected instance as a zip file.")); all_actions.append(&actionExportInstance); instanceToolBar->addAction(actionExportInstance); |