From 6efab5bae5b062942e4d71973d053245ea9ebbb8 Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Tue, 30 Oct 2018 05:44:29 -0400 Subject: [PATCH] House keeping - Remove the potentially GPL-infringing discord_pass.h file. - Let DISCORD_APPID be a public #define. - Use server_context as party ID. - Add more states ("Watching Demo", "Menu"). - Only show map images on supported maps. Falls back to an image of a dice. - Displays "???" as the map name for Hell maps. - Voting displays an image of the BG planet, depending on the gamemode. - Added a fallback title screen large image. - Added a fallback character image. - General code cleanup & safety checks. - Give CV_NETVAR to cv_maxplayers (I should come up with a better way of sending this information without overwriting user settings, but this'll do for now) --- src/Makefile | 1 - src/d_clisrv.c | 2 +- src/d_netfil.c | 2 +- src/discord.c | 151 ++++++++++++++++++++++++--------------------- src/discord_pass.c | 0 src/discord_pass.h | 3 - 6 files changed, 84 insertions(+), 75 deletions(-) delete mode 100644 src/discord_pass.c delete mode 100644 src/discord_pass.h diff --git a/src/Makefile b/src/Makefile index 693de695f..9c65dd360 100644 --- a/src/Makefile +++ b/src/Makefile @@ -371,7 +371,6 @@ ifdef HAVE_DISCORDRPC LIBS+=-ldiscord-rpc CFLAGS+=-DHAVE_DISCORDRPC OBJS+=$(OBJDIR)/discord.o -OBJS+=$(OBJDIR)/discord_pass.o endif ifndef NO_LUA diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 9df160aa6..2f74b2c80 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2944,7 +2944,7 @@ consvar_t cv_allownewplayer = {"allowjoin", "On", CV_NETVAR, CV_OnOff, NULL, 0, consvar_t cv_joinnextround = {"joinnextround", "Off", CV_NETVAR, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; /// \todo not done #endif static CV_PossibleValue_t maxplayers_cons_t[] = {{2, "MIN"}, {MAXPLAYERS, "MAX"}, {0, NULL}}; -consvar_t cv_maxplayers = {"maxplayers", "8", CV_SAVE, maxplayers_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_maxplayers = {"maxplayers", "8", CV_SAVE|CV_NETVAR, maxplayers_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; static CV_PossibleValue_t resynchattempts_cons_t[] = {{0, "MIN"}, {20, "MAX"}, {0, NULL}}; consvar_t cv_resynchattempts = {"resynchattempts", "10", 0, resynchattempts_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; consvar_t cv_blamecfail = {"blamecfail", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; diff --git a/src/d_netfil.c b/src/d_netfil.c index 47d4d276e..7927c4ecf 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -475,7 +475,7 @@ static boolean SV_SendFile(INT32 node, const char *filename, UINT8 fileid) char wadfilename[MAX_WADPATH]; if (cv_noticedownload.value) - CONS_Printf("Sending file \"%s\" to node %d (%s)\n", filename, node, I_GetNodeAddress(node, false)); + CONS_Printf("Sending file \"%s\" to node %d (%s)\n", filename, node, I_GetNodeAddress(node)); // Find the last file in the list and set a pointer to its "next" field q = &transfer[node].txlist; diff --git a/src/discord.c b/src/discord.c index f508cce25..641c8eb09 100644 --- a/src/discord.c +++ b/src/discord.c @@ -23,9 +23,10 @@ #include "mserv.h" // ms_RoomId #include "discord.h" -#include "discord_pass.h" // .gitignore'd file for volitile information; DO NOT push this info #include "doomdef.h" +#define DISCORD_APPID "503531144395096085" // Feel free to provide your own, if you care. + // // DRPC_Handle's // @@ -58,15 +59,12 @@ void DRPC_Init(void) DiscordEventHandlers handlers; memset(&handlers, 0, sizeof(handlers)); - if (!discordappid) - return; - handlers.ready = DRPC_HandleReady; handlers.disconnected = DRPC_HandleDisconnect; handlers.errored = DRPC_HandleError; handlers.joinGame = DRPC_HandleJoin; - Discord_Initialize(discordappid, &handlers, 1, NULL); + Discord_Initialize(DISCORD_APPID, &handlers, 1, NULL); I_AddExitFunc(Discord_Shutdown); DRPC_UpdatePresence(); } @@ -83,85 +81,100 @@ void DRPC_UpdatePresence(void) DiscordRichPresence discordPresence; memset(&discordPresence, 0, sizeof(discordPresence)); - if (discordappid) + // Server info + if (netgame) { - // Server info - if (netgame) + const char *address; + + switch (ms_RoomId) { - const char *address; - - switch (ms_RoomId) - { - case -1: discordPresence.state = "Private"; break; // Private server - case 33: discordPresence.state = "Standard"; break; - case 28: discordPresence.state = "Casual"; break; - default: discordPresence.state = "???"; break; // How? - } - - discordPresence.partyId = "1"; // We don't really have "party" IDs, so to make invites expire we just let it reset to 0 outside of servers - - // Grab the host's IP for joining. - if (I_GetNodeAddress && (address = I_GetNodeAddress(servernode)) != NULL) - { - discordPresence.joinSecret = address; - CONS_Printf("%s\n", address); - } - - discordPresence.partySize = D_NumPlayers(); // Players in server - discordPresence.partyMax = cv_maxplayers.value; // Max players + case -1: discordPresence.state = "Private"; break; // Private server + case 33: discordPresence.state = "Standard"; break; + case 28: discordPresence.state = "Casual"; break; + default: discordPresence.state = "???"; break; // How? } + + discordPresence.partyId = server_context; // Thanks, whoever gave us Mumble support, for implementing the EXACT thing Discord wanted for this field! + + // Grab the host's IP for joining. + if (I_GetNodeAddress && (address = I_GetNodeAddress(servernode)) != NULL) + { + discordPresence.joinSecret = address; + CONS_Printf("%s\n", address); + } + + discordPresence.partySize = D_NumPlayers(); // Players in server + discordPresence.partyMax = cv_maxplayers.value; // Max players (turned into a netvar for this, FOR NOW!) + } + else if (Playing()) + discordPresence.state = "Offline"; + else if (demoplayback) + discordPresence.state = "Watching Demo"; + else + discordPresence.state = "Menu"; + + // Gametype info + if (gamestate == GS_LEVEL || gamestate == GS_INTERMISSION || gamestate == GS_VOTING) + { + if (modeattacking) + discordPresence.details = "Record Attack"; else - discordPresence.state = "Offline"; + discordPresence.details = gametype_cons_t[gametype].strvalue; + } - // Gametype info - if (gamestate == GS_LEVEL || gamestate == GS_INTERMISSION || gamestate == GS_VOTING) - { - if (modeattacking) - discordPresence.details = "Record Attack"; - else - discordPresence.details = gametype_cons_t[gametype].strvalue; - } - - // Map info - if (gamestate == GS_LEVEL || gamestate == GS_INTERMISSION) + if (gamestate == GS_LEVEL || gamestate == GS_INTERMISSION) // Map info + { + if ((gamemap >= 1 && gamemap <= 55) // supported race maps + || (gamemap >= 136 && gamemap <= 164) // supported battle maps + //|| (gamemap >= 352 && gamemap <= 367) // supported hell maps (none of them) + ) { snprintf(mapimg, 8, "%s", G_BuildMapName(gamemap)); strlwr(mapimg); - discordPresence.largeImageKey = mapimg; // Map image + } + else // Fallback, since no image looks crappy! + discordPresence.largeImageKey = "miscdice"; - if (mapheaderinfo[gamemap-1]->lvlttl[0] != '\0') - snprintf(mapname, 48, "Map: %s%s%s", - mapheaderinfo[gamemap-1]->lvlttl, - (strlen(mapheaderinfo[gamemap-1]->zonttl) > 0) ? va(" %s",mapheaderinfo[gamemap-1]->zonttl) : // SRB2kart - ((mapheaderinfo[gamemap-1]->levelflags & LF_NOZONE) ? "" : " ZONE"), - (strlen(mapheaderinfo[gamemap-1]->actnum) > 0) ? va(" %s",mapheaderinfo[gamemap-1]->actnum) : ""); - else - snprintf(mapname, 48, "???"); - + if (mapheaderinfo[gamemap-1]->menuflags & LF2_HIDEINMENU) // hell map, hide the name + discordPresence.largeImageText = "Map: ???"; + else + { + snprintf(mapname, 48, "Map: %s%s%s", + mapheaderinfo[gamemap-1]->lvlttl, + (strlen(mapheaderinfo[gamemap-1]->zonttl) > 0) ? va(" %s",mapheaderinfo[gamemap-1]->zonttl) : // SRB2kart + ((mapheaderinfo[gamemap-1]->levelflags & LF_NOZONE) ? "" : " Zone"), + (strlen(mapheaderinfo[gamemap-1]->actnum) > 0) ? va(" %s",mapheaderinfo[gamemap-1]->actnum) : ""); discordPresence.largeImageText = mapname; // Map name - - //if (cv_timelimit.value) - //discordPresence.endTimestamp = levelstarttime + (cv_timelimit.value*60); // Time limit if applicable } - else if (gamestate == GS_VOTING) + + // discordPresence.startTimestamp & endTimestamp could be used to show leveltime & timelimit respectively, + // but would need converted to epoch seconds somehow + } + else if (gamestate == GS_VOTING) + { + discordPresence.largeImageKey = (G_BattleGametype() ? "miscredplanet" : "miscblueplanet"); + discordPresence.largeImageText = "Voting"; + } + else + { + discordPresence.largeImageKey = "misctitle"; + discordPresence.largeImageText = "Title Screen"; + } + + // Character info + if (Playing() && playeringame[consoleplayer] && !players[consoleplayer].spectator) + { + if (players[consoleplayer].skin < 5) // supported skins { - discordPresence.largeImageText = "Voting"; + snprintf(charimg, 21, "char%s", skins[players[consoleplayer].skin].name); + discordPresence.smallImageKey = charimg; // Character image } + else + discordPresence.smallImageKey = "charnull"; // Just so that you can still see the name of custom chars - // Player info - if (playeringame[consoleplayer]) - { - //discordPresence.startTimestamp = levelstarttime; // Time in level - if (!players[consoleplayer].spectator) - { - snprintf(charimg, 21, "char%s", skins[players[consoleplayer].skin].name); - discordPresence.smallImageKey = charimg; // Character image - - snprintf(charname, 28, "Character: %s", skins[players[consoleplayer].skin].realname); - discordPresence.smallImageText = charname; // Character name - } - } + snprintf(charname, 28, "Character: %s", skins[players[consoleplayer].skin].realname); + discordPresence.smallImageText = charname; // Character name } Discord_UpdatePresence(&discordPresence); diff --git a/src/discord_pass.c b/src/discord_pass.c deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/discord_pass.h b/src/discord_pass.h deleted file mode 100644 index 4adeda90b..000000000 --- a/src/discord_pass.h +++ /dev/null @@ -1,3 +0,0 @@ -// This file is .gitignore'd for a reason! This is very sensitive info! -// Do not push any change that makes this a valid app ID! -const char* discordappid = "503531144395096085";