Reduce dependence on sm_strdup.

This commit is contained in:
David Anderson 2015-09-05 21:55:41 -07:00
parent 13a783d441
commit 86f0a77e73
2 changed files with 12 additions and 23 deletions

View File

@ -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()];
}
/**

View File

@ -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 <IGameHelpers.h>
#include <compat_wrappers.h>
#include <IForwardSys.h>
#include <amtl/am-string.h>
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;