diff options
Diffstat (limited to 'launcher/minecraft/auth/AccountData.cpp')
| -rw-r--r-- | launcher/minecraft/auth/AccountData.cpp | 157 |
1 files changed, 14 insertions, 143 deletions
diff --git a/launcher/minecraft/auth/AccountData.cpp b/launcher/minecraft/auth/AccountData.cpp index 7526c9517c..5470e1e7fe 100644 --- a/launcher/minecraft/auth/AccountData.cpp +++ b/launcher/minecraft/auth/AccountData.cpp @@ -4,6 +4,7 @@ #include <QJsonArray> #include <QDebug> #include <QUuid> +#include <QRegularExpression> namespace { void tokenToJSONV3(QJsonObject &parent, Katabasis::Token t, const char * tokenName) { @@ -238,71 +239,6 @@ bool entitlementFromJSONV3(const QJsonObject &parent, MinecraftEntitlement & out } -bool AccountData::resumeStateFromV2(QJsonObject data) { - // The JSON object must at least have a username for it to be valid. - if (!data.value("username").isString()) - { - qCritical() << "Can't load Mojang account info from JSON object. Username field is missing or of the wrong type."; - return false; - } - - QString userName = data.value("username").toString(""); - QString clientToken = data.value("clientToken").toString(""); - QString accessToken = data.value("accessToken").toString(""); - - QJsonArray profileArray = data.value("profiles").toArray(); - if (profileArray.size() < 1) - { - qCritical() << "Can't load Mojang account with username \"" << userName << "\". No profiles found."; - return false; - } - - struct AccountProfile - { - QString id; - QString name; - bool legacy; - }; - - QList<AccountProfile> profiles; - int currentProfileIndex = 0; - int index = -1; - QString currentProfile = data.value("activeProfile").toString(""); - for (QJsonValue profileVal : profileArray) - { - index++; - QJsonObject profileObject = profileVal.toObject(); - QString id = profileObject.value("id").toString(""); - QString name = profileObject.value("name").toString(""); - bool legacy = profileObject.value("legacy").toBool(false); - if (id.isEmpty() || name.isEmpty()) - { - qWarning() << "Unable to load a profile" << name << "because it was missing an ID or a name."; - continue; - } - if(id == currentProfile) { - currentProfileIndex = index; - } - profiles.append({id, name, legacy}); - } - auto & profile = profiles[currentProfileIndex]; - - type = AccountType::Mojang; - legacy = profile.legacy; - - minecraftProfile.id = profile.id; - minecraftProfile.name = profile.name; - minecraftProfile.validity = Katabasis::Validity::Assumed; - - yggdrasilToken.token = accessToken; - yggdrasilToken.extra["clientToken"] = clientToken; - yggdrasilToken.extra["userName"] = userName; - yggdrasilToken.validity = Katabasis::Validity::Assumed; - - validity_ = minecraftProfile.validity; - return true; -} - bool AccountData::resumeStateFromV3(QJsonObject data) { auto typeV = data.value("type"); if(!typeV.isString()) { @@ -312,24 +248,15 @@ bool AccountData::resumeStateFromV3(QJsonObject data) { auto typeS = typeV.toString(); if(typeS == "MSA") { type = AccountType::MSA; - } else if (typeS == "Mojang") { - type = AccountType::Mojang; } else { - qWarning() << "Failed to parse account data: type is not recognized."; + qWarning() << "Failed to parse account data: type is not recognized (only MSA is supported)."; return false; } - if(type == AccountType::Mojang) { - legacy = data.value("legacy").toBool(false); - canMigrateToMSA = data.value("canMigrateToMSA").toBool(false); - } - - if(type == AccountType::MSA) { - msaToken = tokenFromJSONV3(data, "msa"); - userToken = tokenFromJSONV3(data, "utoken"); - xboxApiToken = tokenFromJSONV3(data, "xrp-main"); - mojangservicesToken = tokenFromJSONV3(data, "xrp-mc"); - } + msaToken = tokenFromJSONV3(data, "msa"); + userToken = tokenFromJSONV3(data, "utoken"); + xboxApiToken = tokenFromJSONV3(data, "xrp-main"); + mojangservicesToken = tokenFromJSONV3(data, "xrp-mc"); yggdrasilToken = tokenFromJSONV3(data, "ygg"); minecraftProfile = profileFromJSONV3(data, "profile"); @@ -347,22 +274,11 @@ bool AccountData::resumeStateFromV3(QJsonObject data) { QJsonObject AccountData::saveState() const { QJsonObject output; - if(type == AccountType::Mojang) { - output["type"] = "Mojang"; - if(legacy) { - output["legacy"] = true; - } - if(canMigrateToMSA) { - output["canMigrateToMSA"] = true; - } - } - else if (type == AccountType::MSA) { - output["type"] = "MSA"; - tokenToJSONV3(output, msaToken, "msa"); - tokenToJSONV3(output, userToken, "utoken"); - tokenToJSONV3(output, xboxApiToken, "xrp-main"); - tokenToJSONV3(output, mojangservicesToken, "xrp-mc"); - } + output["type"] = "MSA"; + tokenToJSONV3(output, msaToken, "msa"); + tokenToJSONV3(output, userToken, "utoken"); + tokenToJSONV3(output, xboxApiToken, "xrp-main"); + tokenToJSONV3(output, mojangservicesToken, "xrp-mc"); tokenToJSONV3(output, yggdrasilToken, "ygg"); profileToJSONV3(output, minecraftProfile, "profile"); @@ -370,45 +286,10 @@ QJsonObject AccountData::saveState() const { return output; } -QString AccountData::userName() const { - if(type != AccountType::Mojang) { - return QString(); - } - return yggdrasilToken.extra["userName"].toString(); -} - QString AccountData::accessToken() const { return yggdrasilToken.token; } -QString AccountData::clientToken() const { - if(type != AccountType::Mojang) { - return QString(); - } - return yggdrasilToken.extra["clientToken"].toString(); -} - -void AccountData::setClientToken(QString clientToken) { - if(type != AccountType::Mojang) { - return; - } - yggdrasilToken.extra["clientToken"] = clientToken; -} - -void AccountData::generateClientTokenIfMissing() { - if(yggdrasilToken.extra.contains("clientToken")) { - return; - } - invalidateClientToken(); -} - -void AccountData::invalidateClientToken() { - if(type != AccountType::Mojang) { - return; - } - yggdrasilToken.extra["clientToken"] = QUuid::createUuid().toString().remove(QRegExp("[{-}]")); -} - QString AccountData::profileId() const { return minecraftProfile.id; } @@ -423,20 +304,10 @@ QString AccountData::profileName() const { } QString AccountData::accountDisplayString() const { - switch(type) { - case AccountType::Mojang: { - return userName(); - } - case AccountType::MSA: { - if(xboxApiToken.extra.contains("gtg")) { - return xboxApiToken.extra["gtg"].toString(); - } - return "Xbox profile missing"; - } - default: { - return "Invalid Account"; - } + if(xboxApiToken.extra.contains("gtg")) { + return xboxApiToken.extra["gtg"].toString(); } + return "Xbox profile missing"; } QString AccountData::lastError() const { |
