Skip to content

Commit

Permalink
UltimMC: Fix ely.by auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Neptune650 committed Mar 8, 2024
1 parent 3993d12 commit 1498132
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 38 deletions.
2 changes: 2 additions & 0 deletions launcher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ set(MINECRAFT_SOURCES
minecraft/auth/flows/MSA.h
minecraft/auth/flows/Local.cpp
minecraft/auth/flows/Local.h
minecraft/auth/flows/Elyby.cpp
minecraft/auth/flows/Elyby.h

minecraft/auth/steps/EntitlementsStep.cpp
minecraft/auth/steps/EntitlementsStep.h
Expand Down
8 changes: 4 additions & 4 deletions launcher/minecraft/auth/AccountData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ QJsonObject AccountData::saveState() const {
}

QString AccountData::userName() const {
if(type != AccountType::Mojang) {
if(type != AccountType::Mojang && type != AccountType::Elyby) {
return QString();
}
return yggdrasilToken.extra["userName"].toString();
Expand All @@ -399,14 +399,14 @@ QString AccountData::accessToken() const {
}

QString AccountData::clientToken() const {
if(type != AccountType::Mojang) {
if(type != AccountType::Mojang && type != AccountType::Elyby) {
return QString();
}
return yggdrasilToken.extra["clientToken"].toString();
}

void AccountData::setClientToken(QString clientToken) {
if(type != AccountType::Mojang) {
if(type != AccountType::Mojang && type != AccountType::Elyby) {
return;
}
yggdrasilToken.extra["clientToken"] = clientToken;
Expand All @@ -420,7 +420,7 @@ void AccountData::generateClientTokenIfMissing() {
}

void AccountData::invalidateClientToken() {
if(type != AccountType::Mojang) {
if(type != AccountType::Mojang && type != AccountType::Elyby) {
return;
}
yggdrasilToken.extra["clientToken"] = QUuid::createUuid().toString().remove(QRegExp("[{-}]"));
Expand Down
19 changes: 15 additions & 4 deletions launcher/minecraft/auth/MinecraftAccount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "flows/MSA.h"
#include "flows/Mojang.h"
#include "flows/Local.h"
#include "flows/Elyby.h"

MinecraftAccount::MinecraftAccount(QObject* parent) : QObject(parent) {
data.internalId = QUuid::createUuid().toString().remove(QRegExp("[{}-]"));
Expand Down Expand Up @@ -95,7 +96,6 @@ MinecraftAccountPtr MinecraftAccount::createLocal(const QString &username)
account->data.yggdrasilToken.extra["userName"] = username;
account->data.yggdrasilToken.extra["clientToken"] = QUuid::createUuid().toString().remove(QRegExp("[{}-]"));
account->data.minecraftProfile.id = uuidFromUsername(username).toString().remove(QRegExp("[{}-]"));
account->data.minecraftProfile.id = account->data.internalId;
account->data.minecraftProfile.name = username;
account->data.minecraftProfile.validity = Katabasis::Validity::Certain;
account->data.minecraftEntitlement.ownsMinecraft = true;
Expand All @@ -109,13 +109,11 @@ MinecraftAccountPtr MinecraftAccount::createElyby(const QString &username)
account->data.type = AccountType::Elyby;
account->data.yggdrasilToken.extra["userName"] = username;
account->data.yggdrasilToken.extra["clientToken"] = QUuid::createUuid().toString().remove(QRegExp("[{}-]"));
account->data.minecraftProfile.id = account->data.internalId;
account->data.minecraftProfile.id = uuidFromUsername(username).toString().remove(QRegExp("[{}-]"));
account->data.minecraftProfile.name = username;
account->data.minecraftProfile.validity = Katabasis::Validity::Certain;
account->data.validity_ = Katabasis::Validity::Certain;
account->data.minecraftEntitlement.ownsMinecraft = true;
account->data.minecraftEntitlement.canPlayMinecraft = true;
account->data.minecraftEntitlement.validity = Katabasis::Validity::Certain;
return account;
}

Expand Down Expand Up @@ -180,6 +178,16 @@ shared_qobject_ptr<AccountTask> MinecraftAccount::loginLocal() {
return m_currentTask;
}

shared_qobject_ptr<AccountTask> MinecraftAccount::loginElyby(QString password) {
Q_ASSERT(m_currentTask.get() == nullptr);

m_currentTask.reset(new ElybyLogin(&data, password));
connect(m_currentTask.get(), SIGNAL(succeeded()), SLOT(authSucceeded()));
connect(m_currentTask.get(), SIGNAL(failed(QString)), SLOT(authFailed(QString)));
emit activityChanged(true);
return m_currentTask;
}

shared_qobject_ptr<AccountTask> MinecraftAccount::refresh() {
if(m_currentTask) {
return m_currentTask;
Expand All @@ -194,6 +202,9 @@ shared_qobject_ptr<AccountTask> MinecraftAccount::refresh() {
else if (data.type == AccountType::Local) {
m_currentTask.reset(new LocalRefresh(&data));
}
else if (data.type == AccountType::Elyby) {
m_currentTask.reset(new ElybyRefresh(&data));
}

connect(m_currentTask.get(), SIGNAL(succeeded()), SLOT(authSucceeded()));
connect(m_currentTask.get(), SIGNAL(failed(QString)), SLOT(authFailed(QString)));
Expand Down
2 changes: 2 additions & 0 deletions launcher/minecraft/auth/MinecraftAccount.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ class MinecraftAccount :

shared_qobject_ptr<AccountTask> loginLocal();

shared_qobject_ptr<AccountTask> loginElyby(QString password);

shared_qobject_ptr<AccountTask> refresh();

shared_qobject_ptr<AccountTask> currentTask();
Expand Down
21 changes: 21 additions & 0 deletions launcher/minecraft/auth/flows/Elyby.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "Elyby.h"

#include "minecraft/auth/steps/YggdrasilStep.h"
#include "minecraft/auth/steps/GetSkinStep.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));
}

ElybyLogin::ElybyLogin(
AccountData *data,
QString password,
QObject *parent
): AuthFlow(data, parent), m_password(password) {
m_steps.append(new YggdrasilStep(m_data, m_password));
m_steps.append(new GetSkinStep(m_data));
}
26 changes: 26 additions & 0 deletions launcher/minecraft/auth/flows/Elyby.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once
#include "AuthFlow.h"

class ElybyRefresh : public AuthFlow
{
Q_OBJECT
public:
explicit ElybyRefresh(
AccountData *data,
QObject *parent = 0
);
};

class ElybyLogin : public AuthFlow
{
Q_OBJECT
public:
explicit ElybyLogin(
AccountData *data,
QString password,
QObject *parent = 0
);

private:
QString m_password;
};
23 changes: 3 additions & 20 deletions launcher/ui/dialogs/LoginDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,6 @@ LoginDialog::LoginDialog(QWidget *parent) : QDialog(parent), ui(new Ui::LoginDia
ui->progressBar->setVisible(false);
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);

for(auto provider: AuthProviders::getAll()) {
auto providerId = provider->id();
// Exclude Microsoft and Local accounts from here...
if (providerId != "MSA" && providerId != "local") {
QRadioButton *button = new QRadioButton(provider->displayName());
m_radioButtons[providerId] = button;
ui->radioLayout->addWidget(button);
}
}
m_radioButtons["elyby"]->setChecked(true);
adjustSize();

connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
}
Expand All @@ -54,16 +42,11 @@ void LoginDialog::accept()
setUserInputsEnabled(false);
ui->progressBar->setVisible(true);

m_account = MinecraftAccount::createFromUsername(ui->userTextBox->text());
for(auto providerId: m_radioButtons.keys()){
if(m_radioButtons[providerId]->isChecked()) {
m_account->setProvider(AuthProviders::lookup(providerId));
break;
}
}
m_account = MinecraftAccount::createElyby(ui->userTextBox->text());
m_account->setProvider(AuthProviders::lookup("elyby"));

// Setup the login task and start it
m_loginTask = m_account->login(ui->passTextBox->text());
m_loginTask = m_account->loginElyby(ui->passTextBox->text());
connect(m_loginTask.get(), &Task::failed, this, &LoginDialog::onTaskFailed);
connect(m_loginTask.get(), &Task::succeeded, this, &LoginDialog::onTaskSucceeded);
connect(m_loginTask.get(), &Task::status, this, &LoginDialog::onTaskStatus);
Expand Down
2 changes: 0 additions & 2 deletions launcher/ui/dialogs/LoginDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#pragma once

#include <QtWidgets/QDialog>
#include <QtWidgets/QRadioButton>
#include <QtCore/QEventLoop>

#include "minecraft/auth/MinecraftAccount.h"
Expand Down Expand Up @@ -56,6 +55,5 @@ protected
private:
Ui::LoginDialog *ui;
MinecraftAccountPtr m_account;
QMap<QString, QRadioButton*> m_radioButtons;
Task::Ptr m_loginTask;
};
3 changes: 0 additions & 3 deletions launcher/ui/dialogs/LoginDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="radioLayout"/>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
Expand Down
6 changes: 3 additions & 3 deletions launcher/ui/pages/global/AccountListPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ AccountListPage::AccountListPage(QWidget *parent)
ui->listView->setEmptyString(tr(
"Welcome!\n"
"If you're new here, you can click the \"Add Local\" button to add your local account.\n"
"Or click the \"Add Premium\" button to add your Ely.by or Mojang account."
"Or click the \"Add Ely.by\" button to add your Ely.by account."
));
ui->listView->setEmptyMode(VersionListView::String);
ui->listView->setContextMenuPolicy(Qt::CustomContextMenu);
Expand Down Expand Up @@ -161,7 +161,7 @@ void AccountListPage::on_actionAddMicrosoft_triggered()
}
MinecraftAccountPtr account = MSALoginDialog::newAccount(
this,
tr("Please enter your account email and password to add your account.")
tr("Please enter your Mojang account email and password to add your account.")
);

if (account)
Expand Down Expand Up @@ -227,7 +227,7 @@ void AccountListPage::updateButtonStates()
ui->actionSetDefault->setEnabled(accountIsReady);
ui->actionUploadSkin->setEnabled(accountIsReady && accountIsOnline);
ui->actionDeleteSkin->setEnabled(accountIsReady && accountIsOnline);
ui->actionRefresh->setEnabled(accountIsReady && accountIsOnline);
ui->actionRefresh->setEnabled(accountIsReady);

if(m_accounts->defaultAccount().get() == nullptr) {
ui->actionNoDefault->setEnabled(false);
Expand Down
4 changes: 2 additions & 2 deletions launcher/ui/pages/global/AccountListPage.ui
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
<bool>false</bool>
</attribute>
<addaction name="actionAddLocal"/>
<addaction name="actionAddMicrosoft"/>
<addaction name="actionAddMojang"/>
<addaction name="actionAddMicrosoft"/>
<addaction name="actionRefresh"/>
<addaction name="actionRemove"/>
<addaction name="actionSetDefault"/>
Expand All @@ -70,7 +70,7 @@
</action>
<action name="actionAddMojang">
<property name="text">
<string>Add Premium</string>
<string>Add Ely.by</string>
</property>
</action>
<action name="actionRemove">
Expand Down

0 comments on commit 1498132

Please sign in to comment.