diff --git a/core/ChatTriggers.cpp b/core/ChatTriggers.cpp index f04a376b..71a67740 100644 --- a/core/ChatTriggers.cpp +++ b/core/ChatTriggers.cpp @@ -363,7 +363,7 @@ bool ChatTriggers::PreProcessTrigger(edict_t *pEdict, const char *args) if (!g_ConCmds.LookForSourceModCommand(cmd_buf)) { /* Check if we had an "sm_" prefix */ - if (strncmp(cmd_buf, "sm_", 3) == 0) + if (strncasecmp(cmd_buf, "sm_", 3) == 0) { return false; } @@ -387,15 +387,7 @@ bool ChatTriggers::PreProcessTrigger(edict_t *pEdict, const char *args) /* See if we need to do extra string manipulation */ if (prepended) { - size_t len; - - /* Check if we need to prepend sm_ */ - if (prepended) - { - len = ke::SafeSprintf(m_ToExecute, sizeof(m_ToExecute), "sm_%s", args); - } else { - len = ke::SafeStrcpy(m_ToExecute, sizeof(m_ToExecute), args); - } + ke::SafeSprintf(m_ToExecute, sizeof(m_ToExecute), "sm_%s", args); } else { ke::SafeStrcpy(m_ToExecute, sizeof(m_ToExecute), args); } diff --git a/core/ConCmdManager.cpp b/core/ConCmdManager.cpp index 790e29c7..1777cfbe 100644 --- a/core/ConCmdManager.cpp +++ b/core/ConCmdManager.cpp @@ -153,30 +153,13 @@ ConCmdInfo *ConCmdManager::FindInTrie(const char *name) return pInfo; } -ConCmdList::iterator ConCmdManager::FindInList(const char *cmd) -{ - List::iterator iter = m_CmdList.begin(); - - while (iter != m_CmdList.end()) - { - if (strcasecmp((*iter)->pCmd->GetName(), cmd) == 0) - break; - iter++; - } - - return iter; -} - ResultType ConCmdManager::DispatchClientCommand(int client, const char *cmd, int args, ResultType type) { - ConCmdInfo *pInfo; + ConCmdInfo *pInfo = FindInTrie(cmd); - if ((pInfo = FindInTrie(cmd)) == NULL) + if (pInfo == NULL) { - ConCmdList::iterator item = FindInList(cmd); - if (item == m_CmdList.end()) - return type; - pInfo = *item; + return type; } cell_t result = type; @@ -231,17 +214,7 @@ bool ConCmdManager::InternalDispatch(int client, const ICommandArgs *args) ConCmdInfo *pInfo = FindInTrie(cmd); if (pInfo == NULL) { - /* Unfortunately, we now have to do a slow lookup because Valve made client commands - * case-insensitive. We can't even use our sortedness. - */ - if (client == 0 && !engine->IsDedicatedServer()) - return false; - - ConCmdList::iterator item = FindInList(cmd); - if (item == m_CmdList.end()) - return false; - - pInfo = *item; + return false; } /* This is a hack to prevent say triggers from firing on messages that were @@ -568,10 +541,6 @@ ConCmdInfo *ConCmdManager::AddOrFindCommand(const char *name, const char *descri ConCmdInfo *pInfo; if (!m_Cmds.retrieve(name, &pInfo)) { - ConCmdList::iterator item = FindInList(name); - if (item != m_CmdList.end()) - return *item; - pInfo = new ConCmdInfo(); /* Find the commandopan */ ConCommand *pCmd = FindCommand(name); diff --git a/core/ConCmdManager.h b/core/ConCmdManager.h index 899fdcff..a9ec07ed 100644 --- a/core/ConCmdManager.h +++ b/core/ConCmdManager.h @@ -49,6 +49,7 @@ #include #include "concmd_cleaner.h" #include "GameHooks.h" +#include using namespace SourceHook; @@ -108,12 +109,32 @@ struct ConCmdInfo pCmd = nullptr; eflags = 0; } + bool sourceMod; /**< Determines whether or not concmd was created by a SourceMod plugin */ ConCommand *pCmd; /**< Pointer to the command itself */ CmdHookList hooks; /**< Hook list */ FlagBits eflags; /**< Effective admin flags */ ke::RefPtr sh_hook; /**< SourceHook hook, if any. */ IPlugin *pPlugin; /**< Owning plugin handle. */ + + struct ConCmdPolicy + { + static inline bool matches(const char *name, ConCmdInfo *info) + { + const char *conCmdChars = info->pCmd->GetName(); + + std::string concmdName = ke::Lowercase(conCmdChars); + std::string input = ke::Lowercase(name); + + return concmdName == input; + } + + static inline uint32_t hash(const detail::CharsAndLength &key) + { + std::string lower = ke::Lowercase(key.c_str()); + return detail::CharsAndLength(lower.c_str()).hash(); + } + }; }; typedef List ConCmdList; @@ -157,11 +178,6 @@ private: void AddToCmdList(ConCmdInfo *info); void RemoveConCmd(ConCmdInfo *info, const char *cmd, bool untrack); bool CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmin); - - // Case insensitive - ConCmdList::iterator FindInList(const char *name); - - // Case sensitive ConCmdInfo *FindInTrie(const char *name); public: inline const List & GetCommandList() @@ -171,7 +187,7 @@ public: private: typedef StringHashMap > GroupMap; - StringHashMap m_Cmds; /* command lookup */ + NameHashSet m_Cmds; /* command lookup */ GroupMap m_CmdGrps; /* command group map */ ConCmdList m_CmdList; /* command list */ }; diff --git a/public/sm_namehashset.h b/public/sm_namehashset.h index 85e975d3..e71b556f 100644 --- a/public/sm_namehashset.h +++ b/public/sm_namehashset.h @@ -111,12 +111,14 @@ public: Result find(const char *aKey) { - return table_.find(aKey); + CharsAndLength key(aKey); + return table_.find(key); } Insert findForAdd(const char *aKey) { - return table_.findForAdd(aKey); + CharsAndLength key(aKey); + return table_.findForAdd(key); } template @@ -128,7 +130,7 @@ public: bool retrieve(const char *aKey, T *value) { CharsAndLength key(aKey); - Result r = table_.find(aKey); + Result r = table_.find(key); if (!r.found()) return false; *value = *r; @@ -148,7 +150,7 @@ public: bool contains(const char *aKey) { CharsAndLength key(aKey); - Result r = table_.find(aKey); + Result r = table_.find(key); return r.found(); }