~redstrate/astra

astra/launcher/core/src/squareboot.cpp -rw-r--r-- 3.0 KiB
04324554Toofy Correct placement of String in right method 2 months ago
                                                                                                                        
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "squareboot.h"

#include <QFile>
#include <QJsonDocument>
#include <QMessageBox>
#include <QNetworkReply>
#include <QPushButton>
#include <QStandardPaths>
#include <QUrlQuery>
#include <physis.hpp>

#include "squarelauncher.h"

SquareBoot::SquareBoot(LauncherCore& window, SquareLauncher& launcher)
    : window(window), launcher(launcher), QObject(&window) {}

void SquareBoot::bootCheck(const LoginInformation& info) {
    patcher = new Patcher(info.settings->gamePath + "/boot", info.settings->bootData);
    connect(patcher, &Patcher::done, [=, &info] {
        window.readGameVersion();

        launcher.getStored(info);
    });

    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));
    url.setQuery(query);

    auto request = QNetworkRequest(url);
    if (info.settings->license == GameLicense::macOS) {
        request.setRawHeader("User-Agent", "FFXIV-MAC PATCH CLIENT");
    } else {
        request.setRawHeader("User-Agent", "FFXIV PATCH CLIENT");
    }

    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);
    });
}

void SquareBoot::checkGateStatus(LoginInformation* info) {
    QUrl url("https://frontier.ffxiv.com/worldStatus/gate_status.json");
    url.setQuery(QString::number(QDateTime::currentMSecsSinceEpoch()));

    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.
        // 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;

        if (isGateOpen) {
            bootCheck(*info);
        } else {
            auto messageBox = new QMessageBox(
                QMessageBox::Icon::Critical,
                "Failed to Login",
                "The login gate is closed, the game may be under maintenance.");

            messageBox->show();
        }
    });
}