diff --git a/src/launchercore.cpp b/src/launchercore.cpp index f65405d..33be0c4 100755 --- a/src/launchercore.cpp +++ b/src/launchercore.cpp @@ -353,6 +353,12 @@ LauncherCore::LauncherCore() : settings(QSettings::IniFormat, QSettings::UserSco assetUpdater = new AssetUpdater(*this); readInitialInformation(); + + // check gate status before login + squareLauncher->gateOpen(); + + // TODO: we really should call this "heavy" signal + connect(squareLauncher, &SquareLauncher::gateStatusRecieved, this, &LauncherCore::settingsChanged); } ProfileSettings LauncherCore::getProfile(int index) const { diff --git a/src/launcherwindow.cpp b/src/launcherwindow.cpp index f734850..c7a69dc 100644 --- a/src/launcherwindow.cpp +++ b/src/launcherwindow.cpp @@ -86,7 +86,7 @@ LauncherWindow::LauncherWindow(LauncherCore& core, QWidget* parent) : QMainWindo otpEdit = new QLineEdit(); layout->addRow("One-Time Password", otpEdit); - auto loginButton = new QPushButton("Login"); + loginButton = new QPushButton("Login"); layout->addRow(loginButton); registerButton = new QPushButton("Register"); @@ -185,6 +185,15 @@ void LauncherWindow::reloadControls() { }); } + const bool isLockedOut = !currentProfile().isSapphire && !core.squareLauncher->isGateOpen; + + if(!isLockedOut) { + loginButton->setText("Login"); + } else { + loginButton->setText("Login (Maintenance is in progress)"); + } + + loginButton->setEnabled(!isLockedOut); registerButton->setEnabled(currentProfile().isSapphire); otpEdit->setEnabled(!currentProfile().isSapphire); diff --git a/src/launcherwindow.h b/src/launcherwindow.h index cf5d524..12a8889 100644 --- a/src/launcherwindow.h +++ b/src/launcherwindow.h @@ -27,5 +27,5 @@ private: QLineEdit* usernameEdit, *passwordEdit; QLineEdit* otpEdit; QCheckBox* rememberUsernameBox, *rememberPasswordBox; - QPushButton* registerButton; + QPushButton* loginButton, *registerButton; }; \ No newline at end of file diff --git a/src/squarelauncher.cpp b/src/squarelauncher.cpp index fa6e788..c47b3c1 100644 --- a/src/squarelauncher.cpp +++ b/src/squarelauncher.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include "launchercore.h" @@ -156,4 +158,30 @@ void SquareLauncher::readExpansionVersions(const LoginInformation& info, int max for(int i = 0; i < max; i++) expansionVersions.push_back(window.readVersion(QString("%1/game/sqpack/ex%2/ex%2.ver").arg(info.settings->gamePath, QString::number(i + 1)))); +} + +void SquareLauncher::gateOpen() { + QUrlQuery query; + query.addQueryItem("", QString::number(QDateTime::currentMSecsSinceEpoch())); + + QUrl url; + url.setUrl("https://frontier.ffxiv.com/worldStatus/gate_status.json"); + url.setQuery(query); + + QNetworkRequest request; + request.setUrl(url); + window.buildRequest(request); + + auto reply = window.mgr->get(request); + connect(reply, &QNetworkReply::finished, [this, reply] { + QJsonDocument document = QJsonDocument::fromJson(reply->readAll()); + + if(document.isEmpty() || document.object()["status"].toInt() == 0) { + gateStatusRecieved(false); + isGateOpen = false; + } else { + gateStatusRecieved(true); + isGateOpen = true; + } + }); } \ No newline at end of file diff --git a/src/squarelauncher.h b/src/squarelauncher.h index c724348..7d780ba 100644 --- a/src/squarelauncher.h +++ b/src/squarelauncher.h @@ -3,15 +3,23 @@ #include "launchercore.h" class SquareLauncher : public QObject { + Q_OBJECT public: SquareLauncher(LauncherCore& window); + void gateOpen(); + void getStored(const LoginInformation& info); void login(const LoginInformation& info, QUrl referer); void registerSession(const LoginInformation& info); + bool isGateOpen = false; + +signals: + void gateStatusRecieved(bool gateOpen); + private: QString getBootHash(const LoginInformation& info); void readExpansionVersions(const LoginInformation& info, int max);