aboutsummaryrefslogtreecommitdiff
path: root/launcher/minecraft/auth/steps/MinecraftProfileStepMojang.cpp
diff options
context:
space:
mode:
authorSefa Eyeoglu <contact@scrumplex.net>2022-05-08 21:43:06 +0200
committerGitHub <noreply@github.com>2022-05-08 21:43:06 +0200
commit1e34de98aba8bc3fd74443f556506c4779c2f8fd (patch)
tree2d113be4a1b888470e11a5e72576522d85e0b865 /launcher/minecraft/auth/steps/MinecraftProfileStepMojang.cpp
parent7b46f50cf1c5709406298424a404a66c948c7a0c (diff)
parentcab40026f2a1253539d0d8e363f1aea32b054bd1 (diff)
downloadPrismLauncher-1e34de98aba8bc3fd74443f556506c4779c2f8fd.tar.gz
PrismLauncher-1e34de98aba8bc3fd74443f556506c4779c2f8fd.tar.bz2
PrismLauncher-1e34de98aba8bc3fd74443f556506c4779c2f8fd.zip
Merge pull request #534 from DioEgizio/stable
Diffstat (limited to 'launcher/minecraft/auth/steps/MinecraftProfileStepMojang.cpp')
-rw-r--r--launcher/minecraft/auth/steps/MinecraftProfileStepMojang.cpp94
1 files changed, 94 insertions, 0 deletions
diff --git a/launcher/minecraft/auth/steps/MinecraftProfileStepMojang.cpp b/launcher/minecraft/auth/steps/MinecraftProfileStepMojang.cpp
new file mode 100644
index 00000000..d3035272
--- /dev/null
+++ b/launcher/minecraft/auth/steps/MinecraftProfileStepMojang.cpp
@@ -0,0 +1,94 @@
+#include "MinecraftProfileStepMojang.h"
+
+#include <QNetworkRequest>
+
+#include "minecraft/auth/AuthRequest.h"
+#include "minecraft/auth/Parsers.h"
+
+MinecraftProfileStepMojang::MinecraftProfileStepMojang(AccountData* data) : AuthStep(data) {
+
+}
+
+MinecraftProfileStepMojang::~MinecraftProfileStepMojang() noexcept = default;
+
+QString MinecraftProfileStepMojang::describe() {
+ return tr("Fetching the Minecraft profile.");
+}
+
+
+void MinecraftProfileStepMojang::perform() {
+ if (m_data->minecraftProfile.id.isEmpty()) {
+ emit finished(AccountTaskState::STATE_FAILED_HARD, tr("A UUID is required to get the profile."));
+ return;
+ }
+
+ // use session server instead of profile due to profile endpoint being locked for locked Mojang accounts
+ QUrl url = QUrl("https://sessionserver.mojang.com/session/minecraft/profile/" + m_data->minecraftProfile.id);
+ QNetworkRequest req = QNetworkRequest(url);
+ AuthRequest *request = new AuthRequest(this);
+ connect(request, &AuthRequest::finished, this, &MinecraftProfileStepMojang::onRequestDone);
+ request->get(req);
+}
+
+void MinecraftProfileStepMojang::rehydrate() {
+ // NOOP, for now. We only save bools and there's nothing to check.
+}
+
+void MinecraftProfileStepMojang::onRequestDone(
+ QNetworkReply::NetworkError error,
+ QByteArray data,
+ QList<QNetworkReply::RawHeaderPair> headers
+) {
+ auto requestor = qobject_cast<AuthRequest *>(QObject::sender());
+ requestor->deleteLater();
+
+#ifndef NDEBUG
+ qDebug() << data;
+#endif
+ if (error == QNetworkReply::ContentNotFoundError) {
+ // NOTE: Succeed even if we do not have a profile. This is a valid account state.
+ if(m_data->type == AccountType::Mojang) {
+ m_data->minecraftEntitlement.canPlayMinecraft = false;
+ m_data->minecraftEntitlement.ownsMinecraft = false;
+ }
+ m_data->minecraftProfile = MinecraftProfile();
+ emit finished(
+ AccountTaskState::STATE_SUCCEEDED,
+ tr("Account has no Minecraft profile.")
+ );
+ return;
+ }
+ if (error != QNetworkReply::NoError) {
+ qWarning() << "Error getting profile:";
+ qWarning() << " HTTP Status: " << requestor->httpStatus_;
+ qWarning() << " Internal error no.: " << error;
+ qWarning() << " Error string: " << requestor->errorString_;
+
+ qWarning() << " Response:";
+ qWarning() << QString::fromUtf8(data);
+
+ emit finished(
+ AccountTaskState::STATE_FAILED_SOFT,
+ tr("Minecraft Java profile acquisition failed.")
+ );
+ return;
+ }
+ if(!Parsers::parseMinecraftProfileMojang(data, m_data->minecraftProfile)) {
+ m_data->minecraftProfile = MinecraftProfile();
+ emit finished(
+ AccountTaskState::STATE_FAILED_SOFT,
+ tr("Minecraft Java profile response could not be parsed")
+ );
+ return;
+ }
+
+ if(m_data->type == AccountType::Mojang) {
+ auto validProfile = m_data->minecraftProfile.validity == Katabasis::Validity::Certain;
+ m_data->minecraftEntitlement.canPlayMinecraft = validProfile;
+ m_data->minecraftEntitlement.ownsMinecraft = validProfile;
+ }
+ emit finished(
+ AccountTaskState::STATE_WORKING,
+ tr("Minecraft Java profile acquisition succeeded.")
+ );
+}