diff options
author | Erik Kundiman <erik@megapahit.org> | 2025-07-27 14:26:47 +0800 |
---|---|---|
committer | Erik Kundiman <erik@megapahit.org> | 2025-07-27 14:26:47 +0800 |
commit | dccf087d652ecf98d24927a397c38cc0c9db3ab4 (patch) | |
tree | 5674accffb95357ed057da983f1886f73e5151a1 /indra/newview/llappviewer.cpp | |
parent | 145ae5aeea43080bbf14de66d3d3886e01b8bb34 (diff) |
Move Discord-related code to llappviewer.cpp
The doFrame is the one called over and over again, so running the
Discord callbacks from there shouldn't have one extra function
overhead, while running the Discord initialisation is only once so
it's much more okay to have the extra function overhead there.
Diffstat (limited to 'indra/newview/llappviewer.cpp')
-rw-r--r-- | indra/newview/llappviewer.cpp | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp index 419d2cb842..d70287ac83 100644 --- a/indra/newview/llappviewer.cpp +++ b/indra/newview/llappviewer.cpp @@ -278,6 +278,12 @@ using namespace LL; #pragma warning (disable:4702) #endif +#ifdef LL_DISCORD +#define DISCORDPP_IMPLEMENTATION +#include <discordpp.h> +static std::shared_ptr<discordpp::Client> gDiscordClient; +#endif + static LLAppViewerListener sAppViewerListener(LLAppViewer::instance); ////// Windows-specific includes to the bottom - nasty defines in these pollute the preprocessor @@ -1349,7 +1355,7 @@ bool LLAppViewer::doFrame() TimePoint fpsLimitFrameStartTime = std::chrono::steady_clock::now(); #ifdef LL_DISCORD - LLStartUp::runDiscordCallbacks(); + discordpp::RunCallbacks(); #endif LL_RECORD_BLOCK_TIME(FTM_FRAME); @@ -5911,3 +5917,39 @@ void LLAppViewer::metricsSend(bool enable_reporting) // resolution in time. gViewerAssetStats->restart(); } + +#ifdef LL_DISCORD + +void LLAppViewer::initDiscordSocial() +{ + gDiscordClient = std::make_shared<discordpp::Client>(); + gDiscordClient->SetStatusChangedCallback([](discordpp::Client::Status status, discordpp::Client::Error, int32_t) { + if (status == discordpp::Client::Status::Ready) { + discordpp::Activity activity; + activity.SetType(discordpp::ActivityTypes::Playing); + gDiscordClient->UpdateRichPresence(activity, [](discordpp::ClientResult) {}); + } + }); +} + +void LLAppViewer::handleDiscordSocial() +{ + static const uint64_t DISCORD_APPLICATION_ID = 1393451183741599796; + discordpp::AuthorizationArgs discordAuthArgs{}; + discordAuthArgs.SetClientId(DISCORD_APPLICATION_ID); + discordAuthArgs.SetScopes(discordpp::Client::GetDefaultPresenceScopes()); + auto discordCodeVerifier = gDiscordClient->CreateAuthorizationCodeVerifier(); + discordAuthArgs.SetCodeChallenge(discordCodeVerifier.Challenge()); + gDiscordClient->Authorize(discordAuthArgs, [discordCodeVerifier](auto result, auto code, auto redirectUri) { + if (result.Successful()) { + gDiscordClient->GetToken(DISCORD_APPLICATION_ID, code, discordCodeVerifier.Verifier(), redirectUri, [](discordpp::ClientResult result, std::string accessToken, std::string, discordpp::AuthorizationTokenType, int32_t, std::string) { + gDiscordClient->UpdateToken(discordpp::AuthorizationTokenType::Bearer, accessToken, [](discordpp::ClientResult result) { + if (result.Successful()) + gDiscordClient->Connect(); + }); + }); + } + }); +} + +#endif |