Skip to content

Commit

Permalink
authlib-injector: Mark correct account as in use
Browse files Browse the repository at this point in the history
Fixes a bug where the wrong account could be marked as "in use" when the
game is launched if there are multiple accounts that share the same
profile ID. This can lead to the launcher trying to refresh an account
that's currently in use by the game, leading to "Invalid session" errors
in-game.

Signed-off-by: Evan Goode <[email protected]>
  • Loading branch information
evan-goode committed Nov 5, 2023
1 parent 712e2f0 commit 4957597
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 1 deletion.
11 changes: 11 additions & 0 deletions launcher/minecraft/auth/AccountList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ int AccountList::findAccountByProfileId(const QString& profileId) const
return -1;
}

MinecraftAccountPtr AccountList::getAccountByInternalId(const QString& accountId) const
{
for (int i = 0; i < count(); i++) {
MinecraftAccountPtr account = at(i);
if (account->internalId() == accountId) {
return account;
}
}
return nullptr;
}

MinecraftAccountPtr AccountList::getAccountByProfileName(const QString& profileName) const
{
for (int i = 0; i < count(); i++) {
Expand Down
1 change: 1 addition & 0 deletions launcher/minecraft/auth/AccountList.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class AccountList : public QAbstractListModel {
void addAccount(const MinecraftAccountPtr account);
void removeAccount(QModelIndex index);
int findAccountByProfileId(const QString& profileId) const;
MinecraftAccountPtr getAccountByInternalId(const QString& accountId) const;
MinecraftAccountPtr getAccountByProfileName(const QString& profileName) const;
QStringList profileNames() const;

Expand Down
2 changes: 2 additions & 0 deletions launcher/minecraft/auth/AuthSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ struct AuthSession {
bool uses_custom_api_servers = false;
QString authlib_injector_metadata;

// account ID
QString account_id;
// client token
QString client_token;
// account user name
Expand Down
2 changes: 2 additions & 0 deletions launcher/minecraft/auth/MinecraftAccount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ void MinecraftAccount::fillSession(AuthSessionPtr session)
}
}

// account ID
session->account_id = internalId();
// the user name. you have to have an user name
// FIXME: not with MSA
session->username = data.userName();
Expand Down
2 changes: 1 addition & 1 deletion launcher/minecraft/launch/ClaimAccount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ClaimAccount::ClaimAccount(LaunchTask* parent, AuthSessionPtr session) : LaunchS
{
if (session->status == AuthSession::Status::PlayableOnline && !session->demo) {
auto accounts = APPLICATION->accounts();
m_account = accounts->getAccountByProfileName(session->player_name);
m_account = accounts->getAccountByInternalId(session->account_id);
}
}

Expand Down

0 comments on commit 4957597

Please sign in to comment.