1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-04-21 20:27:45 +00:00
astra/launcher/core/src/squareboot.cpp

87 lines
3 KiB
C++
Raw Normal View History

2021-11-01 09:54:58 -04:00
#include "squareboot.h"
2022-08-15 11:14:37 -04:00
#include <QFile>
#include <QJsonDocument>
2021-11-01 09:54:58 -04:00
#include <QMessageBox>
2022-08-15 11:14:37 -04:00
#include <QNetworkReply>
#include <QPushButton>
#include <QStandardPaths>
2022-08-15 11:14:37 -04:00
#include <QUrlQuery>
#include <physis.hpp>
2021-11-01 09:54:58 -04:00
#include "squarelauncher.h"
2022-08-15 11:14:37 -04:00
SquareBoot::SquareBoot(LauncherCore& window, SquareLauncher& launcher)
: window(window), launcher(launcher), QObject(&window) {}
2021-11-01 09:54:58 -04:00
void SquareBoot::bootCheck(const LoginInformation& info) {
2022-08-09 22:44:10 -04:00
patcher = new Patcher(info.settings->gamePath + "/boot", info.settings->bootData);
connect(patcher, &Patcher::done, [=, &info] {
window.readGameVersion();
launcher.getStored(info);
});
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");
url.setPath(QString("/http/win32/ffxivneo_release_boot/%1").arg(info.settings->bootVersion));
2021-11-01 09:54:58 -04:00
url.setQuery(query);
auto request = QNetworkRequest(url);
2022-08-15 11:14:37 -04:00
if (info.settings->license == GameLicense::macOS) {
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);
connect(reply, &QNetworkReply::finished, [=, &info] {
const QString response = reply->readAll();
patcher->processPatchList(*window.mgr, response);
2021-11-01 09:54:58 -04:00
});
}
void SquareBoot::checkGateStatus(LoginInformation* info) {
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-09-05 15:50:58 -04:00
QNetworkRequest request(url);
// TODO: really?
window.buildRequest(*info->settings, request);
auto reply = window.mgr->get(request);
connect(reply, &QNetworkReply::finished, [=] {
// 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.
if (reply->error() == QNetworkReply::HostNotFoundError || reply->error() == QNetworkReply::TimeoutError ||
reply->error() == QNetworkReply::UnknownServerError)
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) {
bootCheck(*info);
} else {
2022-08-15 11:14:37 -04:00
auto messageBox = new QMessageBox(
QMessageBox::Icon::Critical,
"Failed to Login",
"The login gate is closed, the game may be under maintenance.");
messageBox->show();
}
});
}