[10403] Stricted name check at chat command data loading from 'command' table.

This commit is contained in:
VladimirMangos 2010-08-23 16:26:31 +04:00
parent 09b03b470e
commit d8fb1a60ac
3 changed files with 17 additions and 8 deletions

View file

@ -995,6 +995,7 @@ ChatCommand const* ChatHandler::FindCommand(char const* text)
* @param parentCommand Output arg for optional return parent command for command arg. * @param parentCommand Output arg for optional return parent command for command arg.
* @param cmdNamePtr Output arg for optional return last parsed command name. * @param cmdNamePtr Output arg for optional return last parsed command name.
* @param allAvailable Optional arg (with false default value) control use command access level checks while command search. * @param allAvailable Optional arg (with false default value) control use command access level checks while command search.
* @param exactlyName Optional arg (with false default value) control use exactly name in checks while command search.
* *
* @return one from enum value of ChatCommandSearchResult. Output args return values highly dependent from this return result: * @return one from enum value of ChatCommandSearchResult. Output args return values highly dependent from this return result:
* *
@ -1013,7 +1014,7 @@ ChatCommand const* ChatHandler::FindCommand(char const* text)
* parentCommand have parent of command in command arg or NULL * parentCommand have parent of command in command arg or NULL
* cmdNamePtr store command name that not found as it extracted from command line * cmdNamePtr store command name that not found as it extracted from command line
*/ */
ChatCommandSearchResult ChatHandler::FindCommand(ChatCommand* table, char const* &text, ChatCommand*& command, ChatCommand** parentCommand /*= NULL*/, std::string* cmdNamePtr /*= NULL*/, bool allAvailable /*= false*/) ChatCommandSearchResult ChatHandler::FindCommand(ChatCommand* table, char const* &text, ChatCommand*& command, ChatCommand** parentCommand /*= NULL*/, std::string* cmdNamePtr /*= NULL*/, bool allAvailable /*= false*/, bool exactlyName /*= false*/)
{ {
std::string cmd = ""; std::string cmd = "";
@ -1029,15 +1030,23 @@ ChatCommandSearchResult ChatHandler::FindCommand(ChatCommand* table, char const*
// search first level command in table // search first level command in table
for(uint32 i = 0; table[i].Name != NULL; ++i) for(uint32 i = 0; table[i].Name != NULL; ++i)
{ {
if (!hasStringAbbr(table[i].Name, cmd.c_str())) if (exactlyName)
continue; {
size_t len = strlen(table[i].Name);
if (strncmp(table[i].Name, cmd.c_str(), len+1) != 0)
continue;
}
else
{
if (!hasStringAbbr(table[i].Name, cmd.c_str()))
continue;
}
// select subcommand from child commands list // select subcommand from child commands list
if (table[i].ChildCommands != NULL) if (table[i].ChildCommands != NULL)
{ {
char const* oldchildtext = text; char const* oldchildtext = text;
ChatCommand* parentSubcommand = NULL; ChatCommand* parentSubcommand = NULL;
ChatCommandSearchResult res = FindCommand(table[i].ChildCommands, text, command, &parentSubcommand, cmdNamePtr, allAvailable); ChatCommandSearchResult res = FindCommand(table[i].ChildCommands, text, command, &parentSubcommand, cmdNamePtr, allAvailable, exactlyName);
switch(res) switch(res)
{ {
@ -1200,7 +1209,7 @@ bool ChatHandler::SetDataForCommandInTable(ChatCommand *commandTable, const char
ChatCommand* command = NULL; ChatCommand* command = NULL;
std::string cmdName; std::string cmdName;
ChatCommandSearchResult res = FindCommand(commandTable, text, command, NULL, &cmdName, true); ChatCommandSearchResult res = FindCommand(commandTable, text, command, NULL, &cmdName, true, true);
switch(res) switch(res)
{ {

View file

@ -111,7 +111,7 @@ class ChatHandler
void ExecuteCommand(const char* text); void ExecuteCommand(const char* text);
bool ShowHelpForCommand(ChatCommand *table, const char* cmd); bool ShowHelpForCommand(ChatCommand *table, const char* cmd);
bool ShowHelpForSubCommands(ChatCommand *table, char const* cmd); bool ShowHelpForSubCommands(ChatCommand *table, char const* cmd);
ChatCommandSearchResult FindCommand(ChatCommand* table, char const*& text, ChatCommand*& command, ChatCommand** parentCommand = NULL, std::string* cmdNamePtr = NULL, bool allAvailable = false); ChatCommandSearchResult FindCommand(ChatCommand* table, char const*& text, ChatCommand*& command, ChatCommand** parentCommand = NULL, std::string* cmdNamePtr = NULL, bool allAvailable = false, bool exactlyName = false);
void CheckIntegrity(ChatCommand *table, ChatCommand *parentCommand); void CheckIntegrity(ChatCommand *table, ChatCommand *parentCommand);
ChatCommand* getCommandTable(); ChatCommand* getCommandTable();

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "10402" #define REVISION_NR "10403"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__