diff options
author | Erik Kundiman <erik@megapahit.org> | 2025-07-12 21:49:15 +0800 |
---|---|---|
committer | Erik Kundiman <erik@megapahit.org> | 2025-07-12 21:49:15 +0800 |
commit | 74b0178b7b4d672c7f6b317102b0ecd26f1ea033 (patch) | |
tree | 64f0f01a6b47b534c42d7f4b085b8724e639937a /indra/newview/llstartup.cpp | |
parent | b1d2961edb593393da5ae88e275be7bb2568969b (diff) |
Download DiscordSocialSdk-1.4.9649.zip
https://discord.com/developers/applications/1393451183741599796/social-sdk/downloads
to your ~/Downloads folder.
Add -DUSE_DISCORD:BOOL=ON to your cmake line.
The authorisation is triggered by selecting Help > Discord Social.
It seems that the user will need to do this every time they want Rich
Presence support on the viewer while using Discord.
The Discord app is still set to be a public client in the OAuth2 tab,
I'm going to try to make it work with the app set to be a confidential
client, next.
All Discord-related code are contained within one file, llstartup.cpp,
and other classes access it through some opaque layer, static functions,
otherwise we'd get these "duplicate symbol" linking errors.
Diffstat (limited to 'indra/newview/llstartup.cpp')
-rw-r--r-- | indra/newview/llstartup.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/indra/newview/llstartup.cpp b/indra/newview/llstartup.cpp index 3450792d30..834b99555e 100644 --- a/indra/newview/llstartup.cpp +++ b/indra/newview/llstartup.cpp @@ -217,6 +217,11 @@ #include "fsfloatersearch.h" +#ifdef LL_DISCORD +#define DISCORDPP_IMPLEMENTATION +#include <discordpp.h> +static std::shared_ptr<discordpp::Client> gDiscordClient; +#endif // // exported globals @@ -752,6 +757,17 @@ bool idle_startup() LL_WARNS("AppInit") << "Unreliable timers detected (may be bad PCI chipset)!!" << LL_ENDL; } +#ifdef LL_DISCORD + 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) {}); + } + }); +#endif + // // Log on to system // @@ -3431,6 +3447,35 @@ bool LLStartUp::startLLProxy() return proxy_ok; } +#ifdef LL_DISCORD + +void LLStartUp::runDiscordCallbacks() +{ + discordpp::RunCallbacks(); +} + +void LLStartUp::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 + bool login_alert_done(const LLSD& notification, const LLSD& response) { LLPanelLogin::giveFocus(); |