aboutsummaryrefslogtreecommitdiff
path: root/launcher
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2021-07-26 21:44:11 +0200
committerPetr Mrázek <peterix@gmail.com>2021-08-15 23:18:50 +0200
commit3a53349e332599221bc325f7fac9dc7927194bc2 (patch)
tree2ee40fa6044c241b3b7db27fe0b83931b453c2b2 /launcher
parentfca2e9e44cb44004eec7f47c03b186bd5e44dc32 (diff)
downloadPrismLauncher-3a53349e332599221bc325f7fac9dc7927194bc2.tar.gz
PrismLauncher-3a53349e332599221bc325f7fac9dc7927194bc2.tar.bz2
PrismLauncher-3a53349e332599221bc325f7fac9dc7927194bc2.zip
GH-3392 dirty initial MSA support that shares logic with Mojang flows
Both act as the first step of AuthContext.
Diffstat (limited to 'launcher')
-rw-r--r--launcher/BaseInstance.h2
-rw-r--r--launcher/CMakeLists.txt39
-rw-r--r--launcher/Env.cpp1
-rw-r--r--launcher/LaunchController.cpp171
-rw-r--r--launcher/MainWindow.cpp158
-rw-r--r--launcher/MainWindow.h5
-rw-r--r--launcher/MultiMC.cpp4
-rw-r--r--launcher/MultiMC.h6
-rw-r--r--launcher/SkinUtils.cpp4
-rw-r--r--launcher/dialogs/LoginDialog.cpp9
-rw-r--r--launcher/dialogs/LoginDialog.h6
-rw-r--r--launcher/dialogs/LoginDialog.ui12
-rw-r--r--launcher/dialogs/MSALoginDialog.cpp96
-rw-r--r--launcher/dialogs/MSALoginDialog.h55
-rw-r--r--launcher/dialogs/MSALoginDialog.ui60
-rw-r--r--launcher/dialogs/ProfileSelectDialog.cpp32
-rw-r--r--launcher/dialogs/ProfileSelectDialog.h8
-rw-r--r--launcher/dialogs/SkinUploadDialog.cpp2
-rw-r--r--launcher/dialogs/SkinUploadDialog.h6
-rw-r--r--launcher/minecraft/MinecraftInstance.cpp16
-rw-r--r--launcher/minecraft/auth-msa/BuildConfig.cpp.in9
-rw-r--r--launcher/minecraft/auth-msa/BuildConfig.h11
-rw-r--r--launcher/minecraft/auth-msa/CMakeLists.txt28
-rw-r--r--launcher/minecraft/auth-msa/main.cpp100
-rw-r--r--launcher/minecraft/auth-msa/mainwindow.cpp97
-rw-r--r--launcher/minecraft/auth-msa/mainwindow.h34
-rw-r--r--launcher/minecraft/auth-msa/mainwindow.ui72
-rw-r--r--launcher/minecraft/auth/AccountData.cpp387
-rw-r--r--launcher/minecraft/auth/AccountData.h73
-rw-r--r--launcher/minecraft/auth/AccountList.cpp (renamed from launcher/minecraft/auth/MojangAccountList.cpp)321
-rw-r--r--launcher/minecraft/auth/AccountList.h118
-rw-r--r--launcher/minecraft/auth/AccountTask.cpp69
-rw-r--r--launcher/minecraft/auth/AccountTask.h (renamed from launcher/minecraft/auth/YggdrasilTask.h)78
-rw-r--r--launcher/minecraft/auth/AuthSession.cpp2
-rw-r--r--launcher/minecraft/auth/AuthSession.h13
-rw-r--r--launcher/minecraft/auth/MinecraftAccount.cpp303
-rw-r--r--launcher/minecraft/auth/MinecraftAccount.h (renamed from launcher/minecraft/auth/MojangAccount.h)120
-rw-r--r--launcher/minecraft/auth/MojangAccount.cpp315
-rw-r--r--launcher/minecraft/auth/MojangAccountList.h199
-rw-r--r--launcher/minecraft/auth/flows/AuthContext.cpp (renamed from launcher/minecraft/auth-msa/context.cpp)508
-rw-r--r--launcher/minecraft/auth/flows/AuthContext.h (renamed from launcher/minecraft/auth-msa/context.h)108
-rw-r--r--launcher/minecraft/auth/flows/AuthenticateTask.cpp202
-rw-r--r--launcher/minecraft/auth/flows/AuthenticateTask.h46
-rw-r--r--launcher/minecraft/auth/flows/MSAHelper.txt51
-rw-r--r--launcher/minecraft/auth/flows/MSAInteractive.cpp20
-rw-r--r--launcher/minecraft/auth/flows/MSAInteractive.h10
-rw-r--r--launcher/minecraft/auth/flows/MSASilent.cpp16
-rw-r--r--launcher/minecraft/auth/flows/MSASilent.h10
-rw-r--r--launcher/minecraft/auth/flows/MojangLogin.cpp14
-rw-r--r--launcher/minecraft/auth/flows/MojangLogin.h13
-rw-r--r--launcher/minecraft/auth/flows/MojangRefresh.cpp14
-rw-r--r--launcher/minecraft/auth/flows/MojangRefresh.h10
-rw-r--r--launcher/minecraft/auth/flows/RefreshTask.cpp144
-rw-r--r--launcher/minecraft/auth/flows/RefreshTask.h44
-rw-r--r--launcher/minecraft/auth/flows/ValidateTask.cpp61
-rw-r--r--launcher/minecraft/auth/flows/ValidateTask.h47
-rw-r--r--launcher/minecraft/auth/flows/Yggdrasil.cpp (renamed from launcher/minecraft/auth/YggdrasilTask.cpp)224
-rw-r--r--launcher/minecraft/auth/flows/Yggdrasil.h82
-rw-r--r--launcher/minecraft/launch/ClaimAccount.h4
-rw-r--r--launcher/pages/global/AccountListPage.cpp80
-rw-r--r--launcher/pages/global/AccountListPage.h8
-rw-r--r--launcher/pages/global/AccountListPage.ui30
-rw-r--r--launcher/pages/instance/VersionPage.cpp2
63 files changed, 2323 insertions, 2466 deletions
diff --git a/launcher/BaseInstance.h b/launcher/BaseInstance.h
index 833646c0..8c08dc05 100644
--- a/launcher/BaseInstance.h
+++ b/launcher/BaseInstance.h
@@ -26,7 +26,7 @@
#include "settings/INIFile.h"
#include "BaseVersionList.h"
-#include "minecraft/auth/MojangAccount.h"
+#include "minecraft/auth/MinecraftAccount.h"
#include "MessageLevel.h"
#include "pathmatcher/IPathMatcher.h"
diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt
index 37f5d3a1..3c140ede 100644
--- a/launcher/CMakeLists.txt
+++ b/launcher/CMakeLists.txt
@@ -203,20 +203,31 @@ set(STATUS_SOURCES
# Support for Minecraft instances and launch
set(MINECRAFT_SOURCES
# Minecraft support
+ minecraft/auth/AccountData.h
+ minecraft/auth/AccountData.cpp
+ minecraft/auth/AccountTask.h
+ minecraft/auth/AccountTask.cpp
minecraft/auth/AuthSession.h
minecraft/auth/AuthSession.cpp
- minecraft/auth/MojangAccountList.h
- minecraft/auth/MojangAccountList.cpp
- minecraft/auth/MojangAccount.h
- minecraft/auth/MojangAccount.cpp
- minecraft/auth/YggdrasilTask.h
- minecraft/auth/YggdrasilTask.cpp
- minecraft/auth/flows/AuthenticateTask.h
- minecraft/auth/flows/AuthenticateTask.cpp
- minecraft/auth/flows/RefreshTask.cpp
- minecraft/auth/flows/RefreshTask.cpp
- minecraft/auth/flows/ValidateTask.h
- minecraft/auth/flows/ValidateTask.cpp
+ minecraft/auth/AccountList.h
+ minecraft/auth/AccountList.cpp
+ minecraft/auth/MinecraftAccount.h
+ minecraft/auth/MinecraftAccount.cpp
+ minecraft/auth/flows/AuthContext.h
+ minecraft/auth/flows/AuthContext.cpp
+
+ minecraft/auth/flows/MSAInteractive.h
+ minecraft/auth/flows/MSAInteractive.cpp
+ minecraft/auth/flows/MSASilent.h
+ minecraft/auth/flows/MSASilent.cpp
+
+ minecraft/auth/flows/MojangLogin.h
+ minecraft/auth/flows/MojangLogin.cpp
+ minecraft/auth/flows/MojangRefresh.h
+ minecraft/auth/flows/MojangRefresh.cpp
+
+ minecraft/auth/flows/Yggdrasil.h
+ minecraft/auth/flows/Yggdrasil.cpp
minecraft/gameoptions/GameOptions.h
minecraft/gameoptions/GameOptions.cpp
@@ -732,6 +743,8 @@ SET(MULTIMC_SOURCES
dialogs/IconPickerDialog.h
dialogs/LoginDialog.cpp
dialogs/LoginDialog.h
+ dialogs/MSALoginDialog.cpp
+ dialogs/MSALoginDialog.h
dialogs/NewComponentDialog.cpp
dialogs/NewComponentDialog.h
dialogs/NewInstanceDialog.cpp
@@ -850,6 +863,7 @@ SET(MULTIMC_UIS
dialogs/EditAccountDialog.ui
dialogs/ExportInstanceDialog.ui
dialogs/LoginDialog.ui
+ dialogs/MSALoginDialog.ui
dialogs/UpdateDialog.ui
dialogs/NotificationDialog.ui
dialogs/SkinUploadDialog.ui
@@ -892,6 +906,7 @@ target_link_libraries(MultiMC_logic
optional-bare
tomlc99
BuildConfig
+ Katabasis
)
target_link_libraries(MultiMC_logic
Qt5::Core
diff --git a/launcher/Env.cpp b/launcher/Env.cpp
index 71b49d95..abf9f58c 100644
--- a/launcher/Env.cpp
+++ b/launcher/Env.cpp
@@ -101,7 +101,6 @@ void Env::initHttpMetaCache()
m_metacache->addBase("ModpacksCHPacks", QDir("cache/ModpacksCHPacks").absolutePath());
m_metacache->addBase("TechnicPacks", QDir("cache/TechnicPacks").absolutePath());
m_metacache->addBase("FlamePacks", QDir("cache/FlamePacks").absolutePath());
- m_metacache->addBase("skins", QDir("accounts/skins").absolutePath());
m_metacache->addBase("root", QDir::currentPath());
m_metacache->addBase("translations", QDir("translations").absolutePath());
m_metacache->addBase("icons", QDir("cache/icons").absolutePath());
diff --git a/launcher/LaunchController.cpp b/launcher/LaunchController.cpp
index ee764082..11780625 100644
--- a/launcher/LaunchController.cpp
+++ b/launcher/LaunchController.cpp
@@ -1,6 +1,6 @@
#include "LaunchController.h"
#include "MainWindow.h"
-#include <minecraft/auth/MojangAccountList.h>
+#include <minecraft/auth/AccountList.h>
#include "MultiMC.h"
#include "dialogs/CustomMessageBox.h"
#include "dialogs/ProfileSelectDialog.h"
@@ -12,7 +12,7 @@
#include <QLineEdit>
#include <QInputDialog>
#include <tasks/Task.h>
-#include <minecraft/auth/YggdrasilTask.h>
+#include <minecraft/auth/AccountTask.h>
#include <launch/steps/TextPrint.h>
#include <QStringList>
#include <QHostInfo>
@@ -35,22 +35,23 @@ void LaunchController::executeTask()
}
// FIXME: minecraft specific
-void LaunchController::login()
-{
+void LaunchController::login() {
JavaCommon::checkJVMArgs(m_instance->settings()->get("JvmArgs").toString(), m_parentWidget);
// Find an account to use.
- std::shared_ptr<MojangAccountList> accounts = MMC->accounts();
- MojangAccountPtr account = accounts->activeAccount();
+ std::shared_ptr<AccountList> accounts = MMC->accounts();
if (accounts->count() <= 0)
{
// Tell the user they need to log in at least one account in order to play.
auto reply = CustomMessageBox::selectable(
- m_parentWidget, tr("No Accounts"),
+ m_parentWidget,
+ tr("No Accounts"),
tr("In order to play Minecraft, you must have at least one Mojang or Minecraft "
"account logged in to MultiMC."
"Would you like to open the account manager to add an account now?"),
- QMessageBox::Information, QMessageBox::Yes | QMessageBox::No)->exec();
+ QMessageBox::Information,
+ QMessageBox::Yes | QMessageBox::No
+ )->exec();
if (reply == QMessageBox::Yes)
{
@@ -58,11 +59,16 @@ void LaunchController::login()
MMC->ShowGlobalSettings(m_parentWidget, "accounts");
}
}
- else if (account.get() == nullptr)
+
+ MinecraftAccountPtr account = accounts->activeAccount();
+ if (account.get() == nullptr)
{
// If no default account is set, ask the user which one to use.
- ProfileSelectDialog selectDialog(tr("Which profile would you like to use?"),
- ProfileSelectDialog::GlobalDefaultCheckbox, m_parentWidget);
+ ProfileSelectDialog selectDialog(
+ tr("Which account would you like to use?"),
+ ProfileSelectDialog::GlobalDefaultCheckbox,
+ m_parentWidget
+ );
selectDialog.exec();
@@ -70,8 +76,9 @@ void LaunchController::login()
account = selectDialog.selectedAccount();
// If the user said to use the account as default, do that.
- if (selectDialog.useAsGlobalDefault() && account.get() != nullptr)
- accounts->setActiveAccount(account->username());
+ if (selectDialog.useAsGlobalDefault() && account.get() != nullptr) {
+ accounts->setActiveAccount(account->profileId());
+ }
}
// if no account is selected, we bail
@@ -93,7 +100,13 @@ void LaunchController::login()
{
m_session = std::make_shared<AuthSession>();
m_session->wants_online = m_online;
- auto task = account->login(m_session, password);
+ std::shared_ptr<AccountTask> task;
+ if(!password.isNull()) {
+ task = account->login(m_session, password);
+ }
+ else {
+ task = account->refresh(m_session);
+ }
if (task)
{
// We'll need to validate the access token to make sure the account
@@ -107,9 +120,9 @@ void LaunchController::login()
if (!task->wasSuccessful())
{
auto failReasonNew = task->failReason();
- if(failReasonNew == "Invalid token.")
+ if(failReasonNew == "Invalid token." || failReasonNew == "Invalid Signature")
{
- account->invalidateClientToken();
+ // account->invalidateClientToken();
failReason = needLoginAgain;
}
else failReason = failReasonNew;
@@ -117,72 +130,82 @@ void LaunchController::login()
}
switch (m_session->status)
{
- case AuthSession::Undetermined:
- {
- qCritical() << "Received undetermined session status during login. Bye.";
- tryagain = false;
- emitFailed(tr("Received undetermined session status during login."));
- break;
- }
- case AuthSession::RequiresPassword:
- {
- EditAccountDialog passDialog(failReason, m_parentWidget, EditAccountDialog::PasswordField);
- auto username = m_session->username;
- auto chopN = [](QString toChop, int N) -> QString
- {
- if(toChop.size() > N)
+ case AuthSession::Undetermined: {
+ qCritical() << "Received undetermined session status during login. Bye.";
+ tryagain = false;
+ emitFailed(tr("Received undetermined session status during login."));
+ return;
+ }
+ case AuthSession::RequiresPassword: {
+ // FIXME: this needs to understand MSA
+ EditAccountDialog passDialog(failReason, m_parentWidget, EditAccountDialog::PasswordField);
+ auto username = m_session->username;
+ auto chopN = [](QString toChop, int N) -> QString
{
- auto left = toChop.left(N);
- left += QString("\u25CF").repeated(toChop.size() - N);
- return left;
- }
- return toChop;
- };
+ if(toChop.size() > N)
+ {
+ auto left = toChop.left(N);
+ left += QString("\u25CF").repeated(toChop.size() - N);
+ return left;
+ }
+ return toChop;
+ };
- if(username.contains('@'))
- {
- auto parts = username.split('@');
- auto mailbox = chopN(parts[0],3);
- QString domain = chopN(parts[1], 3);
- username = mailbox + '@' + domain;
- }
- passDialog.setUsername(username);
- if (passDialog.exec() == QDialog::Accepted)
- {
- password = passDialog.password();
+ if(username.contains('@'))
+ {
+ auto parts = username.split('@');
+ auto mailbox = chopN(parts[0],3);
+ QString domain = chopN(parts[1], 3);
+ username = mailbox + '@' + domain;
+ }
+ passDialog.setUsername(username);
+ if (passDialog.exec() == QDialog::Accepted)
+ {
+ password = passDialog.password();
+ }
+ else
+ {
+ tryagain = false;
+ emitFailed(tr("Received undetermined session status during login."));
+ }
+ break;
}
- else
- {
+ case AuthSession::RequiresOAuth: {
+ // FIXME: add UI for expired / broken MS accounts
tryagain = false;
+ emitFailed(tr("Microsoft account has expired and needs to be logged into again."));
+ return;
}
- break;
- }
- case AuthSession::PlayableOffline:
- {
- // we ask the user for a player name
- bool ok = false;
- QString usedname = m_session->player_name;
- QString name = QInputDialog::getText(m_parentWidget, tr("Player name"),
- tr("Choose your offline mode player name."),
- QLineEdit::Normal, m_session->player_name, &ok);
- if (!ok)
- {
- tryagain = false;
- break;
+ case AuthSession::PlayableOffline: {
+ // we ask the user for a player name
+ bool ok = false;
+ QString usedname = m_session->player_name;
+ QString name = QInputDialog::getText(
+ m_parentWidget,
+ tr("Player name"),
+ tr("Choose your offline mode player name."),
+ QLineEdit::Normal,
+ m_session->player_name,
+ &ok
+ );
+ if (!ok)
+ {
+ tryagain = false;
+ break;
+ }
+ if (name.length())
+ {
+ usedname = name;
+ }
+ m_session->MakeOffline(usedname);
+ // offline flavored game from here :3
}
- if (name.length())
+ case AuthSession::PlayableOnline:
{
- usedname = name;
+ launchInstance();
+ tryagain = false;
+ return;
}
- m_session->MakeOffline(usedname);
- // offline flavored game from here :3
- }
- case AuthSession::PlayableOnline:
- {
- launchInstance();
- tryagain = false;
- return;
- }
}
}
emitFailed(tr("Failed to launch."));
diff --git a/launcher/MainWindow.cpp b/launcher/MainWindow.cpp
index 9225193e..182b22e9 100644
--- a/launcher/MainWindow.cpp
+++ b/launcher/MainWindow.cpp
@@ -54,7 +54,7 @@
#include <java/JavaUtils.h>
#include <java/JavaInstallList.h>
#include <launch/LaunchTask.h>
-#include <minecraft/auth/MojangAccountList.h>
+#include <minecraft/auth/AccountList.h>
#include <SkinUtils.h>
#include <BuildConfig.h>
#include <net/NetJob.h>
@@ -90,6 +90,20 @@
#include "KonamiCode.h"
#include <InstanceCopyTask.h>
+namespace {
+QString profileInUseFilter(const QString & profile, bool used)
+{
+ if(used)
+ {
+ return QObject::tr("%1 (in use)").arg(profile);
+ }
+ else
+ {
+ return profile;
+ }
+}
+}
+
// WHY: to hold the pre-translation strings together with the T pointer, so it can be retranslated without a lot of ugly code
template <typename T>
class Translated
@@ -753,49 +767,27 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
// Update the menu when the active account changes.
// Shouldn't have to use lambdas here like this, but if I don't, the compiler throws a fit.
// Template hell sucks...
- connect(MMC->accounts().get(), &MojangAccountList::activeAccountChanged, [this]
- {
- activeAccountChanged();
- });
- connect(MMC->accounts().get(), &MojangAccountList::listChanged, [this]
- {
- repopulateAccountsMenu();
- });
+ connect(
+ MMC->accounts().get(),
+ &AccountList::activeAccountChanged,
+ [this] {
+ activeAccountChanged();
+ }
+ );
+ connect(
+ MMC->accounts().get(),
+ &AccountList::listChanged,
+ [this]
+ {
+ repopulateAccountsMenu();
+ }
+ );
// Show initial account
activeAccountChanged();
- auto accounts = MMC->accounts();
-
- QList<Net::Download::Ptr> skin_dls;
- for (int i = 0; i < accounts->count(); i++)
- {
- auto account = accounts->at(i);
- if (!account)
- {
- qWarning() << "Null account at index" << i;
- continue;
- }
- for (auto profile : account->profiles())
- {
- auto meta = Env::getInstance().metacache()->resolveEntry("skins", profile.id + ".png");
- auto action = Net::Download::makeCached(QUrl(BuildConfig.SKINS_BASE + profile.id + ".png"), meta);
- skin_dls.append(action);
- meta->setStale(true);
- }
- }
- if (!skin_dls.isEmpty())
- {
- auto job = new NetJob("Startup player skins download");
- connect(job, &NetJob::succeeded, this, &MainWindow::skinJobFinished);
- connect(job, &NetJob::failed, this, &MainWindow::skinJobFinished);
- for (auto action : skin_dls)
- {
- job->addNetAction(action);
- }
- skin_download_job.reset(job);
- job->start();
- }
+ // TODO: refresh accounts here?
+ // auto accounts = MMC->accounts();
// load the news
{
@@ -844,7 +836,15 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
void MainWindow::retranslateUi()
{
- accountMenuButton->setText(tr("Profiles"));
+ std::shared_ptr<AccountList> accounts = MMC->accounts();
+ MinecraftAccountPtr active_account = accounts->activeAccount();
+ if(active_account) {
+ auto profileLabel = profileInUseFilter(active_account->profileName(), active_account->isInUse());
+ accountMenuButton->setText(profileLabel);
+ }
+ else {
+ accountMenuButton->setText(tr("Profiles"));
+ }
if (m_selectedInstance) {
m_statusLeft->setText(m_selectedInstance->getStatusbarDescription());
@@ -872,12 +872,6 @@ void MainWindow::konamiTriggered()
qDebug() << "Super Secret Mode ACTIVATED!";
}
-void MainWindow::skinJobFinished()
-{
- activeAccountChanged();
- skin_download_job.reset();
-}
-
void MainWindow::showInstanceContextMenu(const QPoint &pos)
{
QList<QAction *> actions;
@@ -1018,34 +1012,21 @@ void MainWindow::updateToolsMenu()
ui->actionLaunchInstanceOffline->setMenu(launchOfflineMenu);
}
-QString profileInUseFilter(const QString & profile, bool used)
-{
- if(used)
- {
- return profile + QObject::tr(" (in use)");
- }
- else
- {
- return profile;
- }
-}