diff --git a/src/d_netcmd.c b/src/d_netcmd.c index dc4db789c..509759f06 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1990,11 +1990,6 @@ static void Got_NameAndColor(UINT8 **cp, INT32 playernum) // set follower K_SetFollowerByNum(playernum, follower); - -#ifdef HAVE_DISCORDRPC - if (playernum == consoleplayer) - DRPC_UpdatePresence(); -#endif } enum { diff --git a/src/discord.c b/src/discord.c index 595b17901..295ad0990 100644 --- a/src/discord.c +++ b/src/discord.c @@ -48,8 +48,31 @@ struct discordInfo_s discordInfo; discordRequest_t *discordRequestList = NULL; +size_t g_discord_skins = 0; + static char self_ip[IP_SIZE]; +/*-------------------------------------------------- + * const char *DRPC_HideUsername(const char *input) + * + * See header file for description. + * --------------------------------------------------*/ +const char *DRPC_HideUsername(const char *input) +{ + static char buffer[5]; + int i; + + buffer[0] = input[0]; + + for (i = 1; i < 4; ++i) + { + buffer[i] = '.'; + } + + buffer[4] = '\0'; + return buffer; +} + boolean drpc_init = false; /*-------------------------------------------------- @@ -102,11 +125,11 @@ static void DRPC_HandleReady(const DiscordUser *user) { if (cv_discordstreamer.value) { - CONS_Printf("Discord: connected to %s\n", user->username); + CONS_Printf("Discord: connected to %s\n", DRPC_HideUsername(user->username)); } else { - CONS_Printf("Discord: connected to %s#%s (%s)\n", user->username, user->discriminator, user->userId); + CONS_Printf("Discord: connected to %s (%s)\n", user->username, user->userId); } } @@ -242,8 +265,10 @@ static void DRPC_HandleJoinRequest(const DiscordUser *requestUser) newRequest->username = Z_Calloc(344, PU_STATIC, NULL); snprintf(newRequest->username, 344, "%s", requestUser->username); +#if 0 newRequest->discriminator = Z_Calloc(8, PU_STATIC, NULL); snprintf(newRequest->discriminator, 8, "%s", requestUser->discriminator); +#endif newRequest->userID = Z_Calloc(32, PU_STATIC, NULL); snprintf(newRequest->userID, 32, "%s", requestUser->userId); @@ -309,6 +334,9 @@ void DRPC_RemoveRequest(discordRequest_t *removeRequest) } Z_Free(removeRequest->username); +#if 0 + Z_Free(removeRequest->discriminator); +#endif Z_Free(removeRequest->userID); Z_Free(removeRequest); } @@ -770,66 +798,13 @@ void DRPC_UpdatePresence(void) // Character info if (Playing() && playeringame[consoleplayer] && !players[consoleplayer].spectator) { - // Supported skin names - static const char *supportedSkins[] = { - // base game - "sonic", - "tails", - "knuckles", - "eggman", - "metalsonic", - // bonus chars - "flicky", - "motobug", - "amy", - "mighty", - "ray", - "espio", - "vector", - "chao", - "gamma", - "chaos", - "shadow", - "rouge", - "herochao", - "darkchao", - "cream", - "omega", - "blaze", - "silver", - "wonderboy", - "arle", - "nights", - "sakura", - "ulala", - "beat", - "vyse", - "aiai", - "kiryu", - "aigis", - "miku", - "doom", - NULL - }; - - boolean customChar = true; - UINT8 checkSkin = 0; - // Character image - while (supportedSkins[checkSkin] != NULL) + if ((unsigned)players[consoleplayer].skin < g_discord_skins) // Supported skins { - if (!strcmp(skins[players[consoleplayer].skin].name, supportedSkins[checkSkin])) - { - snprintf(charimg, 22, "char_%s", supportedSkins[checkSkin]); - discordPresence.smallImageKey = charimg; - customChar = false; - break; - } - - checkSkin++; + snprintf(charimg, 21, "char_%s", skins[ players[consoleplayer].skin ].name); + discordPresence.smallImageKey = charimg; } - - if (customChar == true) + else { // Use the custom character icon! discordPresence.smallImageKey = "charcustom"; diff --git a/src/discord.h b/src/discord.h index 667d941da..80d23b15e 100644 --- a/src/discord.h +++ b/src/discord.h @@ -33,7 +33,9 @@ extern struct discordInfo_s { struct discordRequest_t { char *username; // Discord user name. +#if 0 // Good night, sweet prince... char *discriminator; // Discord discriminator (The little hashtag thing after the username). Separated for a "hide discriminators" cvar. +#endif char *userID; // The ID of the Discord user, gets used with Discord_Respond() // HAHAHA, no. @@ -48,6 +50,17 @@ struct discordRequest_t { extern discordRequest_t *discordRequestList; +extern size_t g_discord_skins; + +/*-------------------------------------------------- + * const char *DRPC_HideUsername(const char *input); + * + * Handle usernames while cv_discordstreamer is activated. + * (The loss of discriminators is still a dumbass regression + * that I will never forgive the Discord developers for.) + * --------------------------------------------------*/ + +const char *DRPC_HideUsername(const char *input); /*-------------------------------------------------- void DRPC_RemoveRequest(void); diff --git a/src/m_menu.c b/src/m_menu.c index e96235471..ad10169a9 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -9128,9 +9128,9 @@ static const char *M_GetDiscordName(discordRequest_t *r) return ""; if (cv_discordstreamer.value) - return r->username; + return DRPC_HideUsername(r->username); - return va("%s#%s", r->username, r->discriminator); + return r->username; } void MD_DrawDiscordRequests(void) diff --git a/src/r_skins.c b/src/r_skins.c index 6affcd4e6..e83916a9f 100644 --- a/src/r_skins.c +++ b/src/r_skins.c @@ -36,6 +36,8 @@ #include "hardware/hw_md2.h" #endif +#include "discord.h" + INT32 numskins = 0; skin_t skins[MAXSKINS]; INT32 skinsorted[MAXSKINS]; @@ -235,6 +237,11 @@ void R_InitSkins(void) if (!wadfiles[i]->compatmode) R_PatchSkins((UINT16)i); R_LoadSpriteInfoLumps(i, wadfiles[i]->numlumps); + + if (i < NUMMAINWADS) + { + g_discord_skins = numskins; + } } ST_ReloadSkinFaceGraphics(); } @@ -541,6 +548,11 @@ void SetPlayerSkinByNum(INT32 playernum, INT32 skinnum) // for replays: We have changed our skin mid-game; let the game know so it can do the same in the replay! demo_extradata[playernum] |= DXD_SKIN; +#ifdef HAVE_DISCORDRPC + if (player - players == consoleplayer) + DRPC_UpdatePresence(); +#endif + return; }