# HG changeset patch # User Adam Kaminski # Date 1636261589 14400 # Sun Nov 07 01:06:29 2021 -0400 # Node ID 5e47c4262ad881a1ff9265f1f1b5ad8762e7269d # Parent c7051c731c8ac526d4f1be90c8b053639b1e7a77 Replaced sv_noprivatechat with sv_allowprivatechat, which adds a third option to limit private messaging to teammates only. diff -r c7051c731c8a -r 5e47c4262ad8 src/chat.cpp --- a/src/chat.cpp Sun Nov 07 00:37:08 2021 -0400 +++ b/src/chat.cpp Sun Nov 07 01:06:29 2021 -0400 @@ -557,10 +557,13 @@ g_ulChatTicker = 0; // [AK] If we're typing a chat message to another player, we must constantly check if - // they're in the game. If not, cancel the message entirely. + // they're still valid, or if the server disabled private messaging. if ( g_ulChatMode == CHATMODE_PRIVATE_SEND ) { - if (( g_ulChatPlayer != MAXPLAYERS ) && ( chat_IsPlayerValidReceiver( g_ulChatPlayer ) == false )) + if ( sv_allowprivatechat == PRIVATECHAT_OFF ) + CHAT_SetChatMode( CHATMODE_NONE ); + + if ( chat_IsPlayerValidReceiver( g_ulChatPlayer ) == false ) CHAT_SetChatMode( CHATMODE_NONE ); } } @@ -663,7 +666,7 @@ else if ( tempPlayer > MAXPLAYERS ) tempPlayer = 0; - if (( tempPlayer == MAXPLAYERS ) || ( tempPlayer == g_ulChatPlayer )) + if ( tempPlayer == g_ulChatPlayer ) break; } while ( chat_IsPlayerValidReceiver( tempPlayer ) == false ); @@ -1098,6 +1101,33 @@ } //***************************************************************************** +// +bool CHAT_CanPrivateChatToTeammatesOnly( void ) +{ + return (( sv_allowprivatechat == PRIVATECHAT_TEAMMATESONLY ) && ( GAMEMODE_GetCurrentFlags( ) & GMF_PLAYERSONTEAMS )); +} + +//***************************************************************************** +// +bool CHAT_CanSendPrivateChatToTeammate( ULONG ulSender, ULONG ulReceiver ) +{ + // [AK] If we're not restricted to sending private messages to only teammates, then we + // can send private messages to anyone including this player. + if ( CHAT_CanPrivateChatToTeammatesOnly( ) == false ) + return true; + + // [AK] True spectators are still allowed to send private messages to other true spectators. + if (( PLAYER_IsTrueSpectator( &players[ulSender] )) && ( PLAYER_IsTrueSpectator( &players[ulReceiver] ))) + return true; + + // [AK] In-game players are only allowed to send private messages to their teammates. + if (( ulReceiver < MAXPLAYERS ) && ( players[ulSender].mo != NULL )) + return players[ulSender].mo->IsTeammate( players[ulReceiver].mo ); + + return false; +} + +//***************************************************************************** //***************************************************************************** // void chat_SendMessage( ULONG ulMode, const char *pszString ) @@ -1401,15 +1431,20 @@ // bool chat_IsPlayerValidReceiver( ULONG ulPlayer ) { - // [AK] If the player doesn't exist, they can't be a receiver. - if ( PLAYER_IsValidPlayer( ulPlayer ) == false ) - return false; + if ( ulPlayer != MAXPLAYERS ) + { + // [AK] If the player doesn't exist, they can't be a receiver. + if ( PLAYER_IsValidPlayer( ulPlayer ) == false ) + return false; - // [AK] The receiver can't be ourselves or a bot. - if (( ulPlayer == static_cast( consoleplayer )) || ( players[ulPlayer].bIsBot )) - return false; + // [AK] The receiver can't be ourselves or a bot. + if (( ulPlayer == static_cast( consoleplayer )) || ( players[ulPlayer].bIsBot )) + return false; + } - return true; + // [AK] If we're only allowed to send private messages to teammates, then make + // sure this player is a teammate of ours. + return CHAT_CanSendPrivateChatToTeammate( consoleplayer, ulPlayer ); } //***************************************************************************** @@ -1418,11 +1453,7 @@ // bool chat_FindValidReceiver( void ) { - // [AK] We can always send private messages to the server. - if ( g_ulChatPlayer == MAXPLAYERS ) - return true; - - if ( SERVER_CountPlayers( false ) >= 2 ) + if (( g_ulChatPlayer == MAXPLAYERS ) || ( SERVER_CountPlayers( false ) >= 2 )) { // [AK] If we're trying to send a message to an invalid player, find another one. if ( chat_IsPlayerValidReceiver( g_ulChatPlayer ) == false ) @@ -1432,7 +1463,7 @@ do { // [AK] Keep looping until we find another player who we can send a message to. - if ( ++g_ulChatPlayer >= MAXPLAYERS ) + if ( ++g_ulChatPlayer > MAXPLAYERS ) g_ulChatPlayer = 0; // [AK] If we're back to the old value for some reason, then there's no other @@ -1478,7 +1509,7 @@ } // [AK] No sending private messages if the server has disabled them. - if ( zadmflags & ZADF_NO_PRIVATE_CHAT ) + if ( sv_allowprivatechat == PRIVATECHAT_OFF ) { Printf( "Private messages have been disabled by the server.\n" ); return; @@ -1517,6 +1548,13 @@ } } + // [AK] Check if we're only allowed to send private messages to our teammates. + if (( NETWORK_GetState( ) != NETSTATE_SERVER ) && ( CHAT_CanSendPrivateChatToTeammate( consoleplayer, ulReceiver ) == false )) + { + Printf( "You can only send private messages to teammates.\n" ); + return; + } + g_ulChatPlayer = ulReceiver; if ( argv.argc( ) > 2 ) @@ -1538,9 +1576,9 @@ if ( NETWORK_GetState( ) != NETSTATE_SERVER ) { // [AK] Find a valid receiver, if necessary. - if (( bServerSelected == false ) && ( chat_FindValidReceiver( ) == false )) + if ( chat_FindValidReceiver( ) == false ) { - Printf( "There's nobody to send private messages to. Use \"sayto server\" or \"sayto_idx -1\" to message the host instead.\n" ); + Printf( "There's no valid player to send private messages to.\n" ); return; } @@ -1816,7 +1854,7 @@ if ( NETWORK_GetState( ) != NETSTATE_SERVER ) { // [AK] No sending private messages if the server has disabled them. - if ( zadmflags & ZADF_NO_PRIVATE_CHAT ) + if ( sv_allowprivatechat == PRIVATECHAT_OFF ) { Printf( "Private messages have been disabled by the server.\n" ); return; @@ -1825,7 +1863,7 @@ // [AK] Find a valid receiver, if necessary. if ( chat_FindValidReceiver( ) == false ) { - Printf( "There's nobody to send private messages to. Use \"sayto server\" or \"sayto_idx -1\" to message the host instead.\n" ); + Printf( "There's no valid player to send private messages to.\n" ); return; } diff -r c7051c731c8a -r 5e47c4262ad8 src/chat.h --- a/src/chat.h Sun Nov 07 00:37:08 2021 -0400 +++ b/src/chat.h Sun Nov 07 01:06:29 2021 -0400 @@ -78,6 +78,15 @@ } CHATMODE_e; //***************************************************************************** +typedef enum +{ + PRIVATECHAT_OFF, + PRIVATECHAT_EVERYONE, + PRIVATECHAT_TEAMMATESONLY, + +} PRIVATECHAT_e; + +//***************************************************************************** // PROTOTYPES void CHAT_Construct( void ); @@ -92,6 +101,8 @@ void CHAT_ClearChatMessages( ULONG ulPlayer ); // [AK] void CHAT_SerializeMessages( FArchive &arc ); // [AK] void CHAT_PrintChatString( ULONG ulPlayer, ULONG ulMode, const char *pszString ); +bool CHAT_CanPrivateChatToTeammatesOnly( void ); +bool CHAT_CanSendPrivateChatToTeammate( ULONG ulSender, ULONG ulReceiver ); //***************************************************************************** // EXTERNAL CONSOLE VARIABLES diff -r c7051c731c8a -r 5e47c4262ad8 src/cl_main.cpp --- a/src/cl_main.cpp Sun Nov 07 00:37:08 2021 -0400 +++ b/src/cl_main.cpp Sun Nov 07 01:06:29 2021 -0400 @@ -5907,6 +5907,10 @@ // [TP] Yea. Value.Bool = !!pByteStream->ReadByte(); sv_limitcommands.ForceSet( Value, CVAR_Bool ); + + // [AK] Read in, and set the value for sv_allowprivatechat. + Value.Int = pByteStream->ReadByte(); + sv_allowprivatechat.ForceSet( Value, CVAR_Bool ); } //***************************************************************************** diff -r c7051c731c8a -r 5e47c4262ad8 src/d_main.cpp --- a/src/d_main.cpp Sun Nov 07 00:37:08 2021 -0400 +++ b/src/d_main.cpp Sun Nov 07 01:06:29 2021 -0400 @@ -592,10 +592,6 @@ if (( self ^ self.GetPastValue() ) & ZADF_FORCE_SOFTWARE_PITCH_LIMITS ) P_ResetPlayerPitchLimits(); - // [AK] If we disabled private messaging, make sure the client isn't still trying to send one. - if (( self & ZADF_NO_PRIVATE_CHAT ) && ( CHAT_GetChatMode() == CHATMODE_PRIVATE_SEND )) - CHAT_SetChatMode( CHATMODE_NONE ); - // [BB] If we're the server, tell clients that the dmflags changed. // [AK] Moved everything into a separate function to avoid code duplication. SERVER_FlagsetChanged( self ); @@ -631,7 +627,6 @@ CVAR (Flag, sv_nounlaggedbfgtracers, zadmflags, ZADF_NOUNLAGGED_BFG_TRACERS); CVAR (Flag, sv_nodoorclose, zadmflags, ZADF_NODOORCLOSE); CVAR (Flag, sv_forcesoftwarepitchlimits, zadmflags, ZADF_FORCE_SOFTWARE_PITCH_LIMITS); -CVAR (Flag, sv_noprivatechat, zadmflags, ZADF_NO_PRIVATE_CHAT); CVAR (Flag, sv_shootthroughallies, zadmflags, ZADF_SHOOT_THROUGH_ALLIES); CVAR (Flag, sv_dontpushallies, zadmflags, ZADF_DONT_PUSH_ALLIES); diff -r c7051c731c8a -r 5e47c4262ad8 src/doomdef.h --- a/src/doomdef.h Sun Nov 07 00:37:08 2021 -0400 +++ b/src/doomdef.h Sun Nov 07 01:06:29 2021 -0400 @@ -384,14 +384,11 @@ // [AK] Forces the player's pitch to be limited to what's allowed in the software renderer. ZADF_FORCE_SOFTWARE_PITCH_LIMITS = 1 << 20, - // [AK] No private messaging allowed on the server. - ZADF_NO_PRIVATE_CHAT = 1 << 21, - // [AK] Allows players to fire hitscans and projectiles through teammates. - ZADF_SHOOT_THROUGH_ALLIES = 1 << 22, + ZADF_SHOOT_THROUGH_ALLIES = 1 << 21, // [AK] Players aren't pushed by attacks caused by their teammates (e.g. BFG tracers). - ZADF_DONT_PUSH_ALLIES = 1 << 23, + ZADF_DONT_PUSH_ALLIES = 1 << 22, }; // [RH] Compatibility flags. diff -r c7051c731c8a -r 5e47c4262ad8 src/sv_commands.cpp --- a/src/sv_commands.cpp Sun Nov 07 00:37:08 2021 -0400 +++ b/src/sv_commands.cpp Sun Nov 07 01:06:29 2021 -0400 @@ -2339,6 +2339,8 @@ command.addString( lobby ); // [TP] Send sv_limitcommands command.addByte( sv_limitcommands ); + // [AK] Send sv_allowprivatechat. + command.addByte( sv_allowprivatechat ); command.sendCommandToClients( ulPlayerExtra, flags ); } diff -r c7051c731c8a -r 5e47c4262ad8 src/sv_main.cpp --- a/src/sv_main.cpp Sun Nov 07 00:37:08 2021 -0400 +++ b/src/sv_main.cpp Sun Nov 07 01:06:29 2021 -0400 @@ -432,6 +432,29 @@ } //***************************************************************************** +// +CUSTOM_CVAR( Int, sv_allowprivatechat, PRIVATECHAT_EVERYONE, CVAR_ARCHIVE | CVAR_NOSETBYACS | CVAR_SERVERINFO ) +{ + if ( self < PRIVATECHAT_OFF ) + { + self = PRIVATECHAT_OFF; + return; + } + else if ( self > PRIVATECHAT_TEAMMATESONLY ) + { + self = PRIVATECHAT_TEAMMATESONLY; + return; + } + + // [AK] Notify the clients about the change. + if (( NETWORK_GetState( ) == NETSTATE_SERVER ) && ( gamestate != GS_STARTUP )) + { + SERVER_Printf( "%s changed to: %d\n", self.GetName( ), self.GetGenericRep( CVAR_Int ).Int ); + SERVERCOMMANDS_SetGameModeLimits( ); + } +} + +//***************************************************************************** // FUNCTIONS void SERVER_Construct( void ) @@ -5622,7 +5645,7 @@ if ( ulChatMode == CHATMODE_PRIVATE_SEND ) { // [AK] Don't send the message if we disabled private messaging. - if ( zadmflags & ZADF_NO_PRIVATE_CHAT ) + if ( sv_allowprivatechat == PRIVATECHAT_OFF ) { SERVER_PrintfPlayer( ulPlayer, "Private messages have been disabled by the server.\n" ); return ( false ); @@ -5641,6 +5664,14 @@ SERVER_PrintfPlayer( ulPlayer, "You can't send a private message to this player.\n" ); return ( false ); } + + // [AK] If the client is only allowed to send private messages to teammates, make sure + // the receiver is a teammate of theirs. + if ( CHAT_CanSendPrivateChatToTeammate( ulPlayer, ulReceiver ) == false ) + { + SERVER_PrintfPlayer( ulPlayer, "You can only send private messages to teammates.\n" ); + return ( false ); + } } // [BB] If the client is flooding the server with commands, the client is diff -r c7051c731c8a -r 5e47c4262ad8 src/sv_main.h --- a/src/sv_main.h Sun Nov 07 00:37:08 2021 -0400 +++ b/src/sv_main.h Sun Nov 07 01:06:29 2021 -0400 @@ -699,6 +699,7 @@ EXTERN_CVAR( Bool, sv_limitcommands ) EXTERN_CVAR( Bool, sv_smoothplayers ) EXTERN_CVAR( Int, sv_extrapolatetics ) +EXTERN_CVAR( Int, sv_allowprivatechat ) // From sv_master.cpp EXTERN_CVAR( Bool, sv_updatemaster ); diff -r c7051c731c8a -r 5e47c4262ad8 wadsrc/static/menudef.txt --- a/wadsrc/static/menudef.txt Sun Nov 07 00:37:08 2021 -0400 +++ b/wadsrc/static/menudef.txt Sun Nov 07 01:06:29 2021 -0400 @@ -1312,7 +1312,6 @@ Option "Force translucency", "sv_forcealpha", "YesNo" Option "Full blood brightness", "sv_maxbloodscalar", "YesNo" Option "Force software pitch limits", "sv_forcesoftwarepitchlimits", "YesNo" - Option "Allow private chat", "sv_noprivatechat", "NoYes" Option "Shoot through allies", "sv_shootthroughallies", "YesNo" Option "Attacks push allies", "sv_dontpushallies", "NoYes" // [TP] -- diff -r c7051c731c8a -r 5e47c4262ad8 wadsrc/static/menudef.za --- a/wadsrc/static/menudef.za Sun Nov 07 00:37:08 2021 -0400 +++ b/wadsrc/static/menudef.za Sun Nov 07 01:06:29 2021 -0400 @@ -560,6 +560,13 @@ // // ================================================================================================= +OptionValue ZA_AllowPrivateChat +{ + 0, "Never" + 1, "Everyone" + 2, "Teammates only" +} + OptionMenu ZA_ServerSetupMenu { RequiresRconAccess @@ -580,6 +587,7 @@ TextField "Join password", "sv_joinpassword", "sv_forcejoinpassword" Option "Require login to join", "sv_forcelogintojoin", "YesNo" StaticText " " + Option "Allow private chat", "sv_allowprivatechat", "ZA_AllowPrivateChat" Option "Smooth lagging players", "sv_smoothplayers", "YesNo" Slider "Extrapolation tics", "sv_extrapolatetics", 1, 35, 1 Slider "Backtrace limit (mu)", "sv_backtracelimit", 0.0, 64.0, 8.0