Add per-player mute

This commit is contained in:
Hanicef 2024-02-27 10:58:59 +00:00 committed by sphere
parent 553240f7c2
commit bfd6dbefe6
6 changed files with 117 additions and 12 deletions

View file

@ -603,6 +603,7 @@ typedef struct player_s
boolean spectator; boolean spectator;
boolean outofcoop; boolean outofcoop;
boolean removing; boolean removing;
boolean muted;
UINT8 bot; UINT8 bot;
struct player_s *botleader; struct player_s *botleader;
UINT16 lastbuttons; UINT16 lastbuttons;

View file

@ -465,9 +465,12 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags)
numwords = COM_Argc() - usedargs; numwords = COM_Argc() - usedargs;
I_Assert(numwords > 0); I_Assert(numwords > 0);
if (CHAT_MUTE) // TODO: Per Player mute. if (CHAT_MUTE)
{ {
HU_AddChatText(va("%s>ERROR: The chat is muted. You can't say anything.", "\x85"), false); if (cv_mute.value)
HU_AddChatText(va("%s>ERROR: The chat is muted. You can't say anything.", "\x85"), false);
else
HU_AddChatText(va("%s>ERROR: You have been muted. You can't say anything.", "\x85"), false);
return; return;
} }
@ -644,9 +647,9 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum)
msg = (char *)*p; msg = (char *)*p;
SKIPSTRINGL(*p, HU_MAXMSGLEN + 1); SKIPSTRINGL(*p, HU_MAXMSGLEN + 1);
if ((cv_mute.value || flags & (HU_CSAY|HU_SERVER_SAY)) && playernum != serverplayer && !(IsPlayerAdmin(playernum))) if ((cv_mute.value || players[playernum].muted || flags & (HU_CSAY|HU_SERVER_SAY)) && playernum != serverplayer && !(IsPlayerAdmin(playernum)))
{ {
CONS_Alert(CONS_WARNING, cv_mute.value ? CONS_Alert(CONS_WARNING, (cv_mute.value || players[playernum].muted) ?
M_GetText("Illegal say command received from %s while muted\n") : M_GetText("Illegal csay command received from non-admin %s\n"), M_GetText("Illegal say command received from %s while muted\n") : M_GetText("Illegal csay command received from non-admin %s\n"),
player_names[playernum]); player_names[playernum]);
if (server) if (server)
@ -962,7 +965,10 @@ static void HU_sendChatMessage(void)
// last minute mute check // last minute mute check
if (CHAT_MUTE) if (CHAT_MUTE)
{ {
HU_AddChatText(va("%s>ERROR: The chat is muted. You can't say anything.", "\x85"), false); if (cv_mute.value)
HU_AddChatText(va("%s>ERROR: The chat is muted. You can't say anything.", "\x85"), false);
else
HU_AddChatText(va("%s>ERROR: You have been muted. You can't say anything.", "\x85"), false);
return; return;
} }
@ -1567,7 +1573,6 @@ static void HU_DrawChat(void)
INT32 cflag = 0; INT32 cflag = 0;
const char *ntalk = "Say: ", *ttalk = "Team: "; const char *ntalk = "Say: ", *ttalk = "Team: ";
const char *talk = ntalk; const char *talk = ntalk;
const char *mute = "Chat has been muted.";
#ifdef NETSPLITSCREEN #ifdef NETSPLITSCREEN
if (splitscreen) if (splitscreen)
@ -1594,7 +1599,10 @@ static void HU_DrawChat(void)
if (CHAT_MUTE) if (CHAT_MUTE)
{ {
talk = mute; if (cv_mute.value)
talk = "Chat has been muted.";
else
talk = "You have been muted.";
typelines = 1; typelines = 1;
cflag = V_GRAYMAP; // set text in gray if chat is muted. cflag = V_GRAYMAP; // set text in gray if chat is muted.
} }

View file

@ -69,8 +69,8 @@ typedef struct
#else #else
#define OLDCHAT (cv_consolechat.value == 1 || dedicated || vid.width < 640 || splitscreen) #define OLDCHAT (cv_consolechat.value == 1 || dedicated || vid.width < 640 || splitscreen)
#endif #endif
#define CHAT_MUTE (cv_mute.value && !(server || IsPlayerAdmin(consoleplayer))) // this still allows to open the chat but not to type. That's used for scrolling and whatnot. #define CHAT_MUTE ((cv_mute.value || players[consoleplayer].muted) && !(server || IsPlayerAdmin(consoleplayer))) // this still allows to open the chat but not to type. That's used for scrolling and whatnot.
#define OLD_MUTE (OLDCHAT && cv_mute.value && !(server || IsPlayerAdmin(consoleplayer))) // this is used to prevent oldchat from opening when muted. #define OLD_MUTE (OLDCHAT && (cv_mute.value || players[consoleplayer].muted) && !(server || IsPlayerAdmin(consoleplayer))) // this is used to prevent oldchat from opening when muted.
// some functions // some functions
void HU_AddChatText(const char *text, boolean playsound); void HU_AddChatText(const char *text, boolean playsound);

View file

@ -149,6 +149,10 @@ static void Command_Teamchange_f(void);
static void Command_Teamchange2_f(void); static void Command_Teamchange2_f(void);
static void Command_ServerTeamChange_f(void); static void Command_ServerTeamChange_f(void);
static void Command_MutePlayer_f(void);
static void Command_UnmutePlayer_f(void);
static void Got_MutePlayer(UINT8 **cp, INT32 playernum);
static void Command_Clearscores_f(void); static void Command_Clearscores_f(void);
// Remote Administration // Remote Administration
@ -488,6 +492,10 @@ void D_RegisterServerCommands(void)
RegisterNetXCmd(XD_TEAMCHANGE, Got_Teamchange); RegisterNetXCmd(XD_TEAMCHANGE, Got_Teamchange);
COM_AddCommand("serverchangeteam", Command_ServerTeamChange_f, COM_LUA); COM_AddCommand("serverchangeteam", Command_ServerTeamChange_f, COM_LUA);
RegisterNetXCmd(XD_MUTEPLAYER, Got_MutePlayer);
COM_AddCommand("muteplayer", Command_MutePlayer_f, COM_LUA);
COM_AddCommand("unmuteplayer", Command_UnmutePlayer_f, COM_LUA);
RegisterNetXCmd(XD_CLEARSCORES, Got_Clearscores); RegisterNetXCmd(XD_CLEARSCORES, Got_Clearscores);
COM_AddCommand("clearscores", Command_Clearscores_f, COM_LUA); COM_AddCommand("clearscores", Command_Clearscores_f, COM_LUA);
COM_AddCommand("map", Command_Map_f, COM_LUA); COM_AddCommand("map", Command_Map_f, COM_LUA);
@ -1315,7 +1323,7 @@ static void SendNameAndColor(void)
CV_StealthSet(&cv_playername, player_names[consoleplayer]); CV_StealthSet(&cv_playername, player_names[consoleplayer]);
HU_AddChatText("\x85*You must wait to change your name again", false); HU_AddChatText("\x85*You must wait to change your name again", false);
} }
else if (cv_mute.value && !(server || IsPlayerAdmin(consoleplayer))) else if ((cv_mute.value || players[consoleplayer].muted) && !(server || IsPlayerAdmin(consoleplayer)))
CV_StealthSet(&cv_playername, player_names[consoleplayer]); CV_StealthSet(&cv_playername, player_names[consoleplayer]);
else // Cleanup name if changing it else // Cleanup name if changing it
CleanupPlayerName(consoleplayer, cv_playername.zstring); CleanupPlayerName(consoleplayer, cv_playername.zstring);
@ -2490,6 +2498,91 @@ static void Command_Teamchange2_f(void)
SendNetXCmd2(XD_TEAMCHANGE, &usvalue, sizeof(usvalue)); SendNetXCmd2(XD_TEAMCHANGE, &usvalue, sizeof(usvalue));
} }
static void MutePlayer(boolean mute)
{
UINT8 data[2];
if (!(server || (IsPlayerAdmin(consoleplayer))))
{
CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n"));
return;
}
if (COM_Argc() < 2)
{
CONS_Printf(M_GetText("muteplayer <playernum>: mute a player\n"));
return;
}
data[0] = atoi(COM_Argv(1));
if (data[0] >= MAXPLAYERS || !playeringame[data[0]])
{
CONS_Alert(CONS_NOTICE, M_GetText("There is no player %u!\n"), (unsigned int)data[0]);
return;
}
if (players[data[0]].muted && mute)
{
CONS_Printf(M_GetText("%s is already muted!\n"), player_names[data[0]]);
return;
}
else if (!players[data[0]].muted && !mute)
{
CONS_Printf(M_GetText("%s is not muted!\n"), player_names[data[0]]);
return;
}
data[1] = mute;
SendNetXCmd(XD_MUTEPLAYER, &data, sizeof(data));
}
static void Command_MutePlayer_f(void)
{
MutePlayer(true);
}
static void Command_UnmutePlayer_f(void)
{
MutePlayer(false);
}
static void Got_MutePlayer(UINT8 **cp, INT32 playernum)
{
UINT8 player = READUINT8(*cp);
UINT8 muted = READUINT8(*cp);
if (playernum != serverplayer && !IsPlayerAdmin(playernum))
{
CONS_Alert(CONS_WARNING, M_GetText("Illegal mute received from player %s\n"), player_names[playernum]);
if (server)
SendKick(playernum, KICK_MSG_CON_FAIL | KICK_MSG_KEEP_BODY);
return;
}
if (player >= MAXPLAYERS || !playeringame[player])
{
CONS_Alert(CONS_WARNING, M_GetText("Illegal mute received from player %s\n"), player_names[playernum]);
if (server)
SendKick(playernum, KICK_MSG_CON_FAIL | KICK_MSG_KEEP_BODY);
return;
}
if (!players[player].muted && muted)
{
if (player == consoleplayer)
CONS_Printf(M_GetText("You have been muted.\n"));
else
CONS_Printf(M_GetText("%s has been muted.\n"), player_names[player]);
}
else if (players[player].muted && !muted)
{
if (player == consoleplayer)
CONS_Printf(M_GetText("You are no longer muted.\n"));
else
CONS_Printf(M_GetText("%s is no longer muted.\n"), player_names[player]);
}
players[player].muted = muted;
}
static void Command_ServerTeamChange_f(void) static void Command_ServerTeamChange_f(void)
{ {
changeteam_union NetPacket; changeteam_union NetPacket;
@ -4787,7 +4880,7 @@ static void ForceSkin_OnChange(void)
//Allows the player's name to be changed if cv_mute is off. //Allows the player's name to be changed if cv_mute is off.
static void Name_OnChange(void) static void Name_OnChange(void)
{ {
if (cv_mute.value && !(server || IsPlayerAdmin(consoleplayer))) if ((cv_mute.value || players[consoleplayer].muted) && !(server || IsPlayerAdmin(consoleplayer)))
{ {
CONS_Alert(CONS_NOTICE, M_GetText("You may not change your name when chat is muted.\n")); CONS_Alert(CONS_NOTICE, M_GetText("You may not change your name when chat is muted.\n"));
CV_StealthSet(&cv_playername, player_names[consoleplayer]); CV_StealthSet(&cv_playername, player_names[consoleplayer]);
@ -4798,7 +4891,7 @@ static void Name_OnChange(void)
static void Name2_OnChange(void) static void Name2_OnChange(void)
{ {
if (cv_mute.value) //Secondary player can't be admin. if (cv_mute.value || players[consoleplayer].muted) //Secondary player can't be admin.
{ {
CONS_Alert(CONS_NOTICE, M_GetText("You may not change your name when chat is muted.\n")); CONS_Alert(CONS_NOTICE, M_GetText("You may not change your name when chat is muted.\n"));
CV_StealthSet(&cv_playername2, player_names[secondarydisplayplayer]); CV_StealthSet(&cv_playername2, player_names[secondarydisplayplayer]);

View file

@ -147,6 +147,7 @@ typedef enum
XD_LUACMD, // 22 XD_LUACMD, // 22
XD_LUAVAR, // 23 XD_LUAVAR, // 23
XD_LUAFILE, // 24 XD_LUAFILE, // 24
XD_MUTEPLAYER, // 25
MAXNETXCMD MAXNETXCMD
} netxcmd_t; } netxcmd_t;

View file

@ -170,6 +170,7 @@ static void P_NetArchivePlayers(void)
WRITEUINT8(save_p, players[i].panim); WRITEUINT8(save_p, players[i].panim);
WRITEUINT8(save_p, players[i].stronganim); WRITEUINT8(save_p, players[i].stronganim);
WRITEUINT8(save_p, players[i].spectator); WRITEUINT8(save_p, players[i].spectator);
WRITEUINT8(save_p, players[i].muted);
WRITEUINT16(save_p, players[i].flashpal); WRITEUINT16(save_p, players[i].flashpal);
WRITEUINT16(save_p, players[i].flashcount); WRITEUINT16(save_p, players[i].flashcount);
@ -399,6 +400,7 @@ static void P_NetUnArchivePlayers(void)
players[i].panim = READUINT8(save_p); players[i].panim = READUINT8(save_p);
players[i].stronganim = READUINT8(save_p); players[i].stronganim = READUINT8(save_p);
players[i].spectator = READUINT8(save_p); players[i].spectator = READUINT8(save_p);
players[i].muted = READUINT8(save_p);
players[i].flashpal = READUINT16(save_p); players[i].flashpal = READUINT16(save_p);
players[i].flashcount = READUINT16(save_p); players[i].flashcount = READUINT16(save_p);