mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2024-12-27 04:41:23 +00:00
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:
parent
ff8c70f9fe
commit
f9c8a1286d
6 changed files with 84 additions and 75 deletions
|
@ -371,7 +371,6 @@ ifdef HAVE_DISCORDRPC
|
||||||
LIBS+=-ldiscord-rpc
|
LIBS+=-ldiscord-rpc
|
||||||
CFLAGS+=-DHAVE_DISCORDRPC
|
CFLAGS+=-DHAVE_DISCORDRPC
|
||||||
OBJS+=$(OBJDIR)/discord.o
|
OBJS+=$(OBJDIR)/discord.o
|
||||||
OBJS+=$(OBJDIR)/discord_pass.o
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifndef NO_LUA
|
ifndef NO_LUA
|
||||||
|
|
|
@ -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
|
consvar_t cv_joinnextround = {"joinnextround", "Off", CV_NETVAR, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; /// \todo not done
|
||||||
#endif
|
#endif
|
||||||
static CV_PossibleValue_t maxplayers_cons_t[] = {{2, "MIN"}, {MAXPLAYERS, "MAX"}, {0, NULL}};
|
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}};
|
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_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 };
|
consvar_t cv_blamecfail = {"blamecfail", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL };
|
||||||
|
|
|
@ -475,7 +475,7 @@ static boolean SV_SendFile(INT32 node, const char *filename, UINT8 fileid)
|
||||||
char wadfilename[MAX_WADPATH];
|
char wadfilename[MAX_WADPATH];
|
||||||
|
|
||||||
if (cv_noticedownload.value)
|
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
|
// Find the last file in the list and set a pointer to its "next" field
|
||||||
q = &transfer[node].txlist;
|
q = &transfer[node].txlist;
|
||||||
|
|
151
src/discord.c
151
src/discord.c
|
@ -23,9 +23,10 @@
|
||||||
#include "mserv.h" // ms_RoomId
|
#include "mserv.h" // ms_RoomId
|
||||||
|
|
||||||
#include "discord.h"
|
#include "discord.h"
|
||||||
#include "discord_pass.h" // .gitignore'd file for volitile information; DO NOT push this info
|
|
||||||
#include "doomdef.h"
|
#include "doomdef.h"
|
||||||
|
|
||||||
|
#define DISCORD_APPID "503531144395096085" // Feel free to provide your own, if you care.
|
||||||
|
|
||||||
//
|
//
|
||||||
// DRPC_Handle's
|
// DRPC_Handle's
|
||||||
//
|
//
|
||||||
|
@ -58,15 +59,12 @@ void DRPC_Init(void)
|
||||||
DiscordEventHandlers handlers;
|
DiscordEventHandlers handlers;
|
||||||
memset(&handlers, 0, sizeof(handlers));
|
memset(&handlers, 0, sizeof(handlers));
|
||||||
|
|
||||||
if (!discordappid)
|
|
||||||
return;
|
|
||||||
|
|
||||||
handlers.ready = DRPC_HandleReady;
|
handlers.ready = DRPC_HandleReady;
|
||||||
handlers.disconnected = DRPC_HandleDisconnect;
|
handlers.disconnected = DRPC_HandleDisconnect;
|
||||||
handlers.errored = DRPC_HandleError;
|
handlers.errored = DRPC_HandleError;
|
||||||
handlers.joinGame = DRPC_HandleJoin;
|
handlers.joinGame = DRPC_HandleJoin;
|
||||||
|
|
||||||
Discord_Initialize(discordappid, &handlers, 1, NULL);
|
Discord_Initialize(DISCORD_APPID, &handlers, 1, NULL);
|
||||||
I_AddExitFunc(Discord_Shutdown);
|
I_AddExitFunc(Discord_Shutdown);
|
||||||
DRPC_UpdatePresence();
|
DRPC_UpdatePresence();
|
||||||
}
|
}
|
||||||
|
@ -83,85 +81,100 @@ void DRPC_UpdatePresence(void)
|
||||||
DiscordRichPresence discordPresence;
|
DiscordRichPresence discordPresence;
|
||||||
memset(&discordPresence, 0, sizeof(discordPresence));
|
memset(&discordPresence, 0, sizeof(discordPresence));
|
||||||
|
|
||||||
if (discordappid)
|
// Server info
|
||||||
|
if (netgame)
|
||||||
{
|
{
|
||||||
// Server info
|
const char *address;
|
||||||
if (netgame)
|
|
||||||
|
switch (ms_RoomId)
|
||||||
{
|
{
|
||||||
const char *address;
|
case -1: discordPresence.state = "Private"; break; // Private server
|
||||||
|
case 33: discordPresence.state = "Standard"; break;
|
||||||
switch (ms_RoomId)
|
case 28: discordPresence.state = "Casual"; break;
|
||||||
{
|
default: discordPresence.state = "???"; break; // How?
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
else
|
||||||
discordPresence.state = "Offline";
|
discordPresence.details = gametype_cons_t[gametype].strvalue;
|
||||||
|
}
|
||||||
|
|
||||||
// Gametype info
|
if (gamestate == GS_LEVEL || gamestate == GS_INTERMISSION) // Map info
|
||||||
if (gamestate == GS_LEVEL || gamestate == GS_INTERMISSION || gamestate == GS_VOTING)
|
{
|
||||||
{
|
if ((gamemap >= 1 && gamemap <= 55) // supported race maps
|
||||||
if (modeattacking)
|
|| (gamemap >= 136 && gamemap <= 164) // supported battle maps
|
||||||
discordPresence.details = "Record Attack";
|
//|| (gamemap >= 352 && gamemap <= 367) // supported hell maps (none of them)
|
||||||
else
|
)
|
||||||
discordPresence.details = gametype_cons_t[gametype].strvalue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Map info
|
|
||||||
if (gamestate == GS_LEVEL || gamestate == GS_INTERMISSION)
|
|
||||||
{
|
{
|
||||||
snprintf(mapimg, 8, "%s", G_BuildMapName(gamemap));
|
snprintf(mapimg, 8, "%s", G_BuildMapName(gamemap));
|
||||||
strlwr(mapimg);
|
strlwr(mapimg);
|
||||||
|
|
||||||
discordPresence.largeImageKey = mapimg; // Map image
|
discordPresence.largeImageKey = mapimg; // Map image
|
||||||
|
}
|
||||||
|
else // Fallback, since no image looks crappy!
|
||||||
|
discordPresence.largeImageKey = "miscdice";
|
||||||
|
|
||||||
if (mapheaderinfo[gamemap-1]->lvlttl[0] != '\0')
|
if (mapheaderinfo[gamemap-1]->menuflags & LF2_HIDEINMENU) // hell map, hide the name
|
||||||
snprintf(mapname, 48, "Map: %s%s%s",
|
discordPresence.largeImageText = "Map: ???";
|
||||||
mapheaderinfo[gamemap-1]->lvlttl,
|
else
|
||||||
(strlen(mapheaderinfo[gamemap-1]->zonttl) > 0) ? va(" %s",mapheaderinfo[gamemap-1]->zonttl) : // SRB2kart
|
{
|
||||||
((mapheaderinfo[gamemap-1]->levelflags & LF_NOZONE) ? "" : " ZONE"),
|
snprintf(mapname, 48, "Map: %s%s%s",
|
||||||
(strlen(mapheaderinfo[gamemap-1]->actnum) > 0) ? va(" %s",mapheaderinfo[gamemap-1]->actnum) : "");
|
mapheaderinfo[gamemap-1]->lvlttl,
|
||||||
else
|
(strlen(mapheaderinfo[gamemap-1]->zonttl) > 0) ? va(" %s",mapheaderinfo[gamemap-1]->zonttl) : // SRB2kart
|
||||||
snprintf(mapname, 48, "???");
|
((mapheaderinfo[gamemap-1]->levelflags & LF_NOZONE) ? "" : " Zone"),
|
||||||
|
(strlen(mapheaderinfo[gamemap-1]->actnum) > 0) ? va(" %s",mapheaderinfo[gamemap-1]->actnum) : "");
|
||||||
discordPresence.largeImageText = mapname; // Map name
|
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
|
snprintf(charname, 28, "Character: %s", skins[players[consoleplayer].skin].realname);
|
||||||
if (playeringame[consoleplayer])
|
discordPresence.smallImageText = charname; // Character name
|
||||||
{
|
|
||||||
//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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Discord_UpdatePresence(&discordPresence);
|
Discord_UpdatePresence(&discordPresence);
|
||||||
|
|
|
@ -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";
|
|
Loading…
Reference in a new issue