2023-08-05 22:14:05 -04:00
|
|
|
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2021-11-01 09:54:58 -04:00
|
|
|
#include "squareboot.h"
|
|
|
|
|
2023-07-30 08:49:34 -04:00
|
|
|
#include <KLocalizedString>
|
2022-08-15 11:14:37 -04:00
|
|
|
#include <QFile>
|
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QNetworkReply>
|
2022-03-17 01:03:08 -04:00
|
|
|
#include <QStandardPaths>
|
2022-08-15 11:14:37 -04:00
|
|
|
#include <QUrlQuery>
|
2022-07-20 18:00:42 -04:00
|
|
|
#include <physis.hpp>
|
2023-09-16 18:52:12 -04:00
|
|
|
#include <qcoronetworkreply.h>
|
2021-11-01 09:54:58 -04:00
|
|
|
|
2023-07-30 08:49:34 -04:00
|
|
|
#include "account.h"
|
2021-11-01 09:54:58 -04:00
|
|
|
#include "squarelauncher.h"
|
|
|
|
|
2023-07-30 08:49:34 -04:00
|
|
|
SquareBoot::SquareBoot(LauncherCore &window, SquareLauncher &launcher, QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, window(window)
|
|
|
|
, launcher(launcher)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-09-16 18:52:12 -04:00
|
|
|
QCoro::Task<> SquareBoot::bootCheck(const LoginInformation &info)
|
2023-07-30 08:49:34 -04:00
|
|
|
{
|
|
|
|
Q_EMIT window.stageChanged(i18n("Checking for launcher updates..."));
|
2023-07-31 19:24:01 -04:00
|
|
|
qDebug() << "Performing boot check...";
|
2021-11-01 09:54:58 -04:00
|
|
|
|
2023-09-16 19:02:59 -04:00
|
|
|
const QUrlQuery query{{QStringLiteral("time"), QDateTime::currentDateTimeUtc().toString(QStringLiteral("yyyy-MM-dd-HH-mm"))}};
|
2021-11-01 09:54:58 -04:00
|
|
|
|
|
|
|
QUrl url;
|
2023-09-16 19:02:59 -04:00
|
|
|
url.setScheme(QStringLiteral("http"));
|
2023-08-18 21:36:29 -04:00
|
|
|
url.setHost(QStringLiteral("patch-bootver.%1").arg(window.squareEnixServer()));
|
2023-09-17 08:51:26 -04:00
|
|
|
url.setPath(QStringLiteral("/http/win32/ffxivneo_release_boot/%1").arg(info.profile->bootVersion()));
|
2021-11-01 09:54:58 -04:00
|
|
|
url.setQuery(query);
|
|
|
|
|
|
|
|
auto request = QNetworkRequest(url);
|
2023-07-30 08:49:34 -04:00
|
|
|
if (info.profile->account()->license() == Account::GameLicense::macOS) {
|
2023-09-16 19:02:59 -04:00
|
|
|
request.setRawHeader(QByteArrayLiteral("User-Agent"), QByteArrayLiteral("FFXIV-MAC PATCH CLIENT"));
|
2022-03-16 15:03:35 -04:00
|
|
|
} else {
|
2023-09-16 19:02:59 -04:00
|
|
|
request.setRawHeader(QByteArrayLiteral("User-Agent"), QByteArrayLiteral("FFXIV PATCH CLIENT"));
|
2022-03-16 15:03:35 -04:00
|
|
|
}
|
|
|
|
|
2023-09-16 19:02:59 -04:00
|
|
|
request.setRawHeader(QByteArrayLiteral("Host"), QStringLiteral("patch-bootver.%1").arg(window.squareEnixServer()).toUtf8());
|
2021-11-01 09:54:58 -04:00
|
|
|
|
2023-09-16 19:02:59 -04:00
|
|
|
const auto reply = window.mgr->get(request);
|
2023-09-16 18:52:12 -04:00
|
|
|
co_await reply;
|
2022-03-17 01:03:08 -04:00
|
|
|
|
2023-09-17 18:43:58 -04:00
|
|
|
const QString patchList = reply->readAll();
|
|
|
|
if (!patchList.isEmpty()) {
|
|
|
|
patcher = new Patcher(window, info.profile->gamePath() + QStringLiteral("/boot"), *info.profile->bootData(), this);
|
2023-10-04 11:09:50 -04:00
|
|
|
const bool hasPatched = co_await patcher->patch(PatchList(patchList));
|
2023-09-17 18:43:58 -04:00
|
|
|
if (hasPatched) {
|
|
|
|
// update game version information
|
|
|
|
info.profile->readGameVersion();
|
|
|
|
}
|
|
|
|
patcher->deleteLater();
|
|
|
|
}
|
2023-09-16 20:12:42 -04:00
|
|
|
|
|
|
|
launcher.login(info);
|
2022-05-09 15:53:17 -04:00
|
|
|
}
|
|
|
|
|
2023-09-17 18:43:58 -04:00
|
|
|
QCoro::Task<> SquareBoot::checkGateStatus(const LoginInformation &info)
|
2023-07-30 08:49:34 -04:00
|
|
|
{
|
|
|
|
Q_EMIT window.stageChanged(i18n("Checking gate..."));
|
2023-07-31 19:24:01 -04:00
|
|
|
qDebug() << "Checking gate...";
|
2023-07-30 08:49:34 -04:00
|
|
|
|
2023-08-18 21:36:29 -04:00
|
|
|
QUrl url;
|
2023-10-06 18:14:32 -04:00
|
|
|
url.setScheme(window.preferredProtocol());
|
2023-08-18 21:36:29 -04:00
|
|
|
url.setHost(QStringLiteral("frontier.%1").arg(window.squareEnixServer()));
|
2023-09-16 19:02:59 -04:00
|
|
|
url.setPath(QStringLiteral("/worldStatus/gate_status.json"));
|
2022-09-05 15:49:58 -04:00
|
|
|
url.setQuery(QString::number(QDateTime::currentMSecsSinceEpoch()));
|
2022-05-09 15:53:17 -04:00
|
|
|
|
2022-09-05 15:50:58 -04:00
|
|
|
QNetworkRequest request(url);
|
2022-05-09 15:53:17 -04:00
|
|
|
|
|
|
|
// TODO: really?
|
2023-09-17 18:43:58 -04:00
|
|
|
window.buildRequest(*info.profile, request);
|
2022-05-09 15:53:17 -04:00
|
|
|
|
2023-09-16 19:02:59 -04:00
|
|
|
const auto reply = window.mgr->get(request);
|
2023-10-06 18:14:32 -04:00
|
|
|
window.setupIgnoreSSL(reply);
|
2023-09-16 18:52:12 -04:00
|
|
|
co_await reply;
|
2022-05-09 15:53:17 -04:00
|
|
|
|
2023-09-16 18:52:12 -04:00
|
|
|
const QJsonDocument document = QJsonDocument::fromJson(reply->readAll());
|
2023-09-16 19:02:59 -04:00
|
|
|
const bool isGateOpen = !document.isEmpty() && document.object()[QLatin1String("status")].toInt() != 0;
|
2023-09-16 18:52:12 -04:00
|
|
|
|
|
|
|
if (isGateOpen) {
|
2023-09-17 18:43:58 -04:00
|
|
|
bootCheck(info);
|
2023-09-16 18:52:12 -04:00
|
|
|
} else {
|
|
|
|
Q_EMIT window.loginError(i18n("The login gate is closed, the game may be under maintenance.\n\n%1", reply->errorString()));
|
|
|
|
}
|
2022-05-09 15:53:17 -04:00
|
|
|
}
|