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)
This commit is contained in:
TehRealSalt 2018-10-30 05:44:29 -04:00
parent ff8c70f9fe
commit f9c8a1286d
6 changed files with 84 additions and 75 deletions

View file

@ -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

View file

@ -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 };

View file

@ -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;

View file

@ -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);

View file

View file

@ -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";