# HG changeset patch # User Adam Kaminski # Date 1638112572 18000 # Sun Nov 28 10:16:12 2021 -0500 # Node ID c687969ea3b3ec70abd2f315d78b819d515837b7 # Parent c363af79fb90d1d7b9f79bc82289ff0e71708fc1 - The result value of GAMEEVENT_CHAT event scripts can now be used to determine whether or not the chat message will be displayed. The saved chat message no longer contain color codes either. - The cleaned chat string without color codes is now also sent to bots. diff -r c363af79fb90 -r c687969ea3b3 src/chat.cpp --- a/src/chat.cpp Sun Nov 28 09:38:45 2021 -0500 +++ b/src/chat.cpp Sun Nov 28 10:16:12 2021 -0500 @@ -1056,6 +1056,37 @@ OutString += ChatString; + // [AK] Only save chat messages for non-private chat messages. + if (( ulMode != CHATMODE_PRIVATE_SEND ) && ( ulMode != CHATMODE_PRIVATE_RECEIVE )) + { + // [AK] Remove any color codes that may still be in the chat message. + V_RemoveColorCodes( ChatString ); + + g_SavedChatMessages[ulPlayer].put( ChatString ); + + // [AK] Trigger an event script indicating that a chat message was received. + // If the event returns 0, then don't print the message. + if ( GAMEMODE_HandleEvent( GAMEEVENT_CHAT, NULL, ulPlayer != MAXPLAYERS ? ulPlayer : -1, ulMode - CHATMODE_GLOBAL ) == 0 ) + return; + + BOTCMD_SetLastChatString( ChatString ); + BOTCMD_SetLastChatPlayer( PLAYER_IsValidPlayer( ulPlayer ) ? players[ulPlayer].userinfo.GetName() : "" ); + + for ( ULONG ulIdx = 0; ulIdx < MAXPLAYERS; ulIdx++ ) + { + if ( playeringame[ulIdx] == false ) + continue; + + // Don't tell the bot someone talked if it was it who talked. + if ( ulIdx == ulPlayer ) + continue; + + // If this is a bot, tell it a player said something. + if ( players[ulIdx].pSkullBot ) + players[ulIdx].pSkullBot->PostEvent( BOTEVENT_PLAYER_SAY ); + } + } + Printf( ulChatLevel, "%s\n", OutString.GetChars() ); // [BB] If the user doesn't want to see the messages, they shouldn't make a sound. @@ -1072,32 +1103,6 @@ else if ( sound == 3 ) // Doom 2 S_Sound( CHAN_VOICE | CHAN_UI, "misc/chat", 1, ATTN_NONE ); } - - // [AK] Only save chat messages for non-private chat messages. - if (( ulMode != CHATMODE_PRIVATE_SEND ) && ( ulMode != CHATMODE_PRIVATE_RECEIVE )) - { - g_SavedChatMessages[ulPlayer].put( pszString ); - - // [AK] Trigger an event script indicating that a chat message was received. - GAMEMODE_HandleEvent( GAMEEVENT_CHAT, 0, ulPlayer != MAXPLAYERS ? ulPlayer : -1, ulMode - CHATMODE_GLOBAL ); - - BOTCMD_SetLastChatString( pszString ); - BOTCMD_SetLastChatPlayer( PLAYER_IsValidPlayer( ulPlayer ) ? players[ulPlayer].userinfo.GetName() : "" ); - - for ( ULONG ulIdx = 0; ulIdx < MAXPLAYERS; ulIdx++ ) - { - if ( playeringame[ulIdx] == false ) - continue; - - // Don't tell the bot someone talked if it was it who talked. - if ( ulIdx == ulPlayer ) - continue; - - // If this is a bot, tell it a player said something. - if ( players[ulIdx].pSkullBot ) - players[ulIdx].pSkullBot->PostEvent( BOTEVENT_PLAYER_SAY ); - } - } } //***************************************************************************** diff -r c363af79fb90 -r c687969ea3b3 src/gamemode.cpp --- a/src/gamemode.cpp Sun Nov 28 09:38:45 2021 -0500 +++ b/src/gamemode.cpp Sun Nov 28 10:16:12 2021 -0500 @@ -1092,7 +1092,8 @@ // taking damage to be executed immediately, in case any of the // actor pointers that were responsible for calling the event // become NULL after one tic. - bool bRunNow = ( Event == GAMEEVENT_ACTOR_SPAWNED || Event == GAMEEVENT_ACTOR_DAMAGED ); + // Also allow chat events to be executed immediately. + bool bRunNow = ( Event == GAMEEVENT_ACTOR_SPAWNED || Event == GAMEEVENT_ACTOR_DAMAGED || Event == GAMEEVENT_CHAT ); // [BB] The activator of the event activates the event script. // The first argument is the type, e.g. GAMEEVENT_PLAYERFRAGS, diff -r c363af79fb90 -r c687969ea3b3 src/sv_main.cpp --- a/src/sv_main.cpp Sun Nov 28 09:38:45 2021 -0500 +++ b/src/sv_main.cpp Sun Nov 28 10:16:12 2021 -0500 @@ -1231,11 +1231,18 @@ } else { - SERVERCOMMANDS_PlayerSay( ulPlayer, pszString, ulMode, bForbidChatToPlayers ); - CHAT_AddChatMessage( ulPlayer, pszString ); + // [AK] Remove any color codes that may still be in the chat message. + FString cleanedStringWithoutColor = cleanedChatString; + V_RemoveColorCodes( cleanedStringWithoutColor ); + + CHAT_AddChatMessage( ulPlayer, cleanedStringWithoutColor ); // [AK] Trigger an event script indicating that a chat message was received. - GAMEMODE_HandleEvent( GAMEEVENT_CHAT, 0, ulPlayer != MAXPLAYERS ? ulPlayer : -1, ulMode - CHATMODE_GLOBAL ); + // If the event returns 0, then don't print the message or send it to the clients. + if ( GAMEMODE_HandleEvent( GAMEEVENT_CHAT, NULL, ulPlayer != MAXPLAYERS ? ulPlayer : -1, ulMode - CHATMODE_GLOBAL ) == 0 ) + return; + + SERVERCOMMANDS_PlayerSay( ulPlayer, pszString, ulMode, bForbidChatToPlayers ); } if ( ulMode == CHATMODE_PRIVATE_SEND )