From 86f0a77e7350afe682cee216c0f4fb8aa13ce465 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 5 Sep 2015 21:55:41 -0700 Subject: [PATCH] Reduce dependence on sm_strdup. --- core/ChatTriggers.cpp | 26 ++++++++------------------ core/ChatTriggers.h | 9 ++++----- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/core/ChatTriggers.cpp b/core/ChatTriggers.cpp index 76022a86..2e21a8e9 100644 --- a/core/ChatTriggers.cpp +++ b/core/ChatTriggers.cpp @@ -60,10 +60,8 @@ bool g_bSupressSilentFails = false; ChatTriggers::ChatTriggers() : m_pSayCmd(NULL), m_bWillProcessInPost(false), m_ReplyTo(SM_REPLY_CONSOLE), m_ArgSBackup(NULL) { - m_PubTrigger = sm_strdup("!"); - m_PrivTrigger = sm_strdup("/"); - m_PubTriggerSize = 1; - m_PrivTriggerSize = 1; + m_PubTrigger = "!"; + m_PrivTrigger = "/"; m_bIsChatTrigger = false; m_bPluginIgnored = true; #if SOURCE_ENGINE == SE_EPISODEONE @@ -73,10 +71,6 @@ ChatTriggers::ChatTriggers() : m_pSayCmd(NULL), m_bWillProcessInPost(false), ChatTriggers::~ChatTriggers() { - delete [] m_PubTrigger; - m_PubTrigger = NULL; - delete [] m_PrivTrigger; - m_PrivTrigger = NULL; delete [] m_ArgSBackup; m_ArgSBackup = NULL; } @@ -89,16 +83,12 @@ ConfigResult ChatTriggers::OnSourceModConfigChanged(const char *key, { if (strcmp(key, "PublicChatTrigger") == 0) { - delete [] m_PubTrigger; - m_PubTrigger = sm_strdup(value); - m_PubTriggerSize = strlen(m_PubTrigger); + m_PubTrigger = value; return ConfigResult_Accept; } else if (strcmp(key, "SilentChatTrigger") == 0) { - delete [] m_PrivTrigger; - m_PrivTrigger = sm_strdup(value); - m_PrivTriggerSize = strlen(m_PrivTrigger); + m_PrivTrigger = value; return ConfigResult_Accept; } else if (strcmp(key, "SilentFailSuppress") == 0) @@ -323,16 +313,16 @@ void ChatTriggers::OnSayCommand_Pre() bool is_silent = false; /* Check for either trigger */ - if (m_PubTriggerSize && strncmp(m_ArgSBackup, m_PubTrigger, m_PubTriggerSize) == 0) + if (m_PubTrigger.length() && strncmp(m_ArgSBackup, m_PubTrigger.chars(), m_PubTrigger.length()) == 0) { is_trigger = true; - args = &m_ArgSBackup[m_PubTriggerSize]; + args = &m_ArgSBackup[m_PubTrigger.length()]; } - else if (m_PrivTriggerSize && strncmp(m_ArgSBackup, m_PrivTrigger, m_PrivTriggerSize) == 0) + else if (m_PrivTrigger.length() && strncmp(m_ArgSBackup, m_PrivTrigger.chars(), m_PrivTrigger.length()) == 0) { is_trigger = true; is_silent = true; - args = &m_ArgSBackup[m_PrivTriggerSize]; + args = &m_ArgSBackup[m_PrivTrigger.length()]; } /** diff --git a/core/ChatTriggers.h b/core/ChatTriggers.h index f87ec778..ee8eb49c 100644 --- a/core/ChatTriggers.h +++ b/core/ChatTriggers.h @@ -1,5 +1,5 @@ /** - * vim: set ts=4 : + * vim: set ts=4 sw=4 tw=99 noet : * ============================================================================= * SourceMod * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. @@ -37,6 +37,7 @@ #include #include #include +#include class ChatTriggers : public SMGlobalClass { @@ -81,10 +82,8 @@ private: #elif SOURCE_ENGINE == SE_NUCLEARDAWN ConCommand *m_pSaySquadCmd; #endif - char *m_PubTrigger; - size_t m_PubTriggerSize; - char *m_PrivTrigger; - size_t m_PrivTriggerSize; + ke::AString m_PubTrigger; + ke::AString m_PrivTrigger; bool m_bWillProcessInPost; bool m_bIsChatTrigger; bool m_bWasFloodedMessage;