diff --git a/Client/core/CClientVariables.cpp b/Client/core/CClientVariables.cpp index 65428619cc..fb9bd3b245 100644 --- a/Client/core/CClientVariables.cpp +++ b/Client/core/CClientVariables.cpp @@ -354,7 +354,9 @@ void CClientVariables::LoadDefaults() DEFAULT("browser_remote_javascript", true); // Execute javascript on remote websites? DEFAULT("filter_duplicate_log_lines", true); // Filter duplicate log lines for debug view and clientscript.log DEFAULT("always_show_transferbox", false); // Should the transfer box always be visible for downloads? (and ignore scripted control) - DEFAULT("allow_discord_rpc", true); // Enable Discord Rich Presence + DEFAULT("allow_discord_rpc", true); // Enable Discord Rich Presence + DEFAULT("discord_rpc_share_data", false); // Consistent Rich Presence data sharing + DEFAULT("discord_rpc_share_data_firsttime", false); // Display the user data sharing consent dialog box - for the first time DEFAULT("_beta_qc_rightclick_command", _S("reconnect")); // Command to run when right clicking quick connect (beta - can be removed at any time) if (!Exists("locale")) diff --git a/Client/core/CDiscordRichPresence.cpp b/Client/core/CDiscordRichPresence.cpp index d5acc18333..a759a46557 100644 --- a/Client/core/CDiscordRichPresence.cpp +++ b/Client/core/CDiscordRichPresence.cpp @@ -280,6 +280,20 @@ void CDiscordRichPresence::SetPresencePartySize(int iSize, int iMax, bool bCusto } } +void CDiscordRichPresence::SetDiscordUserID(const std::string& strUserID) +{ + if (CVARS_GET_VALUE("discord_rpc_share_data")) + m_strDiscordUserID = strUserID; +} + +std::string CDiscordRichPresence::GetDiscordUserID() const +{ + if (CVARS_GET_VALUE("discord_rpc_share_data")) + return m_strDiscordUserID; + + return {}; +}; + #ifdef DISCORD_DISABLE_IO_THREAD void CDiscordRichPresence::UpdatePresenceConnection() { @@ -290,7 +304,10 @@ void CDiscordRichPresence::UpdatePresenceConnection() void CDiscordRichPresence::HandleDiscordReady(const DiscordUser* pDiscordUser) { if (const auto discord = g_pCore->GetDiscord(); discord && discord->IsDiscordRPCEnabled()) + { discord->SetDiscordClientConnected(true); + discord->SetDiscordUserID(pDiscordUser->userId); + } } void CDiscordRichPresence::HandleDiscordDisconnected(int iErrorCode, const char* szMessage) @@ -298,7 +315,10 @@ void CDiscordRichPresence::HandleDiscordDisconnected(int iErrorCode, const char* WriteDebugEvent(SString("[DISCORD] Disconnected %s (error #%d)", szMessage, iErrorCode)); if (const auto discord = g_pCore->GetDiscord(); discord) + { + discord->SetDiscordUserID(""); discord->SetDiscordClientConnected(false); + } } void CDiscordRichPresence::HandleDiscordError(int iErrorCode, const char* szMessage) diff --git a/Client/core/CDiscordRichPresence.h b/Client/core/CDiscordRichPresence.h index 6cbc0b1dbe..d20bfa38bf 100644 --- a/Client/core/CDiscordRichPresence.h +++ b/Client/core/CDiscordRichPresence.h @@ -35,6 +35,7 @@ class CDiscordRichPresence : public CDiscordInterface void SetAssetSmallData(const char* szAsset, const char* szAssetText); void SetDiscordClientConnected(bool bConnected) { m_bConnected = bConnected; }; void SetPresencePartySize(int iSize, int iMax, bool bCustom); + void SetDiscordUserID(const std::string& strUserID); bool ResetDiscordData(); bool SetPresenceState(const char* szState, bool bCustom); @@ -47,6 +48,7 @@ class CDiscordRichPresence : public CDiscordInterface bool IsDiscordClientConnected() const { return m_bConnected; }; std::string GetDiscordResourceName() const { return m_strDiscordCustomResourceName; }; + std::string GetDiscordUserID() const; // static handlers static void HandleDiscordReady(const struct DiscordUser* pDiscordUser); @@ -54,6 +56,7 @@ class CDiscordRichPresence : public CDiscordInterface static void HandleDiscordError(int iErrorCode, const char* szMessage); private: + std::string m_strDiscordUserID; std::string m_strDiscordAppId; std::string m_strDiscordAppAsset; std::string m_strDiscordAppAssetText; diff --git a/Client/core/CMainMenu.cpp b/Client/core/CMainMenu.cpp index 97e23f5efb..7d1c2740a8 100644 --- a/Client/core/CMainMenu.cpp +++ b/Client/core/CMainMenu.cpp @@ -304,7 +304,6 @@ CMainMenu::CMainMenu(CGUI* pManager) discord->SetPresenceState(_("Main menu"), false); discord->SetPresenceStartTimestamp(0); } - // Store the pointer to the graphics subsystem m_pGraphics = CGraphics::GetSingletonPtr(); @@ -683,6 +682,19 @@ void CMainMenu::Update() } #endif + if (WaitForMenu == 299) + { + if (!g_pCore->GetCVars()->GetValue("discord_rpc_share_data_firsttime", false) + && g_pCore->GetCVars()->GetValue("allow_discord_rpc", false) + && !g_pCore->GetCVars()->GetValue("discord_rpc_share_data", false)) + { + m_Settings.ShowRichPresenceShareDataQuestionBox(); + CVARS_SET("discord_rpc_share_data_firsttime", true); + } + else + CVARS_SET("discord_rpc_share_data_firsttime", true); + } + if (WaitForMenu < 300) WaitForMenu++; } diff --git a/Client/core/CSettings.cpp b/Client/core/CSettings.cpp index 0992f0fec8..085241c468 100644 --- a/Client/core/CSettings.cpp +++ b/Client/core/CSettings.cpp @@ -4515,10 +4515,38 @@ bool CSettings::OnAllowExternalSoundsClick(CGUIElement* pElement) // bool CSettings::OnAllowDiscordRPC(CGUIElement* pElement) { - g_pCore->GetDiscord()->SetDiscordRPCEnabled(m_pCheckBoxAllowDiscordRPC->GetSelected()); + bool isEnabled = m_pCheckBoxAllowDiscordRPC->GetSelected(); + g_pCore->GetDiscord()->SetDiscordRPCEnabled(isEnabled); + + if (isEnabled) + ShowRichPresenceShareDataQuestionBox(); // show question box + return true; } +static void ShowRichPresenceShareDataCallback(void* ptr, unsigned int uiButton) +{ + CCore::GetSingleton().GetLocalGUI()->GetMainMenu()->GetQuestionWindow()->Reset(); + + CVARS_SET("discord_rpc_share_data", static_cast(uiButton)); +} + +void CSettings::ShowRichPresenceShareDataQuestionBox() const +{ + SStringX strMessage( + _("It seems that you have the Rich Presence connection option enabled." + "\nDo you want to allow servers to share their data?" + "\n\nThis includes yours unique ID identifier.")); + CQuestionBox* pQuestionBox = CCore::GetSingleton().GetLocalGUI()->GetMainMenu()->GetQuestionWindow(); + pQuestionBox->Reset(); + pQuestionBox->SetTitle(_("CONSENT TO ALLOW DATA SHARING")); + pQuestionBox->SetMessage(strMessage); + pQuestionBox->SetButton(0, _("No")); + pQuestionBox->SetButton(1, _("Yes")); + pQuestionBox->SetCallback(ShowRichPresenceShareDataCallback); + pQuestionBox->Show(); +} + // // CustomizedSAFiles // diff --git a/Client/core/CSettings.h b/Client/core/CSettings.h index 495eb2a01b..8ee44437f5 100644 --- a/Client/core/CSettings.h +++ b/Client/core/CSettings.h @@ -119,6 +119,7 @@ class CSettings bool IsActive(); void SetSelectedIndex(unsigned int uiIndex); + void ShowRichPresenceShareDataQuestionBox() const; protected: const static int SecKeyNum = 3; // Number of secondary keys diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaDiscordDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaDiscordDefs.cpp index 9b3e907aa9..f2ca089565 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaDiscordDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaDiscordDefs.cpp @@ -25,7 +25,7 @@ void CLuaDiscordDefs::LoadFunctions() {"setDiscordRichPresencePartySize", ArgumentParser}, {"resetDiscordRichPresenceData", ArgumentParser}, {"isDiscordRichPresenceConnected", ArgumentParser }, - + {"getDiscordRichPresenceUserID", ArgumentParser}, }; // Add functions @@ -266,3 +266,13 @@ bool CLuaDiscordDefs::IsDiscordRPCConnected() return discord->IsDiscordClientConnected(); } + +std::string CLuaDiscordDefs::GetDiscordUserID() +{ + auto discord = g_pCore->GetDiscord(); + + if (!discord || !discord->IsDiscordRPCEnabled()) + return {}; + + return discord->GetDiscordUserID(); +} diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaDiscordDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaDiscordDefs.h index 936ec6839d..dfa7787cad 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaDiscordDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaDiscordDefs.h @@ -29,6 +29,6 @@ class CLuaDiscordDefs : public CLuaDefs static bool SetEndTime(unsigned long ulTime); static bool SetPartySize(int iMin, int iMax); static bool IsDiscordRPCConnected(); - + static std::string GetDiscordUserID(); }; diff --git a/Client/sdk/core/CDiscordInterface.h b/Client/sdk/core/CDiscordInterface.h index e1f927e7f8..3730939671 100644 --- a/Client/sdk/core/CDiscordInterface.h +++ b/Client/sdk/core/CDiscordInterface.h @@ -27,6 +27,7 @@ class CDiscordInterface virtual void SetPresenceEndTimestamp(const unsigned long ulEnd) = 0; virtual void SetPresencePartySize(int iSize, int iMax, bool bCustom) = 0; virtual void SetDiscordClientConnected(bool bConnected) = 0; + virtual void SetDiscordUserID(const std::string& strUserID) = 0; virtual bool SetPresenceDetails(const char* szDetails, bool bCustom) = 0; virtual bool SetApplicationID(const char* szResourceName, const char* szAppID) = 0; @@ -39,4 +40,5 @@ class CDiscordInterface virtual bool IsDiscordClientConnected() const = 0; virtual std::string GetDiscordResourceName() const = 0; + virtual std::string GetDiscordUserID() const = 0; };