From 923d88158846f8619e52cb34ba5dd1586f0af72d Mon Sep 17 00:00:00 2001 From: MysterD Date: Sat, 26 Mar 2022 01:21:36 -0700 Subject: [PATCH] Make Discord update the activity if player count changes --- src/pc/network/discord/activity.c | 17 ++++++++++++++++- src/pc/network/discord/activity.h | 1 + src/pc/network/discord/discord.c | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/pc/network/discord/activity.c b/src/pc/network/discord/activity.c index b891c050..cc4eaad4 100644 --- a/src/pc/network/discord/activity.c +++ b/src/pc/network/discord/activity.c @@ -117,7 +117,7 @@ void discord_activity_update(bool hosting) { if (gCurActivity.party.size.current_size > 1) { strcpy(gCurActivity.state, "Playing!"); } else if (hosting) { - strcpy(gCurActivity.state, "Waiting for player..."); + strcpy(gCurActivity.state, "Waiting for players..."); } else { strcpy(gCurActivity.state, "In-game."); gCurActivity.party.size.current_size = 1; @@ -138,6 +138,21 @@ void discord_activity_update(bool hosting) { LOGFILE_INFO(LFT_DISCORD, "set activity"); } +void discord_activity_update_check(void) { + if (gNetworkType == NT_NONE) { return; } + bool shouldUpdate = false; + u8 connectedCount = network_player_connected_count(); + + if (connectedCount > 0 && connectedCount != gCurActivity.party.size.current_size) { + gCurActivity.party.size.current_size = connectedCount; + shouldUpdate = true; + } + + if (shouldUpdate) { + discord_activity_update(gNetworkType == NT_SERVER); + } +} + struct IDiscordActivityEvents* discord_activity_initialize(void) { static struct IDiscordActivityEvents events = { 0 }; events.on_activity_join = on_activity_join; diff --git a/src/pc/network/discord/activity.h b/src/pc/network/discord/activity.h index aa134385..43eb25a1 100644 --- a/src/pc/network/discord/activity.h +++ b/src/pc/network/discord/activity.h @@ -5,6 +5,7 @@ extern struct DiscordActivity gCurActivity; void discord_activity_update(bool hosting); +void discord_activity_update_check(void); struct IDiscordActivityEvents* discord_activity_initialize(void); extern bool gActivityLock; diff --git a/src/pc/network/discord/discord.c b/src/pc/network/discord/discord.c index 55d2872a..e519f0b2 100644 --- a/src/pc/network/discord/discord.c +++ b/src/pc/network/discord/discord.c @@ -138,6 +138,8 @@ static bool ns_discord_match_addr(void* addr1, void* addr2) { static void ns_discord_update(void) { if (!gDiscordInitialized) { return; } + + discord_activity_update_check(); discord_lobby_update(); DISCORD_REQUIRE(app.core->run_callbacks(app.core)); discord_network_flush();