Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions launcher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ set(NET_SOURCES
net/Download.h
net/FileSink.cpp
net/FileSink.h
net/Head.cpp
net/Head.h
net/HttpMetaCache.cpp
net/HttpMetaCache.h
net/MetaCacheSink.cpp
Expand Down
53 changes: 47 additions & 6 deletions launcher/minecraft/auth/custom/steps/CustomAuthStep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include "CustomAuthStep.h"

#include <QInputDialog>

#include "Application.h"
#include "Logging.h"
#include "net/NetUtils.h"
Expand Down Expand Up @@ -77,7 +79,11 @@ QString CustomAuthStep::requestTemplate()
{
"accessToken": "%1",
"clientToken": "%2",
"requestUser": false
"requestUser": false,
"selectedProfile": {
"id": "%3",
"name": "%4"
}
}
)XXX";
}
Expand All @@ -88,7 +94,8 @@ QString CustomAuthStep::fillRequest()
if (m_action == AuthFlow::Action::Login) {
return requestTemplate().arg(m_data->accountLogin, m_password, clientID());
} else {
return requestTemplate().arg(m_data->yggdrasilToken.token, m_data->clientID);
return requestTemplate().arg(m_data->yggdrasilToken.token, m_data->clientID, m_data->minecraftProfile.id,
m_data->minecraftProfile.name);
}
}

Expand All @@ -106,9 +113,43 @@ bool CustomAuthStep::parseResponse()

m_data->clientID = jsonResponse["clientToken"].toString();

auto profile = jsonResponse["selectedProfile"].toObject();
m_data->minecraftProfile.id = profile["id"].toString();
m_data->minecraftProfile.name = profile["name"].toString();
if (!jsonResponse["selectedProfile"].isNull()) {
auto profile = jsonResponse["selectedProfile"].toObject();
m_data->minecraftProfile.id = profile["id"].toString();
m_data->minecraftProfile.name = profile["name"].toString();
}

const QJsonArray profiles = jsonResponse["availableProfiles"].toArray();
if (profiles.size() > 1) {
const auto profileName = [](const auto& profile) {
auto obj = profile.toObject();
return obj["name"].toString();
};

QStringList list;
std::ranges::transform(profiles, std::back_inserter(list), profileName);

bool ok = false;
QString selectedProfileName =
QInputDialog::getItem(nullptr, tr("Select profile"), tr("Select profile for this account"), list, 0, false, &ok);

if (!ok) {
return false;
}

const auto it = std::ranges::find(profiles, selectedProfileName, profileName);
if (it != profiles.end()) {
auto profileObj = it->toObject();
m_data->minecraftProfile = MinecraftProfile{ .id = profileObj["id"].toString(), .name = profileObj["name"].toString() };
} else {
return false;
}
}

if (profiles.size() == 1 && m_data->minecraftProfile.id.isEmpty()) {
auto profileObj = profiles.first().toObject();
m_data->minecraftProfile = MinecraftProfile{ .id = profileObj["id"].toString(), .name = profileObj["name"].toString() };
}

return true;
}
Expand All @@ -121,4 +162,4 @@ void CustomAuthStep::onRequestDone()
return;
}
emit finished(AccountTaskState::STATE_WORKING, tr("Got authorization for %1 account").arg(authType()));
}
}
39 changes: 39 additions & 0 deletions launcher/net/Head.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Freesm Launcher - Minecraft Launcher
* Copyright (C) 2026 so5iso4ka <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <memory>

#include "ByteArraySink.h"

#include "Head.h"


Net::Head::Ptr Net::Head::makeHeaderPairs(QUrl url, Options options)
{
auto dl = makeShared<Head>();
dl->m_url = url;
dl->setObjectName(QString("HEAD:") + url.toString());
dl->m_options = options;
dl->m_sink = std::make_unique<ByteArraySink>(std::make_shared<QByteArray>());
return dl;
}

QNetworkReply* Net::Head::getReply(QNetworkRequest& request)
{
return m_network->head(request);
}
35 changes: 35 additions & 0 deletions launcher/net/Head.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Freesm Launcher - Minecraft Launcher
* Copyright (C) 2026 so5iso4ka <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#pragma once

#include "net/NetRequest.h"

namespace Net {
class Head : public NetRequest {
Q_OBJECT
public:
using Ptr = shared_qobject_ptr<Head>;
Head() { logCat = taskDownloadLogC; }

static Ptr makeHeaderPairs(QUrl url, Options options = Option::NoOptions);

protected:
QNetworkReply* getReply(QNetworkRequest& request) override;
};
} // namespace Net
4 changes: 1 addition & 3 deletions launcher/ui/dialogs/CustomLoginDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ void CustomLoginDialog::accept()
setUserInputsEnabled(false);
ui->progressBar->setVisible(true);

m_response = std::make_shared<QByteArray>();

m_requestTask = Net::Download::makeByteArray(url, m_response);
m_requestTask = Net::Head::makeHeaderPairs(url);
m_requestTask->setNetwork(APPLICATION->network());

connect(m_requestTask.get(), &Task::finished, this, &CustomLoginDialog::onUrlResolving);
Expand Down
5 changes: 2 additions & 3 deletions launcher/ui/dialogs/CustomLoginDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <QDialog>

#include "minecraft/auth/custom/CustomAccount.h"
#include "net/Download.h"
#include "net/Head.h"
#include "tasks/Task.h"

namespace Ui {
Expand Down Expand Up @@ -56,6 +56,5 @@ class CustomLoginDialog : public QDialog {
Ui::CustomLoginDialog* ui;
CustomAccountPtr m_account;
Task::Ptr m_loginTask;
Net::Download::Ptr m_requestTask;
std::shared_ptr<QByteArray> m_response;
Net::Head::Ptr m_requestTask;
};
Loading