Mentrillum / Slender-Fortress-Modified-Versions

A modification of Team Fortress 2 based on the game Slender: The Eight Pages.
GNU General Public License v3.0
34 stars 23 forks source link

[Bug] Chat Messages #19

Closed MAGNAT2645 closed 3 years ago

MAGNAT2645 commented 3 years ago

Source-Chat-Relay bot reads in-game chat messages (and sends them to Discord) via OnClientSayCommand_Post(). SF2 uses command listeners and calls FakeClientCommand() to send message to team chat. Because of this bot reads and sends one message two times (due to original say "Text" (which are blocked in command listener but not in OnClientSayCommand()) and its duplicate say_team "Text").

I suggest to use OnClientSayCommand() instead of two command listeners (say and say_team) because it should block original message and bot won't see original say message if this message are moved to say_team.

Code Snippet (didn't test):

public void OnClientSayCommand(int client, const char[] command, const char[] sArgs) {
    if ( !g_bPlayerCalledForNightmare[client] )
        g_bPlayerCalledForNightmare[client] = ( StrContains( sArgs, "nightmare", false ) != -1 || StrContains( sArgs, "Nightmare", false ) != -1 );

    if ( !g_bEnabled || g_cvAllChat.BoolValue || SF_IsBoxingMap() ) return Plugin_Continue;

    if ( !IsRoundEnding() ) {
        bool bSayTeam = strcmp( command, "say_team" ) == 0;

        if ( g_bPlayerEliminated[client] ) {
            if ( !IsPlayerAlive( client ) && GetClientTeam( client ) == TFTeam_Red )
                return Plugin_Stop; // Plugin_Stop in this case stops message AND post hook so bot won't see message in OnClientSayCommand_Post()

            char szMessage[256];
            FormatEx( szMessage, sizeof szMessage, "{blue}%N:{default} %s", client, sArgs );
            //Broadcast the msg to the source tv, if the server has one.
            PrintToSourceTV( szMessage );

            if ( !bSayTeam ) {
                FakeClientCommandEx( client, "say_team '%s'", sArgs );
                return Plugin_Stop;
            }
        }

        if ( !bSayTeam ) {
            char szMessage[256];
            FormatEx( szMessage, sizeof szMessage, "{red}%N:{default} %s", client, sArgs );
            //Broadcast the msg to the source tv, if the server has one.
            PrintToSourceTV( szMessage );
        }
    }

    return Plugin_Continue;
}

Also, i'm not sure about escaping text in FakeClientCommandEx( client, "say_team '%s'", sArgs );

Mentrillum commented 3 years ago

Added since then after months