From a30b26fa3a279906666107424ac1efa36f463071 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 29 Jun 2024 20:46:08 -0400 Subject: [PATCH] Meh, throw out XIVAPI and fetch avatars from the Lodestone directly XIVAPI was kind of unnecessary here, and on top of that it's barely working nowadays. We can grab the image URL directly from the Lodestone, cutting out the middleman. --- launcher/config.kcfg | 4 +- launcher/include/launchersettings.h | 8 ++-- launcher/src/account.cpp | 45 ++++++++++++---------- launcher/src/launchersettings.cpp | 12 +++--- launcher/src/squareenixlogin.cpp | 8 ++-- launcher/ui/Settings/DeveloperSettings.qml | 14 +++---- 6 files changed, 47 insertions(+), 44 deletions(-) diff --git a/launcher/config.kcfg b/launcher/config.kcfg index 85c9b45..7242e32 100644 --- a/launcher/config.kcfg +++ b/launcher/config.kcfg @@ -40,8 +40,8 @@ SPDX-License-Identifier: CC0-1.0 square-enix.com - - xivapi.com + + finalfantasyxiv.com https diff --git a/launcher/include/launchersettings.h b/launcher/include/launchersettings.h index e5d536f..f1adbf2 100644 --- a/launcher/include/launchersettings.h +++ b/launcher/include/launchersettings.h @@ -22,7 +22,7 @@ class LauncherSettings : public QObject Q_PROPERTY(QString dalamudDistribServer READ dalamudDistribServer WRITE setDalamudDistribServer NOTIFY dalamudDistribServerChanged) Q_PROPERTY(QString squareEnixServer READ squareEnixServer WRITE setSquareEnixServer NOTIFY squareEnixServerChanged) Q_PROPERTY(QString squareEnixLoginServer READ squareEnixLoginServer WRITE setSquareEnixLoginServer NOTIFY squareEnixLoginServerChanged) - Q_PROPERTY(QString xivApiServer READ xivApiServer WRITE setXivApiServer NOTIFY xivApiServerChanged) + Q_PROPERTY(QString mainServer READ mainServer WRITE setMainServer NOTIFY mainServerChanged) Q_PROPERTY(QString preferredProtocol READ preferredProtocol WRITE setPreferredProtocol NOTIFY preferredProtocolChanged) Q_PROPERTY(QString screenshotDir READ screenshotDir WRITE setScreenshotDir NOTIFY screenshotDirChanged) Q_PROPERTY(bool argumentsEncrypted READ argumentsEncrypted WRITE setArgumentsEncrypted NOTIFY encryptedArgumentsChanged) @@ -52,8 +52,8 @@ public: [[nodiscard]] QString squareEnixLoginServer() const; void setSquareEnixLoginServer(const QString &value); - [[nodiscard]] QString xivApiServer() const; - void setXivApiServer(const QString &value); + [[nodiscard]] QString mainServer() const; + void setMainServer(const QString &value); [[nodiscard]] QString preferredProtocol() const; void setPreferredProtocol(const QString &value); @@ -80,7 +80,7 @@ Q_SIGNALS: void dalamudDistribServerChanged(); void squareEnixServerChanged(); void squareEnixLoginServerChanged(); - void xivApiServerChanged(); + void mainServerChanged(); void preferredProtocolChanged(); void screenshotDirChanged(); void encryptedArgumentsChanged(); diff --git a/launcher/src/account.cpp b/launcher/src/account.cpp index 8d86368..df71038 100644 --- a/launcher/src/account.cpp +++ b/launcher/src/account.cpp @@ -239,38 +239,41 @@ void Account::fetchAvatar() const QString filename = QStringLiteral("%1/%2.jpg").arg(cacheLocation, lodestoneId()); if (!QFile(filename).exists()) { - qDebug(ASTRA_LOG) << "Did not find lodestone character " << lodestoneId() << " in cache, fetching from xivapi."; + qDebug(ASTRA_LOG) << "Did not find lodestone character " << lodestoneId() << " in cache, fetching from Lodestone."; QUrl url; url.setScheme(m_launcher.settings()->preferredProtocol()); - url.setHost(m_launcher.settings()->xivApiServer()); - - url.setPath(QStringLiteral("/character/%1").arg(lodestoneId())); + url.setHost(QStringLiteral("na.%1").arg(m_launcher.settings()->mainServer())); // TODO: NA isnt the only thing in the world... + url.setPath(QStringLiteral("/lodestone/character/%1").arg(lodestoneId())); QNetworkRequest request(url); Utility::printRequest(QStringLiteral("GET"), request); const auto reply = m_launcher.mgr()->get(request); connect(reply, &QNetworkReply::finished, [this, filename, reply] { - auto document = QJsonDocument::fromJson(reply->readAll()); - if (document.isObject()) { - const QNetworkRequest avatarRequest(QUrl(document.object()["Character"_L1].toObject()["Avatar"_L1].toString())); - Utility::printRequest(QStringLiteral("GET"), avatarRequest); + QString document = QString::fromUtf8(reply->readAll()); + if (!document.isEmpty()) { + const static QRegularExpression re( + QStringLiteral(R"lit(]*class=["|']frame__chara__face["|'][^>]*>\s*]*src=["|']([^"']*))lit")); + const QRegularExpressionMatch match = re.match(document); - if (avatarRequest.url().isEmpty()) { - return; + if (match.hasCaptured(1)) { + const QString newAvatarUrl = match.captured(1); + + const QNetworkRequest avatarRequest = QNetworkRequest(QUrl(newAvatarUrl)); + Utility::printRequest(QStringLiteral("GET"), avatarRequest); + + auto avatarReply = m_launcher.mgr()->get(avatarRequest); + connect(avatarReply, &QNetworkReply::finished, [this, filename, avatarReply] { + QFile file(filename); + file.open(QIODevice::ReadWrite); + file.write(avatarReply->readAll()); + file.close(); + + m_avatarUrl = QStringLiteral("file:///%1").arg(filename); + Q_EMIT avatarUrlChanged(); + }); } - - auto avatarReply = m_launcher.mgr()->get(avatarRequest); - connect(avatarReply, &QNetworkReply::finished, [this, filename, avatarReply] { - QFile file(filename); - file.open(QIODevice::ReadWrite); - file.write(avatarReply->readAll()); - file.close(); - - m_avatarUrl = QStringLiteral("file:///%1").arg(filename); - Q_EMIT avatarUrlChanged(); - }); } }); } else { diff --git a/launcher/src/launchersettings.cpp b/launcher/src/launchersettings.cpp index eae1693..777bfbc 100644 --- a/launcher/src/launchersettings.cpp +++ b/launcher/src/launchersettings.cpp @@ -107,17 +107,17 @@ void LauncherSettings::setSquareEnixLoginServer(const QString &value) } } -QString LauncherSettings::xivApiServer() const +QString LauncherSettings::mainServer() const { - return m_config->xivApiServer(); + return m_config->mainServer(); } -void LauncherSettings::setXivApiServer(const QString &value) +void LauncherSettings::setMainServer(const QString &value) { - if (value != m_config->xivApiServer()) { - m_config->setXivApiServer(value); + if (value != m_config->mainServer()) { + m_config->setMainServer(value); m_config->save(); - Q_EMIT xivApiServerChanged(); + Q_EMIT mainServerChanged(); } } diff --git a/launcher/src/squareenixlogin.cpp b/launcher/src/squareenixlogin.cpp index 4192055..a2705d0 100644 --- a/launcher/src/squareenixlogin.cpp +++ b/launcher/src/squareenixlogin.cpp @@ -237,7 +237,7 @@ QCoro::Task> SquareEnixLogin::getStor // fetches Steam username if (m_info->profile->account()->license() == Account::GameLicense::WindowsSteam) { - const QRegularExpression re(QStringLiteral(R"lit(.*)""\/>)lit")); + const static QRegularExpression re(QStringLiteral(R"lit(.*)""\/>)lit")); const QRegularExpressionMatch match = re.match(str); if (match.hasMatch()) { @@ -249,7 +249,7 @@ QCoro::Task> SquareEnixLogin::getStor m_username = m_info->username; } - const QRegularExpression re(QStringLiteral(R"lit(\t<\s*input .* name="_STORED_" value="(?.*)">)lit")); + const static QRegularExpression re(QStringLiteral(R"lit(\t<\s*input .* name="_STORED_" value="(?.*)">)lit")); const QRegularExpressionMatch match = re.match(str); if (match.hasMatch()) { co_return StoredInfo{match.captured(1), url}; @@ -296,7 +296,7 @@ QCoro::Task SquareEnixLogin::loginOAuth() const QString str = QString::fromUtf8(reply->readAll()); - const QRegularExpression re(QStringLiteral(R"lit(window.external.user\("login=auth,ok,(?.*)\);)lit")); + const static QRegularExpression re(QStringLiteral(R"lit(window.external.user\("login=auth,ok,(?.*)\);)lit")); const QRegularExpressionMatch match = re.match(str); if (match.hasMatch()) { const auto parts = match.captured(1).split(','_L1); @@ -320,7 +320,7 @@ QCoro::Task SquareEnixLogin::loginOAuth() co_return true; } else { - const QRegularExpression errorRe(QStringLiteral(R"lit(window.external.user\("login=auth,ng,err,(?.*)\);)lit")); + const static QRegularExpression errorRe(QStringLiteral(R"lit(window.external.user\("login=auth,ng,err,(?.*)\);)lit")); const QRegularExpressionMatch errorMatch = errorRe.match(str); if (errorMatch.hasCaptured(1)) { diff --git a/launcher/ui/Settings/DeveloperSettings.qml b/launcher/ui/Settings/DeveloperSettings.qml index a1359f2..38f57f0 100644 --- a/launcher/ui/Settings/DeveloperSettings.qml +++ b/launcher/ui/Settings/DeveloperSettings.qml @@ -114,7 +114,7 @@ FormCard.FormCardPage { FormCard.FormTextFieldDelegate { id: mainServerDelegate - label: i18n("SE Main Server") + label: i18n("SE Main Server (ffxiv.com)") text: LauncherCore.settings.squareEnixServer onTextChanged: LauncherCore.settings.squareEnixServer = text } @@ -127,22 +127,22 @@ FormCard.FormCardPage { FormCard.FormTextFieldDelegate { id: loginServerDelegate - label: i18n("SE Login Server") + label: i18n("SE Login Server (square-enix.com)") text: LauncherCore.settings.squareEnixLoginServer onTextChanged: LauncherCore.settings.squareEnixLoginServer = text } FormCard.FormDelegateSeparator { above: loginServerDelegate - below: xivApiServerDelegate + below: mainServerDelegate } FormCard.FormTextFieldDelegate { - id: xivApiServerDelegate + id: mainServerDelegate - label: i18n("XIV Api Server") - text: LauncherCore.settings.xivApiServer - onTextChanged: LauncherCore.settings.xivApiServer = text + label: i18n("Main Server (finalfantasyxiv.com)") + text: LauncherCore.settings.mainServer + onTextChanged: LauncherCore.settings.mainServer = text } } } \ No newline at end of file