diff options
| author | Petr Mrázek <peterix@gmail.com> | 2021-08-29 22:55:33 +0200 |
|---|---|---|
| committer | Petr Mrázek <peterix@gmail.com> | 2021-08-29 22:55:33 +0200 |
| commit | 317101430148e3bbc52995aa92d668b8473026d9 (patch) | |
| tree | 0dda85a8fd0b60c7eeba3950842bd1dd876155e2 /launcher/minecraft/auth/flows | |
| parent | 7239502675fb68b1a2050c68f483e5d5371114e1 (diff) | |
| download | PrismLauncher-317101430148e3bbc52995aa92d668b8473026d9.tar.gz PrismLauncher-317101430148e3bbc52995aa92d668b8473026d9.tar.bz2 PrismLauncher-317101430148e3bbc52995aa92d668b8473026d9.zip | |
GH-3392 checking for migration status and refresh button in accounts list
Diffstat (limited to 'launcher/minecraft/auth/flows')
| -rw-r--r-- | launcher/minecraft/auth/flows/AuthContext.cpp | 68 | ||||
| -rw-r--r-- | launcher/minecraft/auth/flows/AuthContext.h | 4 |
2 files changed, 72 insertions, 0 deletions
diff --git a/launcher/minecraft/auth/flows/AuthContext.cpp b/launcher/minecraft/auth/flows/AuthContext.cpp index 9ae99453..5d7d858d 100644 --- a/launcher/minecraft/auth/flows/AuthContext.cpp +++ b/launcher/minecraft/auth/flows/AuthContext.cpp @@ -192,6 +192,15 @@ bool getNumber(QJsonValue value, double & out) { return true; } + +bool getBool(QJsonValue value, bool & out) { + if(!value.isBool()) { + return false; + } + out = value.toBool(); + return true; +} + /* { "IssueInstant":"2020-12-07T19:52:08.4463796Z", @@ -693,6 +702,63 @@ void AuthContext::onMinecraftProfileDone(int, QNetworkReply::NetworkError error, changeState(STATE_FAILED_HARD, tr("Minecraft Java profile response could not be parsed")); return; } + + if(m_data->type == AccountType::Mojang) { + doMigrationEligibilityCheck(); + } + else { + doGetSkin(); + } +} + +void AuthContext::doMigrationEligibilityCheck() { + setStage(AuthStage::MigrationEligibility); + changeState(STATE_WORKING, tr("Starting check for migration eligibility")); + + auto url = QUrl("https://api.minecraftservices.com/rollout/v1/msamigration"); + QNetworkRequest request = QNetworkRequest(url); + request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); + request.setRawHeader("Authorization", QString("Bearer %1").arg(m_data->yggdrasilToken.token).toUtf8()); + + Requestor *requestor = new Requestor(mgr, m_oauth2, this); + connect(requestor, &Requestor::finished, this, &AuthContext::onMigrationEligibilityCheckDone); + requestor->get(request); +} + +bool parseRolloutResponse(QByteArray & data, bool& result) { + qDebug() << "Parsing Rollout response..."; +#ifndef NDEBUG + qDebug() << data; +#endif + + QJsonParseError jsonError; + QJsonDocument doc = QJsonDocument::fromJson(data, &jsonError); + if(jsonError.error) { + qWarning() << "Failed to parse response from https://api.minecraftservices.com/rollout/v1/msamigration as JSON: " << jsonError.errorString(); + return false; + } + + auto obj = doc.object(); + QString feature; + if(!getString(obj.value("feature"), feature)) { + qWarning() << "Rollout feature is not a string"; + return false; + } + if(feature != "msamigration") { + qWarning() << "Rollout feature is not what we expected (msamigration), but is instead \"" << feature << "\""; + return false; + } + if(!getBool(obj.value("rollout"), result)) { + qWarning() << "Rollout feature is not a string"; + return false; + } + return true; +} + +void AuthContext::onMigrationEligibilityCheckDone(int, QNetworkReply::NetworkError error, QByteArray data, QList<QNetworkReply::RawHeaderPair> headers) { + if (error == QNetworkReply::NoError) { + parseRolloutResponse(data, m_data->canMigrateToMSA); + } doGetSkin(); } @@ -742,6 +808,8 @@ QString AuthContext::getStateMessage() const { return tr("Logging in with XBox and Mojang services"); case AuthStage::MinecraftProfile: return tr("Getting Minecraft profile"); + case AuthStage::MigrationEligibility: + return tr("Checking for migration eligibility"); case AuthStage::Skin: return tr("Getting Minecraft skin"); case AuthStage::Complete: diff --git a/launcher/minecraft/auth/flows/AuthContext.h b/launcher/minecraft/auth/flows/AuthContext.h index 1d9f8f72..7bf69623 100644 --- a/launcher/minecraft/auth/flows/AuthContext.h +++ b/launcher/minecraft/auth/flows/AuthContext.h @@ -63,6 +63,9 @@ protected: void doMinecraftProfile(); Q_SLOT void onMinecraftProfileDone(int, QNetworkReply::NetworkError, QByteArray, QList<QNetworkReply::RawHeaderPair>); + void doMigrationEligibilityCheck(); + Q_SLOT void onMigrationEligibilityCheckDone(int, QNetworkReply::NetworkError, QByteArray, QList<QNetworkReply::RawHeaderPair>); + void doGetSkin(); Q_SLOT void onSkinDone(int, QNetworkReply::NetworkError, QByteArray, QList<QNetworkReply::RawHeaderPair>); @@ -86,6 +89,7 @@ protected: UserAuth, XboxAuth, MinecraftProfile, + MigrationEligibility, Skin, Complete } m_stage = AuthStage::Initial; |
