From d163f677005934cc0524f92298a09f1d68fcd0b3 Mon Sep 17 00:00:00 2001
From: Sally Coolatta <tehrealsalt@gmail.com>
Date: Mon, 17 Aug 2020 06:52:46 -0400
Subject: [PATCH] Update presence when maxplayers is changed

---
 src/d_clisrv.c | 14 +++++++++++++-
 src/discord.c  |  4 ----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/d_clisrv.c b/src/d_clisrv.c
index 3b29b2b0..16ed731e 100644
--- a/src/d_clisrv.c
+++ b/src/d_clisrv.c
@@ -3261,8 +3261,11 @@ consvar_t cv_allownewplayer = {"allowjoin", "On", CV_SAVE|CV_NETVAR, CV_OnOff, N
 #ifdef VANILLAJOINNEXTROUND
 consvar_t cv_joinnextround = {"joinnextround", "Off", CV_SAVE|CV_NETVAR, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; /// \todo not done
 #endif
+
+static void MaxPlayers_OnChange(void);
 static CV_PossibleValue_t maxplayers_cons_t[] = {{2, "MIN"}, {MAXPLAYERS, "MAX"}, {0, NULL}};
-consvar_t cv_maxplayers = {"maxplayers", "8", CV_SAVE|CV_NETVAR, maxplayers_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
+consvar_t cv_maxplayers = {"maxplayers", "8", CV_SAVE|CV_NETVAR|CV_CALL, maxplayers_cons_t, MaxPlayers_OnChange, 0, NULL, NULL, 0, 0, NULL};
+
 static CV_PossibleValue_t resynchattempts_cons_t[] = {{0, "MIN"}, {20, "MAX"}, {0, NULL}};
 consvar_t cv_resynchattempts = {"resynchattempts", "5", CV_SAVE, resynchattempts_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL	};
 consvar_t cv_blamecfail = {"blamecfail", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL	};
@@ -3279,6 +3282,15 @@ consvar_t cv_downloadspeed = {"downloadspeed", "16", CV_SAVE, downloadspeed_cons
 static void Got_AddPlayer(UINT8 **p, INT32 playernum);
 static void Got_RemovePlayer(UINT8 **p, INT32 playernum);
 
+static void MaxPlayers_OnChange(void)
+{
+#ifdef HAVE_DISCORDRPC
+	DRPC_UpdatePresence();
+#else
+	return;
+#endif
+}
+
 // called one time at init
 void D_ClientServerInit(void)
 {
diff --git a/src/discord.c b/src/discord.c
index f4789794..718f20c7 100644
--- a/src/discord.c
+++ b/src/discord.c
@@ -111,10 +111,6 @@ static void DRPC_HandleError(int err, const char *msg)
 --------------------------------------------------*/
 static void DRPC_HandleJoin(const char *secret)
 {
-	// Yes, this is called a "secret", but we send & use it
-	// directly, because if you're hosting SRB2, then you've
-	// already made your IP address totally public.
-
 	CONS_Printf("Connecting to %s via Discord\n", secret);
 	COM_BufAddText(va("connect \"%s\"\n", secret));
 }