diff --git a/launcher/include/launchercore.h b/launcher/include/launchercore.h index 0c31aa3..3b322d4 100755 --- a/launcher/include/launchercore.h +++ b/launcher/include/launchercore.h @@ -75,9 +75,6 @@ public: LauncherCore(); ~LauncherCore() override; - /// Initializes the Steamworks API. - void initializeSteam(); - /// Begins the login process. /// It's designed to be opaque as possible to the caller. /// \note The login process is asynchronous. @@ -130,6 +127,7 @@ public: [[nodiscard]] AccountManager *accountManager(); [[nodiscard]] Headline *headline() const; [[nodiscard]] QString cachedLogoImage() const; + [[nodiscard]] SteamAPI *steamApi() const; /** * @brief Opens the official launcher. Useful if Astra decides not to work that day! diff --git a/launcher/include/steamapi.h b/launcher/include/steamapi.h index e55533f..34b14c1 100644 --- a/launcher/include/steamapi.h +++ b/launcher/include/steamapi.h @@ -3,6 +3,8 @@ #pragma once +#include +#include #include class LauncherCore; @@ -12,7 +14,10 @@ class SteamAPI : public QObject public: explicit SteamAPI(QObject *parent = nullptr); - void setLauncherMode(bool isLauncher); + QCoro::Task<> initialize(); + QCoro::Task<> shutdown(); + QCoro::Task getTicket(); - [[nodiscard]] bool isDeck() const; +private: + QNetworkAccessManager m_qnam; }; \ No newline at end of file diff --git a/launcher/src/launchercore.cpp b/launcher/src/launchercore.cpp index 32db888..28149ed 100755 --- a/launcher/src/launchercore.cpp +++ b/launcher/src/launchercore.cpp @@ -45,6 +45,7 @@ LauncherCore::LauncherCore() m_profileManager = new ProfileManager(this); m_accountManager = new AccountManager(this); m_runner = new GameRunner(*this, this); + m_steamApi = new SteamAPI(this); connect(m_accountManager, &AccountManager::accountAdded, this, &LauncherCore::fetchAvatar); connect(m_accountManager, &AccountManager::accountLodestoneIdChanged, this, &LauncherCore::fetchAvatar); @@ -79,12 +80,6 @@ LauncherCore::~LauncherCore() m_config->save(); } -void LauncherCore::initializeSteam() -{ - m_steamApi = new SteamAPI(this); - m_steamApi->setLauncherMode(true); -} - void LauncherCore::login(Profile *profile, const QString &username, const QString &password, const QString &oneTimePassword) { Q_ASSERT(profile != nullptr); @@ -445,6 +440,11 @@ QString LauncherCore::cachedLogoImage() const return m_cachedLogoImage; } +SteamAPI *LauncherCore::steamApi() const +{ + return m_steamApi; +} + #ifdef BUILD_SYNC SyncManager *LauncherCore::syncManager() const { @@ -480,10 +480,6 @@ QCoro::Task<> LauncherCore::beginLogin(LoginInformation &info) Q_EMIT stageChanged(i18n("Launching game...")); - if (isSteam()) { - m_steamApi->setLauncherMode(false); - } - m_runner->beginGameExecutable(*info.profile, auth); } diff --git a/launcher/src/main.cpp b/launcher/src/main.cpp index d20bc45..e60c641 100755 --- a/launcher/src/main.cpp +++ b/launcher/src/main.cpp @@ -133,11 +133,6 @@ int main(int argc, char *argv[]) QQmlApplicationEngine engine; - const auto core = engine.singletonInstance(QStringLiteral("zone.xiv.astra"), QStringLiteral("LauncherCore")); - if (parser.isSet(steamOption)) { - core->initializeSteam(); - } - engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); QObject::connect(&engine, &QQmlApplicationEngine::quit, &app, &QCoreApplication::quit); diff --git a/launcher/src/squareenixlogin.cpp b/launcher/src/squareenixlogin.cpp index 0233014..e972576 100644 --- a/launcher/src/squareenixlogin.cpp +++ b/launcher/src/squareenixlogin.cpp @@ -232,9 +232,12 @@ QCoro::Task> SquareEnixLogin::getStor if (m_info->profile->account()->config()->license() == Account::GameLicense::WindowsSteam) { query.addQueryItem(QStringLiteral("issteam"), QString::number(1)); - // TODO: get steam ticket information from steam api - query.addQueryItem(QStringLiteral("session_ticket"), QString::number(1)); - query.addQueryItem(QStringLiteral("ticket_size"), QString::number(1)); + co_await m_launcher.steamApi()->initialize(); + + auto ticket = co_await m_launcher.steamApi()->getTicket(); + + query.addQueryItem(QStringLiteral("session_ticket"), ticket); + query.addQueryItem(QStringLiteral("ticket_size"), QString::number(ticket.length())); } QUrl url; diff --git a/launcher/src/steamapi.cpp b/launcher/src/steamapi.cpp index 2084db9..fdba45c 100644 --- a/launcher/src/steamapi.cpp +++ b/launcher/src/steamapi.cpp @@ -2,23 +2,46 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "steamapi.h" - #include "launchercore.h" +#include + SteamAPI::SteamAPI(QObject *parent) : QObject(parent) { - // TODO: stub } -void SteamAPI::setLauncherMode(bool isLauncher) +QCoro::Task<> SteamAPI::initialize() { - Q_UNUSED(isLauncher) - // TODO: stub + QUrl url; + url.setScheme(QStringLiteral("http")); + url.setHost(QStringLiteral("127.0.0.1")); + url.setPort(50481); + url.setPath(QStringLiteral("/init")); + + Q_UNUSED(co_await m_qnam.post(QNetworkRequest(url), QByteArray{})) } -bool SteamAPI::isDeck() const +QCoro::Task<> SteamAPI::shutdown() { - // TODO: stub - return false; + QUrl url; + url.setScheme(QStringLiteral("http")); + url.setHost(QStringLiteral("127.0.0.1")); + url.setPort(50481); + url.setPath(QStringLiteral("/shutdown")); + + Q_UNUSED(co_await m_qnam.post(QNetworkRequest(url), QByteArray{})) } + +QCoro::Task SteamAPI::getTicket() +{ + QUrl url; + url.setScheme(QStringLiteral("http")); + url.setHost(QStringLiteral("127.0.0.1")); + url.setPort(50481); + url.setPath(QStringLiteral("/ticket")); + + auto reply = co_await m_qnam.get(QNetworkRequest(url)); + + co_return QStringLiteral("todo"); +} \ No newline at end of file