fivem
fivem copied to clipboard
feat(discord): user toggle for rich presence
Requested in https://forum.cfx.re/t/5018677
Allow users to either completely disable Discords Rich Presence status or only show the current game version without displaying any game status.
Shouldn't the flag for the ConVar be ConVar_UserPref
Shouldn't the flag for the ConVar be
ConVar_UserPref
Yes, correct! I missed this one, thank you. Should be fixed.
You could probably handle all of this in OnGameFrame and not have to modify the natives to have a bunch of g_richPresenceEnabled->GetValue() calls everywhere
static std::shared_ptr<ConVar<bool>> g_richPresenceEnabled = std::make_shared<ConVar<bool>>("game_enableDiscordRichPresence", ConVar_Archive | ConVar_UserPref, true);
static bool g_discordRichPresenceEnabled;
static bool g_wasRichPresencePreviouslyEnabled = true;
OnGameFrame.Connect([&handlers]()
{
if (!g_discordRichPresenceEnabled)
{
if (g_wasRichPresencePreviouslyEnabled)
{
g_wasRichPresencePreviouslyEnabled = false;
Discord_Shutdown();
}
return;
}
if (!g_wasRichPresencePreviouslyEnabled)
{
g_wasRichPresencePreviouslyEnabled = true;
Discord_Initialize(g_discordAppId.c_str(), &handlers, 1, nullptr);
}
Discord_RunCallbacks();
UpdatePresence();
});
You could probably handle all of this in OnGameFrame and not have to modify the natives to have a bunch of
g_richPresenceEnabled->GetValue()calls everywhere
Decided to go with your approach: If disabled, Rich Presence should be completely killed. Implemented like you proposed.
It would be cool to have a getter to check if the player has enabled Rich Presence (for example, to offer rewards if the player enables this option).
Servers have notoriously abused stuff like that
You can already get the current ConVar value with GetConvar("game_enableDiscordRichPresence", "true").
I already wanted to block this ConVar from ScRTs reads to avoid a situation like this one, seems like I forgot about this while implementing.
Any objections to blocking this?
I've discussed the mentioned improvements in the forum post and discussed this feature internally, we'd like to see it offer at least 3 options:
- Off
- On - only mentioning FiveM/RedM
- On - with server information
I'm more drawn to naming it cl_discordRichPresence for these options.
Will implement like proposed, thank you for the feedback.
This should now include all desired changes requested by @thorium-cfx.
The current commit has two implementation aspects I'm not sure about, but wasn't able to accomplish without changing other things first:
-~~ConVar change handlers won't get called if the ConVar value is unset and the default value is returned, so on a "fresh" install, Discord Rich Presence will not work till the user restarts their game at least once to get the ConVar set.~~ Applied a small workaround to properly set this on first startup and correct wrong values set by a user executing set cl_discordRichPresence
-cfx-ui doesn't expose any ConVar setters for int values, this is why I went with string here.
Also, regarding possible "unwanted" side-effects: Should this ConVar be readable by ScRTs to avoid servers kicking users if they decide to disable their rich presence?
Should this ConVar be readable by ScRTs to avoid servers kicking users if they decide to disable their rich presence?
Probably out of scope, but can't this be achieved with a discord bot? Most servers already force you to join their discord server.
Thank you @tens0rfl0w, I've been quite busy and will review the changes soon, but wanted to address this question:
Also, regarding possible "unwanted" side-effects: Should this ConVar be readable by ScRTs to avoid servers kicking users if they decide to disable their rich presence?
Seeing that the player wants to hide this for personal or privacy reasons, there's reason enough not to expose this to anyone, so no it shouldn't be readable.
Returning default_ now if read by GET_CONVAR.
(CI checks seem hung, repush didn't help)
~~Seems stale~~
Wrong assumption by me, apologies.
Merge conflicts resolved.