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"
This commit is contained in:
toaster 2024-09-22 17:44:26 +01:00
parent 27f5da1fd5
commit b62892ba1c
3 changed files with 41 additions and 47 deletions

View file

@ -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);
}
if (desired_state != 0)
{
player->pflags |= PF_WANTSTOJOIN;
}
else
{
player->pflags &= ~PF_WANTSTOJOIN;
}
if (gamestate != GS_LEVEL || was_spectator == true)
{

View file

@ -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];
tospectator = (
players[splitspecid].spectator == false
|| (players[splitspecid].pflags & PF_WANTSTOJOIN)
);
}
const UINT8 joingame = (
players[splitspecid].spectator == true
&& ((players[splitspecid].pflags & PF_WANTSTOJOIN) == 0)
) ? 1 : 0;
if (!tospectator && !cv_allowteamchange.value)
if (joingame && !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;
}

View file

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