# HG changeset patch # User Adam Kaminski # Date 1608343150 18000 # Fri Dec 18 20:59:10 2020 -0500 # Node ID a8602c193b2c1f534f1cddc3abba324ddb5fe789 # Parent 33d8c4adc37f99760224701c1493183e142e2efa Added a new EVENT script type: GAMEEVENT_CHAT that triggers when a non-private chat message is sent. Use this in conjunction with the ACS function: GetChatMessage(int player) to get the last chat message received by the player (or the server if -1 is passed). diff -r 33d8c4adc37f -r a8602c193b2c docs/zandronum-history.txt --- a/docs/zandronum-history.txt Fri Dec 18 20:54:27 2020 -0500 +++ b/docs/zandronum-history.txt Fri Dec 18 20:59:10 2020 -0500 @@ -29,6 +29,7 @@ + - Added a new scoreboard icon that displays if a player is lagging to the server. [Kaminsky] + - Added ACS functions: SetPlayerScore(int player, int type, int value) and GetPlayerScore(int player, int type) to get or set the player's score. The type can be either frags, points, wins, deaths, kills, or the item and secret counts. [Kaminsky] + - Added an ACS special to check whether the game is in demo or not [DoomJoshuaBoy/geNia] ++ - Added a new EVENT script type: GAMEEVENT_CHAT that triggers when a non-private chat message is sent. Use this in conjunction with the ACS function: GetChatMessage(int player) to get the last chat message received by the player (or the server if -1 is passed). [Kaminsky] - - Fixed: Bots tries to jump to reach item when sv_nojump is true. [sleep] - - Fixed: ACS function SetSkyScrollSpeed didn't work online. [Edward-san] - - Fixed: color codes in callvote reasons weren't terminated properly. [Dusk] diff -r 33d8c4adc37f -r a8602c193b2c src/chat.cpp --- a/src/chat.cpp Fri Dec 18 20:54:27 2020 -0500 +++ b/src/chat.cpp Fri Dec 18 20:59:10 2020 -0500 @@ -905,13 +905,21 @@ S_Sound( CHAN_VOICE | CHAN_UI, "misc/chat", 1, ATTN_NONE ); } - BOTCMD_SetLastChatString( pszString ); - BOTCMD_SetLastChatPlayer( PLAYER_IsValidPlayer( ulPlayer ) ? players[ulPlayer].userinfo.GetName() : "" ); - + // [AK] Only save chat messages for non-private chat messages. + if (( ulMode != CHATMODE_PRIVATE_SEND ) && ( ulMode != CHATMODE_PRIVATE_RECEIVE )) { - ULONG ulIdx; + if ( ulPlayer == MAXPLAYERS ) + SERVER_SetLastChatMessage( pszString ); + else + players[ulPlayer].LastChatMessage = pszString; - for ( ulIdx = 0; ulIdx < MAXPLAYERS; ulIdx++ ) + // [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; diff -r 33d8c4adc37f -r a8602c193b2c src/cl_main.cpp --- a/src/cl_main.cpp Fri Dec 18 20:54:27 2020 -0500 +++ b/src/cl_main.cpp Fri Dec 18 20:59:10 2020 -0500 @@ -2983,6 +2983,7 @@ pPlayer->ulDeathCount = 0; PLAYER_ResetSpecialCounters ( pPlayer ); pPlayer->bChatting = 0; + pPlayer->LastChatMessage = '\0'; pPlayer->bInConsole = 0; pPlayer->bSpectating = 0; pPlayer->bIgnoreChat = 0; diff -r 33d8c4adc37f -r a8602c193b2c src/d_player.h --- a/src/d_player.h Fri Dec 18 20:54:27 2020 -0500 +++ b/src/d_player.h Fri Dec 18 20:59:10 2020 -0500 @@ -636,6 +636,9 @@ // This player is chatting. bool bChatting; + // [AK] The last chat message we received from this player. + FString LastChatMessage; + // [RC] This player is in the console or menu. bool bInConsole; diff -r 33d8c4adc37f -r a8602c193b2c src/g_game.cpp --- a/src/g_game.cpp Fri Dec 18 20:54:27 2020 -0500 +++ b/src/g_game.cpp Fri Dec 18 20:59:10 2020 -0500 @@ -2083,6 +2083,7 @@ APlayerPawn *actor; const PClass *cls; FString log; + FString LastChatMessage; bool bOnTeam; bool bSpectating; bool bDeadSpectator; @@ -2120,6 +2121,7 @@ bOnTeam = p->bOnTeam; const bool bChatting = p->bChatting; + LastChatMessage = p->LastChatMessage; const bool bInConsole = p->bInConsole; bSpectating = p->bSpectating; bDeadSpectator = p->bDeadSpectator; @@ -2169,6 +2171,7 @@ p->bOnTeam = bOnTeam; p->bChatting = bChatting; + p->LastChatMessage = LastChatMessage; p->bInConsole = bInConsole; p->bSpectating = bSpectating; p->bDeadSpectator = bDeadSpectator; diff -r 33d8c4adc37f -r a8602c193b2c src/gamemode.h --- a/src/gamemode.h Fri Dec 18 20:54:27 2020 -0500 +++ b/src/gamemode.h Fri Dec 18 20:59:10 2020 -0500 @@ -105,6 +105,7 @@ GAMEEVENT_ROUND_STARTS, GAMEEVENT_ROUND_ENDS, GAMEEVENT_ROUND_ABORTED, + GAMEEVENT_CHAT, } GAMEEVENT_e; //***************************************************************************** diff -r 33d8c4adc37f -r a8602c193b2c src/p_acs.cpp --- a/src/p_acs.cpp Fri Dec 18 20:54:27 2020 -0500 +++ b/src/p_acs.cpp Fri Dec 18 20:59:10 2020 -0500 @@ -5209,6 +5209,7 @@ ACSF_SetPlayerScore, ACSF_GetPlayerScore, ACSF_InDemoMode, + ACSF_GetChatMessage, // ZDaemon ACSF_GetTeamScore = 19620, // (int team) @@ -7422,7 +7423,6 @@ case ACSF_GetPlayerScore: { const ULONG ulPlayer = static_cast ( args[0] ); - if ( PLAYER_IsValidPlayer( ulPlayer ) ) { switch ( args[1] ) @@ -7440,6 +7440,23 @@ return 0; } + case ACSF_GetChatMessage: + { + const ULONG ulPlayer = static_cast ( args[0] ); + if ( ulPlayer == -1 ) + { + // [AK] Return the last message sent by the server. + return GlobalACSStrings.AddString( SERVER_GetLastChatMessage() ); + } + else if ( PLAYER_IsValidPlayer( ulPlayer ) ) + { + // [AK] Return the last message we received from this player. + return GlobalACSStrings.AddString( players[ulPlayer].LastChatMessage ); + } + + return GlobalACSStrings.AddString( "" ); + } + case ACSF_GetActorFloorTexture: { auto a = SingleActorFromTID(args[0], activator); diff -r 33d8c4adc37f -r a8602c193b2c src/p_user.cpp --- a/src/p_user.cpp Fri Dec 18 20:54:27 2020 -0500 +++ b/src/p_user.cpp Fri Dec 18 20:59:10 2020 -0500 @@ -495,6 +495,7 @@ ulDeathsWithoutFrag = p.ulDeathsWithoutFrag; ulUnrewardedDamageDealt = p.ulUnrewardedDamageDealt; bChatting = p.bChatting; + LastChatMessage = p.LastChatMessage; bInConsole = p.bInConsole; bSpectating = p.bSpectating; bDeadSpectator = p.bDeadSpectator; diff -r 33d8c4adc37f -r a8602c193b2c src/sv_main.cpp --- a/src/sv_main.cpp Fri Dec 18 20:54:27 2020 -0500 +++ b/src/sv_main.cpp Fri Dec 18 20:59:10 2020 -0500 @@ -230,6 +230,9 @@ // This is the current font the "screen" is using when it displays messages. static char g_szCurrentFont[16]; +// This is the last chat message the server sent using RCON. +static FString g_LastChatMessage; + // This is the music the loaded map is currently using. static FString g_MapMusic; static int g_MapMusicOrder; @@ -1120,11 +1123,24 @@ pszString = cleanedChatString.GetChars(); // [AK] Check if we're sending a private message. - if( ulMode == CHATMODE_PRIVATE_SEND ) + if ( ulMode == CHATMODE_PRIVATE_SEND ) + { SERVERCOMMANDS_PrivateSay( ulPlayer, ulReceiver, pszString, bFordidChatToPlayers ); + } else + { SERVERCOMMANDS_PlayerSay( ulPlayer, pszString, ulMode, bFordidChatToPlayers ); + // [AK] Store the last chat message we received from this player. + if ( ulPlayer == MAXPLAYERS ) + SERVER_SetLastChatMessage( pszString ); + else + players[ulPlayer].LastChatMessage = 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 ); + } + // [AK] Don't log private messages that aren't sent to/from the server. if (( ulMode == CHATMODE_PRIVATE_SEND ) && ( ulPlayer != MAXPLAYERS ) && ( ulReceiver != MAXPLAYERS )) return; @@ -3715,6 +3731,20 @@ //***************************************************************************** // +FString SERVER_GetLastChatMessage( void ) +{ + return ( g_LastChatMessage ); +} + +//***************************************************************************** +// +void SERVER_SetLastChatMessage( const char *pszMessage ) +{ + g_LastChatMessage = pszMessage; +} + +//***************************************************************************** +// LONG SERVER_AdjustDoorDirection( LONG lDirection ) { // Not a valid door direction. diff -r 33d8c4adc37f -r a8602c193b2c src/sv_main.h --- a/src/sv_main.h Fri Dec 18 20:54:27 2020 -0500 +++ b/src/sv_main.h Fri Dec 18 20:59:10 2020 -0500 @@ -487,6 +487,8 @@ bool SERVER_IsPlayerAllowedToKnowHealth( ULONG ulPlayer, ULONG ulPlayer2 ); const char *SERVER_GetCurrentFont( void ); void SERVER_SetCurrentFont( const char *pszFont ); +FString SERVER_GetLastChatMessage( void ); +void SERVER_SetLastChatMessage( const char *pszMessage ); LONG SERVER_AdjustDoorDirection( LONG lDirection ); LONG SERVER_AdjustFloorDirection( LONG lDirection ); LONG SERVER_AdjustCeilingDirection( LONG lDirection );