diff -r 0f75d9c13fc2 -r 767c92704500 core/ConCmdManager.cpp --- a/core/ConCmdManager.cpp Sat Jun 18 14:36:20 2011 -0400 +++ b/core/ConCmdManager.cpp Mon Jun 20 13:30:14 2011 -0400 @@ -226,30 +226,38 @@ m_CmdClient = client + 1; } +ConCmdInfo *ConCmdManager::FindInTrie(const char *name) +{ + ConCmdInfo *pInfo; + if (!sm_trie_retrieve(m_pCmds, name, (void **)&pInfo)) + return NULL; + 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; - if (!sm_trie_retrieve(m_pCmds, cmd, (void **)&pInfo)) + if ((pInfo = FindInTrie(cmd)) == NULL) { - List::iterator iter; - - pInfo = NULL; - iter = m_CmdList.begin(); - while (iter != m_CmdList.end()) - { - if (strcasecmp((*iter)->pCmd->GetName(), cmd) == 0) - { - pInfo = (*iter); - break; - } - iter++; - } - - if (pInfo == NULL) - { + ConCmdList::iterator item = FindInList(cmd); + if (item == m_CmdList.end()) return type; - } + pInfo = *item; } cell_t result = type; @@ -314,35 +322,20 @@ */ const char *cmd = g_HL2.CurrentCommandName(); - ConCmdInfo *pInfo; - if (!sm_trie_retrieve(m_pCmds, cmd, (void **)&pInfo)) + 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; - } - - List::iterator iter; - pInfo = NULL; - iter = m_CmdList.begin(); - while (iter != m_CmdList.end()) - { - if (strcasecmp((*iter)->pCmd->GetName(), cmd) == 0) - { - pInfo = (*iter); - break; - } - iter++; - } - - if (pInfo == NULL) - { - return; - } + ConCmdList::iterator item = FindInList(cmd); + if (item == m_CmdList.end()) + return; + + pInfo = *item; } /* This is a hack to prevent say triggers from firing on messages that were @@ -916,6 +909,10 @@ ConCmdInfo *pInfo; if (!sm_trie_retrieve(m_pCmds, name, (void **)&pInfo)) { + ConCmdList::iterator item = FindInList(name); + if (item != m_CmdList.end()) + return *item; + pInfo = new ConCmdInfo(); /* Find the commandopan */ ConCommand *pCmd = FindCommand(name);