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>
|
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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SquareBoot::bootCheck(const LoginInformation &info)
|
|
|
|
{
|
|
|
|
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-07-30 14:56:24 -04:00
|
|
|
patcher = new Patcher(window, info.profile->gamePath() + "/boot", info.profile->bootData, this);
|
2023-07-30 10:11:14 -04:00
|
|
|
connect(patcher, &Patcher::done, [this, &info] {
|
2023-07-30 08:49:34 -04:00
|
|
|
info.profile->readGameVersion();
|
2022-07-20 18:00:42 -04:00
|
|
|
|
|
|
|
launcher.getStored(info);
|
|
|
|
});
|
2022-03-17 11:41:02 -04:00
|
|
|
|
2021-11-01 09:54:58 -04:00
|
|
|
QUrlQuery query;
|
|
|
|
query.addQueryItem("time", QDateTime::currentDateTimeUtc().toString("yyyy-MM-dd-HH-mm"));
|
|
|
|
|
|
|
|
QUrl url;
|
|
|
|
url.setScheme("http");
|
|
|
|
url.setHost("patch-bootver.ffxiv.com");
|
2023-07-30 08:49:34 -04:00
|
|
|
url.setPath(QString("/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) {
|
2022-03-16 15:03:35 -04:00
|
|
|
request.setRawHeader("User-Agent", "FFXIV-MAC PATCH CLIENT");
|
|
|
|
} else {
|
|
|
|
request.setRawHeader("User-Agent", "FFXIV PATCH CLIENT");
|
|
|
|
}
|
|
|
|
|
2021-11-01 09:54:58 -04:00
|
|
|
request.setRawHeader("Host", "patch-bootver.ffxiv.com");
|
|
|
|
|
|
|
|
auto reply = window.mgr->get(request);
|
2023-07-30 08:49:34 -04:00
|
|
|
connect(reply, &QNetworkReply::finished, [this, reply] {
|
2022-03-17 01:03:08 -04:00
|
|
|
const QString response = reply->readAll();
|
|
|
|
|
2022-07-20 18:00:42 -04:00
|
|
|
patcher->processPatchList(*window.mgr, response);
|
2021-11-01 09:54:58 -04:00
|
|
|
});
|
2022-05-09 15:53:17 -04:00
|
|
|
}
|
|
|
|
|
2023-07-30 08:49:34 -04:00
|
|
|
void SquareBoot::checkGateStatus(LoginInformation *info)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2022-09-05 15:50:58 -04:00
|
|
|
QUrl url("https://frontier.ffxiv.com/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-07-30 08:49:34 -04:00
|
|
|
window.buildRequest(*info->profile, request);
|
2022-05-09 15:53:17 -04:00
|
|
|
|
|
|
|
auto reply = window.mgr->get(request);
|
2023-07-30 10:11:14 -04:00
|
|
|
connect(reply, &QNetworkReply::finished, [this, reply, info] {
|
2022-05-09 15:53:17 -04:00
|
|
|
// I happen to run into this issue often, if I start the launcher really quickly after bootup
|
|
|
|
// it's possible to actually check this quicker than the network is actually available,
|
|
|
|
// causing the launcher to be stuck in "maintenace mode". so if that happens, we try to rerun this logic.
|
2022-08-15 11:14:37 -04:00
|
|
|
// TODO: this selection of errors is currently guesswork, i'm assuming one of these will fit the bill of
|
|
|
|
// "internet is unavailable" in some way.
|
2023-07-30 08:49:34 -04:00
|
|
|
if (reply->error() == QNetworkReply::HostNotFoundError || reply->error() == QNetworkReply::TimeoutError
|
|
|
|
|| reply->error() == QNetworkReply::UnknownServerError)
|
2022-05-09 15:53:17 -04:00
|
|
|
checkGateStatus(info);
|
|
|
|
|
|
|
|
QJsonDocument document = QJsonDocument::fromJson(reply->readAll());
|
|
|
|
|
|
|
|
const bool isGateOpen = !document.isEmpty() && document.object()["status"].toInt() != 0;
|
|
|
|
|
2022-08-15 11:14:37 -04:00
|
|
|
if (isGateOpen) {
|
2022-06-08 13:55:15 -04:00
|
|
|
bootCheck(*info);
|
2022-05-09 15:53:17 -04:00
|
|
|
} else {
|
2023-07-30 08:49:34 -04:00
|
|
|
Q_EMIT window.loginError(i18n("The login gate is closed, the game may be under maintenance."));
|
2022-05-09 15:53:17 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|