mirror of
https://github.com/redstrate/Astra.git
synced 2025-04-20 19:57:45 +00:00
Use coroutines in square enix login process
This commit is contained in:
parent
6dc8041c71
commit
b068d34001
4 changed files with 116 additions and 104 deletions
|
@ -3,6 +3,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <qcorotask.h>
|
||||
|
||||
#include "patcher.h"
|
||||
|
||||
class SquareLauncher;
|
||||
|
@ -15,9 +17,9 @@ class SquareBoot : public QObject
|
|||
public:
|
||||
SquareBoot(LauncherCore &window, SquareLauncher &launcher, QObject *parent = nullptr);
|
||||
|
||||
Q_INVOKABLE void checkGateStatus(LoginInformation *info);
|
||||
QCoro::Task<> checkGateStatus(LoginInformation *info);
|
||||
|
||||
void bootCheck(const LoginInformation &info);
|
||||
QCoro::Task<> bootCheck(const LoginInformation &info);
|
||||
|
||||
private:
|
||||
Patcher *patcher = nullptr;
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <qcorotask.h>
|
||||
|
||||
#include "launchercore.h"
|
||||
#include "patcher.h"
|
||||
|
||||
|
@ -12,18 +14,19 @@ class SquareLauncher : public QObject
|
|||
public:
|
||||
explicit SquareLauncher(LauncherCore &window, QObject *parent = nullptr);
|
||||
|
||||
void getStored(const LoginInformation &info);
|
||||
using StoredInfo = std::pair<QString, QUrl>;
|
||||
QCoro::Task<std::optional<StoredInfo>> getStored(const LoginInformation &info);
|
||||
|
||||
void login(const LoginInformation &info, const QUrl &referer);
|
||||
QCoro::Task<> login(const LoginInformation &info);
|
||||
|
||||
void registerSession(const LoginInformation &info);
|
||||
QCoro::Task<> registerSession(const LoginInformation &info);
|
||||
|
||||
private:
|
||||
QString getBootHash(const LoginInformation &info);
|
||||
|
||||
Patcher *patcher = nullptr;
|
||||
|
||||
QString stored, SID, username;
|
||||
QString SID, username;
|
||||
LoginAuth auth;
|
||||
|
||||
LauncherCore &window;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <QStandardPaths>
|
||||
#include <QUrlQuery>
|
||||
#include <physis.hpp>
|
||||
#include <qcoronetworkreply.h>
|
||||
|
||||
#include "account.h"
|
||||
#include "squarelauncher.h"
|
||||
|
@ -21,7 +22,7 @@ SquareBoot::SquareBoot(LauncherCore &window, SquareLauncher &launcher, QObject *
|
|||
{
|
||||
}
|
||||
|
||||
void SquareBoot::bootCheck(const LoginInformation &info)
|
||||
QCoro::Task<> SquareBoot::bootCheck(const LoginInformation &info)
|
||||
{
|
||||
Q_EMIT window.stageChanged(i18n("Checking for launcher updates..."));
|
||||
qDebug() << "Performing boot check...";
|
||||
|
@ -30,7 +31,7 @@ void SquareBoot::bootCheck(const LoginInformation &info)
|
|||
connect(patcher, &Patcher::done, [this, &info] {
|
||||
info.profile->readGameVersion();
|
||||
|
||||
launcher.getStored(info);
|
||||
launcher.login(info);
|
||||
});
|
||||
|
||||
QUrlQuery query;
|
||||
|
@ -52,14 +53,14 @@ void SquareBoot::bootCheck(const LoginInformation &info)
|
|||
request.setRawHeader("Host", QStringLiteral("patch-bootver.%1").arg(window.squareEnixServer()).toUtf8());
|
||||
|
||||
auto reply = window.mgr->get(request);
|
||||
connect(reply, &QNetworkReply::finished, [this, reply] {
|
||||
co_await reply;
|
||||
|
||||
const QString response = reply->readAll();
|
||||
|
||||
patcher->processPatchList(*window.mgr, response);
|
||||
});
|
||||
}
|
||||
|
||||
void SquareBoot::checkGateStatus(LoginInformation *info)
|
||||
QCoro::Task<> SquareBoot::checkGateStatus(LoginInformation *info)
|
||||
{
|
||||
Q_EMIT window.stageChanged(i18n("Checking gate..."));
|
||||
qDebug() << "Checking gate...";
|
||||
|
@ -76,7 +77,8 @@ void SquareBoot::checkGateStatus(LoginInformation *info)
|
|||
window.buildRequest(*info->profile, request);
|
||||
|
||||
auto reply = window.mgr->get(request);
|
||||
connect(reply, &QNetworkReply::finished, [this, reply, info] {
|
||||
co_await reply;
|
||||
|
||||
const QJsonDocument document = QJsonDocument::fromJson(reply->readAll());
|
||||
|
||||
const bool isGateOpen = !document.isEmpty() && document.object()["status"].toInt() != 0;
|
||||
|
@ -86,5 +88,4 @@ void SquareBoot::checkGateStatus(LoginInformation *info)
|
|||
} else {
|
||||
Q_EMIT window.loginError(i18n("The login gate is closed, the game may be under maintenance.\n\n%1", reply->errorString()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <QNetworkReply>
|
||||
#include <QRegularExpressionMatch>
|
||||
#include <QUrlQuery>
|
||||
#include <qcoronetworkreply.h>
|
||||
|
||||
#include "account.h"
|
||||
#include "launchercore.h"
|
||||
|
@ -31,7 +32,7 @@ QString getFileHash(const QString &file)
|
|||
return QString("%1/%2").arg(QString::number(f.size()), hash.result().toHex());
|
||||
}
|
||||
|
||||
void SquareLauncher::getStored(const LoginInformation &info)
|
||||
QCoro::Task<std::optional<SquareLauncher::StoredInfo>> SquareLauncher::getStored(const LoginInformation &info)
|
||||
{
|
||||
Q_EMIT window.stageChanged(i18n("Logging in..."));
|
||||
|
||||
|
@ -62,10 +63,10 @@ void SquareLauncher::getStored(const LoginInformation &info)
|
|||
auto request = QNetworkRequest(url);
|
||||
window.buildRequest(*info.profile, request);
|
||||
|
||||
QNetworkReply *reply = window.mgr->get(request);
|
||||
auto reply = window.mgr->get(request);
|
||||
co_await reply;
|
||||
|
||||
connect(reply, &QNetworkReply::finished, [this, &info, reply, url] {
|
||||
auto str = QString(reply->readAll());
|
||||
const auto str = QString(reply->readAll());
|
||||
|
||||
// fetches Steam username
|
||||
if (info.profile->account()->license() == Account::GameLicense::WindowsSteam) {
|
||||
|
@ -84,17 +85,22 @@ void SquareLauncher::getStored(const LoginInformation &info)
|
|||
QRegularExpression re(R"lit(\t<\s*input .* name="_STORED_" value="(?<stored>.*)">)lit");
|
||||
QRegularExpressionMatch match = re.match(str);
|
||||
if (match.hasMatch()) {
|
||||
stored = match.captured(1);
|
||||
login(info, url);
|
||||
co_return StoredInfo{match.captured(1), url};
|
||||
} else {
|
||||
Q_EMIT window.loginError(
|
||||
i18n("Square Enix servers refused to confirm session information. The game may be under maintenance, try the official launcher."));
|
||||
co_return {};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void SquareLauncher::login(const LoginInformation &info, const QUrl &referer)
|
||||
QCoro::Task<> SquareLauncher::login(const LoginInformation &info)
|
||||
{
|
||||
const auto storedResult = co_await getStored(info);
|
||||
if (storedResult == std::nullopt) {
|
||||
co_return;
|
||||
}
|
||||
const auto [stored, referer] = *storedResult;
|
||||
|
||||
QUrlQuery postData;
|
||||
postData.addQueryItem("_STORED_", stored);
|
||||
postData.addQueryItem("sqexid", info.username);
|
||||
|
@ -113,7 +119,8 @@ void SquareLauncher::login(const LoginInformation &info, const QUrl &referer)
|
|||
request.setRawHeader("Cache-Control", "no-cache");
|
||||
|
||||
auto reply = window.mgr->post(request, postData.toString(QUrl::FullyEncoded).toUtf8());
|
||||
connect(reply, &QNetworkReply::finished, [this, &info, reply] {
|
||||
co_await reply;
|
||||
|
||||
auto str = QString(reply->readAll());
|
||||
|
||||
QRegularExpression re(R"lit(window.external.user\("login=auth,ok,(?<launchParams>.*)\);)lit");
|
||||
|
@ -126,12 +133,12 @@ void SquareLauncher::login(const LoginInformation &info, const QUrl &referer)
|
|||
|
||||
if (!playable) {
|
||||
Q_EMIT window.loginError(i18n("Your account is unplayable. Check that you have the correct license, and a valid subscription."));
|
||||
return;
|
||||
co_return;
|
||||
}
|
||||
|
||||
if (!terms) {
|
||||
Q_EMIT window.loginError(i18n("Your account is unplayable. You need to accept the terms of service from the official launcher first."));
|
||||
return;
|
||||
co_return;
|
||||
}
|
||||
|
||||
SID = parts[1];
|
||||
|
@ -150,10 +157,9 @@ void SquareLauncher::login(const LoginInformation &info, const QUrl &referer)
|
|||
|
||||
Q_EMIT window.loginError(errorStr);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void SquareLauncher::registerSession(const LoginInformation &info)
|
||||
QCoro::Task<> SquareLauncher::registerSession(const LoginInformation &info)
|
||||
{
|
||||
QUrl url;
|
||||
url.setScheme("https");
|
||||
|
@ -177,7 +183,8 @@ void SquareLauncher::registerSession(const LoginInformation &info)
|
|||
}
|
||||
|
||||
auto reply = window.mgr->post(request, report.toUtf8());
|
||||
connect(reply, &QNetworkReply::finished, [this, &info, reply] {
|
||||
co_await reply;
|
||||
|
||||
if (reply->error() == QNetworkReply::NoError) {
|
||||
if (reply->rawHeaderList().contains("X-Patch-Unique-Id")) {
|
||||
QString body = reply->readAll();
|
||||
|
@ -205,7 +212,6 @@ void SquareLauncher::registerSession(const LoginInformation &info)
|
|||
Q_EMIT window.loginError(i18n("Unknown error when registering the session."));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
QString SquareLauncher::getBootHash(const LoginInformation &info)
|
||||
|
|
Loading…
Add table
Reference in a new issue