From e5428a3c270b6c9d0bf8c19b11f855a502d83a50 Mon Sep 17 00:00:00 2001 From: Peace-Maker Date: Fri, 23 Aug 2013 07:31:04 -0400 Subject: [PATCH] Fixed crash in OnSayCommand_Post with console chat, pass console chat (bug 5864, r=kyles). --- core/ChatTriggers.cpp | 46 +++++++++++++++++++++++++++---------------- core/ChatTriggers.h | 1 + 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/core/ChatTriggers.cpp b/core/ChatTriggers.cpp index fba3d264..73436bbb 100644 --- a/core/ChatTriggers.cpp +++ b/core/ChatTriggers.cpp @@ -208,9 +208,27 @@ void ChatTriggers::OnSayCommand_Pre() m_bWasFloodedMessage = false; m_bPluginIgnored = false; + const char *args = command.ArgS(); + + if (!args) + { + RETURN_META(MRES_IGNORED); + } + + /* Save these off for post hook as the command data returned from the engine in older engine versions + * can be NULL, despite the data still being there and valid. */ + m_Arg0Backup = command.Arg(0); + m_ArgSBackup = command.ArgS(); + /* The server console cannot do this */ if (client == 0) { + cell_t res = CallOnClientSayCommand(client); + if (res >= Pl_Handled) + { + m_bPluginIgnored = (res >= Pl_Stop); + RETURN_META(MRES_SUPERCEDE); + } RETURN_META(MRES_IGNORED); } @@ -222,13 +240,6 @@ void ChatTriggers::OnSayCommand_Pre() RETURN_META(MRES_IGNORED); } - const char *args = command.ArgS(); - - if (!args) - { - RETURN_META(MRES_IGNORED); - } - /* Check if we need to block this message from being sent */ if (ClientIsFlooding(client)) { @@ -256,11 +267,6 @@ void ChatTriggers::OnSayCommand_Pre() is_quoted = true; } - /* Save these off for post hook as the command data returned from the engine in older engine versions - * can be NULL, despite the data still being there and valid. */ - m_Arg0Backup = command.Arg(0); - m_ArgSBackup = command.ArgS(); - #if SOURCE_ENGINE == SE_EPISODEONE if (m_bIsINS && strcmp(m_Arg0Backup, "say2") == 0 && strlen(args) >= 4) { @@ -300,11 +306,7 @@ void ChatTriggers::OnSayCommand_Pre() if (m_pOnClientSayCmd->GetFunctionCount() != 0) { - cell_t res = Pl_Continue; - m_pOnClientSayCmd->PushCell(client); - m_pOnClientSayCmd->PushString(m_Arg0Backup); - m_pOnClientSayCmd->PushString(m_ArgSBackup); - m_pOnClientSayCmd->Execute(&res); + cell_t res = CallOnClientSayCommand(client); if (res >= Pl_Handled) { @@ -438,6 +440,16 @@ bool ChatTriggers::PreProcessTrigger(edict_t *pEdict, const char *args, bool is_ return true; } +cell_t ChatTriggers::CallOnClientSayCommand(int client) +{ + cell_t res = Pl_Continue; + m_pOnClientSayCmd->PushCell(client); + m_pOnClientSayCmd->PushString(m_Arg0Backup); + m_pOnClientSayCmd->PushString(m_ArgSBackup); + m_pOnClientSayCmd->Execute(&res); + return res; +} + unsigned int ChatTriggers::SetReplyTo(unsigned int reply) { unsigned int old = m_ReplyTo; diff --git a/core/ChatTriggers.h b/core/ChatTriggers.h index f2247ea9..7cff14c9 100644 --- a/core/ChatTriggers.h +++ b/core/ChatTriggers.h @@ -72,6 +72,7 @@ public: private: bool PreProcessTrigger(edict_t *pEdict, const char *args, bool is_quoted); bool ClientIsFlooding(int client); + cell_t CallOnClientSayCommand(int client); private: ConCommand *m_pSayCmd; ConCommand *m_pSayTeamCmd;