From b8f3cb04302c0284619899d49a733021a86e6014 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sun, 17 Dec 2023 13:24:08 -0500 Subject: [PATCH] Check login gate status too --- launcher/include/squareenixlogin.h | 4 +++ launcher/src/squareenixlogin.cpp | 39 ++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/launcher/include/squareenixlogin.h b/launcher/include/squareenixlogin.h index 53d795e..3df9f35 100644 --- a/launcher/include/squareenixlogin.h +++ b/launcher/include/squareenixlogin.h @@ -25,6 +25,10 @@ private: /// \return False if the gate is closed, true if open. QCoro::Task checkGateStatus(); + /// Checks the login status to see if the servers are closed for maintenance + /// \return False if logging in is disabled, true if open. + QCoro::Task checkLoginStatus(); + /// Check for updates to the boot components. Even though we don't use these, it's checked by later login steps. QCoro::Task<> checkBootUpdates(); diff --git a/launcher/src/squareenixlogin.cpp b/launcher/src/squareenixlogin.cpp index a94ce7a..132f20f 100644 --- a/launcher/src/squareenixlogin.cpp +++ b/launcher/src/squareenixlogin.cpp @@ -37,6 +37,10 @@ QCoro::Task> SquareEnixLogin::login(LoginInformation *i co_await checkBootUpdates(); + if (!co_await checkLoginStatus()) { + co_return std::nullopt; + } + if (!co_await loginOAuth()) { co_return std::nullopt; } @@ -83,6 +87,41 @@ QCoro::Task SquareEnixLogin::checkGateStatus() } } +QCoro::Task SquareEnixLogin::checkLoginStatus() +{ + Q_EMIT m_launcher.stageChanged(i18n("Checking login...")); + qInfo(ASTRA_LOG) << "Checking if login is open..."; + + QUrl url; + url.setScheme(m_launcher.settings()->preferredProtocol()); + url.setHost(QStringLiteral("frontier.%1").arg(m_launcher.settings()->squareEnixServer())); + url.setPath(QStringLiteral("/worldStatus/login_status.json")); + url.setQuery(QString::number(QDateTime::currentMSecsSinceEpoch())); + + QNetworkRequest request(url); + + // TODO: really? + m_launcher.buildRequest(*m_info->profile, request); + + Utility::printRequest(QStringLiteral("GET"), request); + + const auto reply = m_launcher.mgr()->get(request); + m_launcher.setupIgnoreSSL(reply); + co_await reply; + + const QJsonDocument document = QJsonDocument::fromJson(reply->readAll()); + const bool isGateOpen = !document.isEmpty() && document.object()["status"_L1].toInt() != 0; + + if (isGateOpen) { + qInfo(ASTRA_LOG) << "Login is open!"; + co_return true; + } else { + qInfo(ASTRA_LOG) << "Lgoin is closed!"; + Q_EMIT m_launcher.loginError(i18n("The login gate is closed, the game may be under maintenance.\n\n%1", reply->errorString())); + co_return false; + } +} + QCoro::Task<> SquareEnixLogin::checkBootUpdates() { Q_EMIT m_launcher.stageChanged(i18n("Checking for launcher updates..."));