forked from MultiMC/Launcher
-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60aead3
commit 51fff1f
Showing
4 changed files
with
117 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#include "ElybyProfileStep.h" | ||
|
||
#include <QNetworkRequest> | ||
|
||
#include "minecraft/auth/AuthRequest.h" | ||
#include "minecraft/auth/Parsers.h" | ||
|
||
ElybyProfileStep::ElybyProfileStep(AccountData* data) : AuthStep(data) { | ||
|
||
} | ||
|
||
ElybyProfileStep::~ElybyProfileStep() noexcept = default; | ||
|
||
QString ElybyProfileStep::describe() { | ||
return tr("Fetching the Ely.by profile."); | ||
} | ||
|
||
|
||
void ElybyProfileStep::perform() { | ||
auto url = QUrl(QString("https://authserver.ely.by/api/users/profiles/minecraft/%1").arg(m_data->userName()).toUtf8()); | ||
QNetworkRequest request = QNetworkRequest(url); | ||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); | ||
|
||
AuthRequest *requestor = new AuthRequest(this); | ||
connect(requestor, &AuthRequest::finished, this, &ElybyProfileStep::onRequestDone); | ||
requestor->get(request); | ||
} | ||
|
||
void ElybyProfileStep::rehydrate() { | ||
// NOOP, for now. We only save bools and there's nothing to check. | ||
} | ||
|
||
void ElybyProfileStep::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::parseMinecraftProfile(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.") | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
#include <QObject> | ||
|
||
#include "QObjectPtr.h" | ||
#include "minecraft/auth/AuthStep.h" | ||
|
||
|
||
class ElybyProfileStep : public AuthStep { | ||
Q_OBJECT | ||
|
||
public: | ||
explicit ElybyProfileStep(AccountData *data); | ||
virtual ~ElybyProfileStep() noexcept; | ||
|
||
void perform() override; | ||
void rehydrate() override; | ||
|
||
QString describe() override; | ||
|
||
private slots: | ||
void onRequestDone(QNetworkReply::NetworkError, QByteArray, QList<QNetworkReply::RawHeaderPair>); | ||
}; |