From b62892ba1c62f00769a2964195eea4b6c271fb6c Mon Sep 17 00:00:00 2001 From: toaster Date: Sun, 22 Sep 2024 17:44:26 +0100 Subject: [PATCH] Reimplement midgame Pause Menu flow for Spectate status change - Currently no console command, as "teamchange" no longer applies... relatively simple to add one if needed though - Change the "Team Change" warning when allowteamchange is false to say "Joining Play" --- src/d_netcmd.c | 27 ++++++++++----- src/menus/transient/pause-game.c | 58 ++++++++++++-------------------- src/p_user.c | 3 +- 3 files changed, 41 insertions(+), 47 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 328a540e2..4e24613c0 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -3480,10 +3480,18 @@ void P_SetPlayerSpectator(INT32 playernum) static void Got_Spectate(const UINT8 **cp, INT32 playernum) { UINT8 edit_player = READUINT8(*cp); + UINT8 desired_state = READUINT8(*cp); - if (playernum != serverplayer && IsPlayerAdmin(playernum) == false) + if (playeringame[edit_player] == false) { - CONS_Alert(CONS_WARNING, M_GetText("Illegal team change received from player %s\n"), player_names[playernum]); + return; + } + + if (playernum != playerconsole[edit_player] + && playernum != serverplayer + && IsPlayerAdmin(playernum) == false) + { + CONS_Alert(CONS_WARNING, M_GetText("Illegal spectate command received from player %s\n"), player_names[playernum]); if (server) { SendKick(playernum, KICK_MSG_CON_FAIL); @@ -3497,14 +3505,8 @@ static void Got_Spectate(const UINT8 **cp, INT32 playernum) } player_t *const player = &players[edit_player]; - if (player->spectator == true && (player->pflags & PF_WANTSTOJOIN) == 0) - { - // No change would occur. - return; - } // Safety first! - // (not respawning spectators here...) const boolean was_spectator = (player->spectator == true); if (was_spectator == false) { @@ -3519,7 +3521,14 @@ static void Got_Spectate(const UINT8 **cp, INT32 playernum) HU_AddChatText(va("\x82*%s became a spectator.", player_names[edit_player]), false); } - player->pflags &= ~PF_WANTSTOJOIN; + if (desired_state != 0) + { + player->pflags |= PF_WANTSTOJOIN; + } + else + { + player->pflags &= ~PF_WANTSTOJOIN; + } if (gamestate != GS_LEVEL || was_spectator == true) { diff --git a/src/menus/transient/pause-game.c b/src/menus/transient/pause-game.c index 7e283504e..fb684650f 100644 --- a/src/menus/transient/pause-game.c +++ b/src/menus/transient/pause-game.c @@ -11,6 +11,7 @@ /// \file menus/transient/pause-game.c /// \brief In-game/pause menus +#include "../../byteptr.h" #include "../../d_netcmd.h" #include "../../i_time.h" #include "../../k_menu.h" @@ -478,50 +479,33 @@ void M_HandleSpectateToggle(INT32 choice) return; } - boolean tospectator = false; + // Identify relevant spectator state of pausemenu.splitscreenfocusid. + // See also M_DrawPause. + + const UINT8 splitspecid = + g_localplayers[pausemenu.splitscreenfocusid]; + + const UINT8 joingame = ( + players[splitspecid].spectator == true + && ((players[splitspecid].pflags & PF_WANTSTOJOIN) == 0) + ) ? 1 : 0; + + if (joingame && !cv_allowteamchange.value) { - // Identify relevant spectator state of pausemenu.splitscreenfocusid. - // See also M_DrawPause. - - const UINT8 splitspecid = - g_localplayers[pausemenu.splitscreenfocusid]; - - tospectator = ( - players[splitspecid].spectator == false - || (players[splitspecid].pflags & PF_WANTSTOJOIN) - ); - } - - if (!tospectator && !cv_allowteamchange.value) - { - M_StartMessage("Team Change", M_GetText("The server is not allowing\nteam changes at this time.\n"), NULL, MM_NOTHING, NULL, NULL); + M_StartMessage("Joining Play", M_GetText("The server is not allowing\njoining play at this time.\n"), NULL, MM_NOTHING, NULL, NULL); return; } M_QuitPauseMenu(-1); - const char *destinationstate = tospectator ? "spectator" : "playing"; + // Send spectate + UINT8 buf[2]; + UINT8 *p = buf; - // These console command names... - if (pausemenu.splitscreenfocusid == 0) - { - COM_ImmedExecute( - va( - "changeteam %s", - destinationstate - ) - ); - } - else - { - COM_ImmedExecute( - va( - "changeteam%u %s", - pausemenu.splitscreenfocusid + 1, - destinationstate - ) - ); - } + WRITEUINT8(p, splitspecid); + WRITEUINT8(p, joingame); + + SendNetXCmd(XD_SPECTATE, &buf, p - buf); return; } diff --git a/src/p_user.c b/src/p_user.c index 5f5e2947b..478503157 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -4866,10 +4866,11 @@ void P_CheckRaceGriefing(player_t *player, boolean dopunishment) else { // Send spectate - UINT8 buf[1]; + UINT8 buf[2]; UINT8 *p = buf; WRITEUINT8(p, n); + WRITEUINT8(p, 0); SendNetXCmd(XD_SPECTATE, &buf, p - buf); }