Skip to content

Commit

Permalink
UltimMC: Use proper Ely.by profile
Browse files Browse the repository at this point in the history
  • Loading branch information
Neptune650 committed Mar 12, 2024
1 parent 60aead3 commit 51fff1f
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 3 deletions.
2 changes: 2 additions & 0 deletions launcher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ set(MINECRAFT_SOURCES
minecraft/auth/steps/MigrationEligibilityStep.h
minecraft/auth/steps/MinecraftProfileStep.cpp
minecraft/auth/steps/MinecraftProfileStep.h
minecraft/auth/steps/ElybyProfileStep.cpp
minecraft/auth/steps/ElybyProfileStep.h
minecraft/auth/steps/MSAStep.cpp
minecraft/auth/steps/MSAStep.h
minecraft/auth/steps/LocalStep.cpp
Expand Down
6 changes: 3 additions & 3 deletions launcher/minecraft/auth/flows/Elyby.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include "Elyby.h"

#include "minecraft/auth/steps/YggdrasilStep.h"
#include "minecraft/auth/steps/GetSkinStep.h"
#include "minecraft/auth/steps/ElybyProfileStep.h"

ElybyRefresh::ElybyRefresh(
AccountData *data,
QObject *parent
) : AuthFlow(data, parent) {
m_steps.append(new YggdrasilStep(m_data, QString()));
m_steps.append(new GetSkinStep(m_data));
m_steps.append(new ElybyProfileStep(m_data));
}

ElybyLogin::ElybyLogin(
Expand All @@ -17,5 +17,5 @@ ElybyLogin::ElybyLogin(
QObject *parent
): AuthFlow(data, parent), m_password(password) {
m_steps.append(new YggdrasilStep(m_data, m_password));
m_steps.append(new GetSkinStep(m_data));
m_steps.append(new ElybyProfileStep(m_data));
}
90 changes: 90 additions & 0 deletions launcher/minecraft/auth/steps/ElybyProfileStep.cpp
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.")
);
}
22 changes: 22 additions & 0 deletions launcher/minecraft/auth/steps/ElybyProfileStep.h
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>);
};

0 comments on commit 51fff1f

Please sign in to comment.