From 8d386fba66fa6554389e8c9aaa021ce2aeecd518 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Mon, 17 Aug 2020 02:05:16 -0400 Subject: [PATCH] Display time elasped/time limit --- src/discord.c | 36 +++++++++++++++++++++++++----------- src/mserv.c | 16 ++++++++-------- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/discord.c b/src/discord.c index 68c1d14d..0a57b15f 100644 --- a/src/discord.c +++ b/src/discord.c @@ -192,25 +192,28 @@ void DRPC_UpdatePresence(void) case 33: discordPresence.state = "Standard"; break; case 28: discordPresence.state = "Casual"; break; case 38: discordPresence.state = "Custom Gametypes"; break; - //case ??: discordPresence.state = "OLDC"; break; // If I remembered this one's room ID, I would add it :V + case 31: discordPresence.state = "OLDC"; break; default: discordPresence.state = "Unknown Room"; break; // HOW } discordPresence.partyId = server_context; // Thanks, whoever gave us Mumble support, for implementing the EXACT thing Discord wanted for this field! + discordPresence.partySize = D_NumPlayers(); // Players in server + discordPresence.partyMax = cv_maxplayers.value; // Max players (TODO: use another variable to hold this, so maxplayers doesn't have to be a netvar!) // Grab the host's IP for joining. if ((join = DRPC_GetServerIP()) != NULL) discordPresence.joinSecret = join; - - discordPresence.partySize = D_NumPlayers(); // Players in server - discordPresence.partyMax = cv_maxplayers.value; // Max players (TODO: use another variable to hold this, so maxplayers doesn't have to be a netvar!) } - else if (Playing()) - discordPresence.state = "Offline"; - else if (demo.playback) - discordPresence.state = "Watching Replay"; else - discordPresence.state = "Menu"; + { + // Offline info + if (Playing()) + discordPresence.state = "Offline"; + else if (demo.playback && !demo.title) + discordPresence.state = "Watching Replay"; + else + discordPresence.state = "Menu"; + } // Gametype info if (gamestate == GS_LEVEL || gamestate == GS_INTERMISSION || gamestate == GS_VOTING) @@ -245,8 +248,19 @@ void DRPC_UpdatePresence(void) discordPresence.largeImageText = mapname; // Map name } - // discordPresence.startTimestamp & endTimestamp could be used to show leveltime & timelimit respectively, - // but would need converted to epoch seconds somehow + if (gamestate == GS_LEVEL) + { + const time_t currentTime = time(NULL); + const time_t mapTimeStart = currentTime - (leveltime / TICRATE); + + discordPresence.startTimestamp = mapTimeStart; + + if (timelimitintics > 0) + { + const time_t mapTimeEnd = mapTimeStart + ((timelimitintics + starttime + 1) / TICRATE); + discordPresence.endTimestamp = mapTimeEnd; + } + } } else if (gamestate == GS_VOTING) { diff --git a/src/mserv.c b/src/mserv.c index 7311227a..2c91781c 100644 --- a/src/mserv.c +++ b/src/mserv.c @@ -261,6 +261,10 @@ Finish_update (void) if (! done) Finish_update(); +#ifdef HAVE_DISCORDRPC + else + DRPC_UpdatePresence(); +#endif } static void @@ -298,6 +302,10 @@ Finish_unlist (void) MSId++; } Unlock_state(); + +#ifdef HAVE_DISCORDRPC + DRPC_UpdatePresence(); +#endif } #ifdef HAVE_THREADS @@ -434,10 +442,6 @@ void UnregisterServer(void) #else Finish_unlist(); #endif - -#ifdef HAVE_DISCORDRPC - DRPC_UpdatePresence(); -#endif } static boolean @@ -495,10 +499,6 @@ Update_parameters (void) if (! delayed && registered) UpdateServer(); } - -#ifdef HAVE_DISCORDRPC - DRPC_UpdatePresence(); -#endif } void MasterClient_Ticker(void)