Add custom login support

This commit is contained in:
0xf8 2023-06-21 13:23:24 -04:00
parent 8e6c20dc99
commit ebbfaf8713
Signed by: 0xf8
GPG Key ID: 446580D758689584
7 changed files with 20 additions and 5 deletions

View File

@ -931,6 +931,8 @@ SET(LAUNCHER_SOURCES
ui/dialogs/ProfileSetupDialog.h
ui/dialogs/CopyInstanceDialog.cpp
ui/dialogs/CopyInstanceDialog.h
ui/dialogs/CustomLoginDialog.cpp
ui/dialogs/CustomLoginDialog.h
ui/dialogs/CustomMessageBox.cpp
ui/dialogs/CustomMessageBox.h
ui/dialogs/EditAccountDialog.cpp
@ -1094,6 +1096,7 @@ qt_wrap_ui(LAUNCHER_UI
ui/dialogs/MSALoginDialog.ui
ui/dialogs/OfflineLoginDialog.ui
ui/dialogs/ElybyLoginDialog.ui
ui/dialogs/CustomLoginDialog.ui
ui/dialogs/AboutDialog.ui
ui/dialogs/LoginDialog.ui
ui/dialogs/EditAccountDialog.ui

View File

@ -377,6 +377,13 @@ bool AccountData::resumeStateFromV3(QJsonObject data) {
mojangservicesToken = tokenFromJSONV3(data, "xrp-mc");
}
if(type == AccountType::Custom) {
auto urlV = data.value("url");
if (urlV.isString()) {
customUrl = urlV.toString();
}
}
yggdrasilToken = tokenFromJSONV3(data, "ygg");
minecraftProfile = profileFromJSONV3(data, "profile");
if(!entitlementFromJSONV3(data, minecraftEntitlement)) {
@ -418,6 +425,7 @@ QJsonObject AccountData::saveState() const {
}
else if (type == AccountType::Custom) {
output["type"] = "Custom";
output["url"] = customUrl;
}
tokenToJSONV3(output, yggdrasilToken, "ygg");

View File

@ -128,6 +128,7 @@ MinecraftAccountPtr MinecraftAccount::createCustom(const QString &username, cons
account->data.yggdrasilToken.extra["clientToken"] = QUuid::createUuid().toString().remove(QRegularExpression("[{}-]"));
account->data.minecraftEntitlement.ownsMinecraft = true;
account->data.minecraftEntitlement.canPlayMinecraft = true;
account->data.customUrl = url;
return account;
}

View File

@ -24,6 +24,8 @@ void CustomProfileStep::perform() {
// m_data->
qWarning() << "Url: " << m_data->customUrl;
QUrl url = QUrl(m_data->customUrl + "/session/profile/" + m_data->minecraftProfile.id);
QNetworkRequest req = QNetworkRequest(url);
AuthRequest *request = new AuthRequest(this);

View File

@ -23,11 +23,12 @@ void CustomStep::rehydrate() {
}
void CustomStep::perform() {
qWarning() << "url: " << m_url << " / " << m_data->customUrl;
if(m_password.size()) {
m_yggdrasil->login(m_password, m_url + "/auth/");
}
else {
m_yggdrasil->refresh(m_url + "/auth/");
m_yggdrasil->refresh(m_data->customUrl + "/auth/");
}
}
@ -50,7 +51,7 @@ void CustomStep::onAuthFailed() {
// NOTE: soft error in the first step means 'offline'
if(state == AccountTaskState::STATE_FAILED_SOFT) {
state = AccountTaskState::STATE_OFFLINE;
errorMessage = tr("Custom user authentication ended with a network error. Is MutliFactor Auth current?");
errorMessage = tr("Custom user authentication ended with a network error. Is MutliFactor Auth correct?");
}
emit finished(state, errorMessage);
}

View File

@ -42,7 +42,7 @@ void CustomLoginDialog::accept()
ui->progressBar->setVisible(true);
// Setup the login task and start it
m_account = MinecraftAccount::createCustom(ui->userTextBox->text());
m_account = MinecraftAccount::createCustom(ui->userTextBox->text(), ui->urlTextBox->text());
if (ui->mfaTextBox->text().length() > 0) {
m_loginTask = m_account->loginCustom(ui->passTextBox->text() + ':' + ui->mfaTextBox->text(), ui->urlTextBox->text());
}

View File

@ -231,7 +231,7 @@ void AccountListPage::on_actionAddCustom_triggered()
{
m_accounts->addAccount(account);
if (m_accounts->count() == 1) {
m_account->setDefaultAccount(account);
m_accounts->setDefaultAccount(account);
}
}
}
@ -280,7 +280,7 @@ void AccountListPage::updateButtonStates()
bool accountIsReady = false;
bool accountIsOnline = false;
bool accountIsElyby = false;
bool AccountIsCustom = false;
bool accountIsCustom = false;
if (hasSelection)
{
QModelIndex selected = selection.first();