From ec86ee28171428824cde4afe88d1165e80633233 Mon Sep 17 00:00:00 2001 From: Erik Kundiman Date: Sun, 27 Jul 2025 22:38:14 +0800 Subject: Connect to Discord now through privacy tab Now the access token is saved the way passwords are saved, but without a username, so we can have some persistence without having to implement an OAuth2 backend server cause we would have to store those tokens there anyway still and that would even require more disclosure that the user token gets saved on a server, and it's just simpler to not go that way. Discord Social SDK doesn't have to have a helper for sending code to a custom server anyway, that we would have to have some asynchronous HTTP requestor ready. Show location check button gets enabled only when Discord integration is enabled, though it's not functioning yet. --- indra/newview/app_settings/settings.xml | 11 ++++ indra/newview/llappviewer.cpp | 72 +++++++++++++++------- indra/newview/llappviewer.h | 2 +- indra/newview/llfloaterpreference.cpp | 10 +++ indra/newview/llviewermenu.cpp | 10 --- indra/newview/skins/default/xui/en/menu_login.xml | 7 --- indra/newview/skins/default/xui/en/menu_viewer.xml | 7 --- .../default/xui/en/panel_preferences_privacy.xml | 2 + 8 files changed, 74 insertions(+), 47 deletions(-) diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index 315018bbee..a2e0a8dbbe 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -1161,6 +1161,17 @@ Value 1 + EnableDiscord + + Comment + When set, connect to Discord to enable Rich Presence + Persist + 1 + Type + Boolean + Value + 0 + EnableDiskCacheDebugInfo Comment diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp index 17f8c3e367..030c778990 100644 --- a/indra/newview/llappviewer.cpp +++ b/indra/newview/llappviewer.cpp @@ -5922,34 +5922,62 @@ void LLAppViewer::metricsSend(bool enable_reporting) void LLAppViewer::initDiscordSocial() { - gDiscordClient = std::make_shared(); - 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) {}); - } + gDiscordClient = std::make_shared(); + 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) {}); + } + }); + if (gSavedSettings.getBOOL("EnableDiscord")) + { + gDiscordClient->UpdateToken(discordpp::AuthorizationTokenType::Bearer, gSecAPIHandler->loadCredential("Discord")->getAuthenticator()["token"].asString(), [](discordpp::ClientResult result) { + if (result.Successful()) + gDiscordClient->Connect(); }); + } } -void LLAppViewer::handleDiscordSocial() +void LLAppViewer::handleDiscordSocial(bool enable) { static const uint64_t APPLICATION_ID = 1393451183741599796; - discordpp::AuthorizationArgs args{}; - args.SetClientId(APPLICATION_ID); - args.SetScopes(discordpp::Client::GetDefaultPresenceScopes()); - auto codeVerifier = gDiscordClient->CreateAuthorizationCodeVerifier(); - args.SetCodeChallenge(codeVerifier.Challenge()); - gDiscordClient->Authorize(args, [codeVerifier](auto result, auto code, auto redirectUri) { - if (result.Successful()) { - gDiscordClient->GetToken(APPLICATION_ID, code, codeVerifier.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(); + if (enable) + { + discordpp::AuthorizationArgs args{}; + args.SetClientId(APPLICATION_ID); + args.SetScopes(discordpp::Client::GetDefaultPresenceScopes()); + auto codeVerifier = gDiscordClient->CreateAuthorizationCodeVerifier(); + args.SetCodeChallenge(codeVerifier.Challenge()); + gDiscordClient->Authorize(args, [codeVerifier](auto result, auto code, auto redirectUri) { + if (result.Successful()) + { + gDiscordClient->GetToken(APPLICATION_ID, code, codeVerifier.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(); }); - }); - } - }); + LLSD authenticator = LLSD::emptyMap(); + authenticator["token"] = accessToken; + gSecAPIHandler->saveCredential(gSecAPIHandler->createCredential("Discord", LLSD::emptyMap(), authenticator), true); + }); + } + else + { + gSavedSettings.setBOOL("EnableDiscord", false); + } + }); + } + else + { + gDiscordClient->RevokeToken(APPLICATION_ID, gSecAPIHandler->loadCredential("Discord")->getAuthenticator()["token"].asString(), [](discordpp::ClientResult result) { + if (result.Successful()) + gDiscordClient->Disconnect(); + auto cred = new LLCredential("Discord"); + gSecAPIHandler->deleteCredential(cred); + }); + } } #endif diff --git a/indra/newview/llappviewer.h b/indra/newview/llappviewer.h index dc10738249..8ff07accbe 100644 --- a/indra/newview/llappviewer.h +++ b/indra/newview/llappviewer.h @@ -252,7 +252,7 @@ public: #ifdef LL_DISCORD static void initDiscordSocial(); - static void handleDiscordSocial(); + static void handleDiscordSocial(bool enable); #endif protected: diff --git a/indra/newview/llfloaterpreference.cpp b/indra/newview/llfloaterpreference.cpp index fdac390e8a..136683296f 100644 --- a/indra/newview/llfloaterpreference.cpp +++ b/indra/newview/llfloaterpreference.cpp @@ -237,6 +237,13 @@ void handleAppearanceCameraMovementChanged(const LLSD& newvalue) } } +#ifdef LL_DISCORD +void handleDiscordSocial(const LLSD& newvalue) +{ + LLAppViewer::handleDiscordSocial(newvalue.asBoolean()); +} +#endif + void fractionFromDecimal(F32 decimal_val, S32& numerator, S32& denominator) { numerator = 0; @@ -366,6 +373,9 @@ LLFloaterPreference::LLFloaterPreference(const LLSD& key) mCommitCallbackRegistrar.add("Pref.ClearLog", boost::bind(&LLConversationLog::onClearLog, &LLConversationLog::instance())); mCommitCallbackRegistrar.add("Pref.DeleteTranscripts", boost::bind(&LLFloaterPreference::onDeleteTranscripts, this)); mCommitCallbackRegistrar.add("UpdateFilter", boost::bind(&LLFloaterPreference::onUpdateFilterTerm, this, false)); // Hook up for filtering +#ifdef LL_DISCORD + gSavedSettings.getControl("EnableDiscord")->getCommitSignal()->connect(boost::bind(&handleDiscordSocial, _2)); +#endif } void LLFloaterPreference::processProperties( void* pData, EAvatarProcessorType type ) diff --git a/indra/newview/llviewermenu.cpp b/indra/newview/llviewermenu.cpp index 2c022d0a4c..810ebd90a5 100644 --- a/indra/newview/llviewermenu.cpp +++ b/indra/newview/llviewermenu.cpp @@ -8943,13 +8943,6 @@ void handle_report_bug(const LLSD& param) LLWeb::loadURLExternal(url); } -#ifdef LL_DISCORD -void handle_discord_social(const LLSD& param) -{ - LLAppViewer::handleDiscordSocial(); -} -#endif - void handle_buy_currency_test() { std::string url = @@ -9928,9 +9921,6 @@ void initialize_menus() commit.add("Advanced.WebContentTest", boost::bind(&handle_web_content_test, _2)); // this one opens the Web Content floater commit.add("Advanced.ShowURL", boost::bind(&handle_show_url, _2)); commit.add("Advanced.ReportBug", boost::bind(&handle_report_bug, _2)); -#ifdef LL_DISCORD - commit.add("Advanced.DiscordSocial", boost::bind(&handle_discord_social, _2)); -#endif view_listener_t::addMenu(new LLAdvancedBuyCurrencyTest(), "Advanced.BuyCurrencyTest"); view_listener_t::addMenu(new LLAdvancedDumpSelectMgr(), "Advanced.DumpSelectMgr"); view_listener_t::addMenu(new LLAdvancedDumpInventory(), "Advanced.DumpInventory"); diff --git a/indra/newview/skins/default/xui/en/menu_login.xml b/indra/newview/skins/default/xui/en/menu_login.xml index 04514e8a52..5fff9b7bc0 100644 --- a/indra/newview/skins/default/xui/en/menu_login.xml +++ b/indra/newview/skins/default/xui/en/menu_login.xml @@ -109,13 +109,6 @@ function="Advanced.ReportBug"/> - - - - diff --git a/indra/newview/skins/default/xui/en/menu_viewer.xml b/indra/newview/skins/default/xui/en/menu_viewer.xml index 56261ce874..1ec59bf2eb 100644 --- a/indra/newview/skins/default/xui/en/menu_viewer.xml +++ b/indra/newview/skins/default/xui/en/menu_viewer.xml @@ -1817,13 +1817,6 @@ function="World.EnvPreset" function="Advanced.ReportBug"/> - - - -