Skip to content

Commit

Permalink
[10403] Stricted name check at chat command data loading from 'comman…
Browse files Browse the repository at this point in the history
…d' table.
  • Loading branch information
VladimirMangos committed Aug 23, 2010
1 parent 9c83c79 commit 4bbb824
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
21 changes: 15 additions & 6 deletions src/game/Chat.cpp
Expand Up @@ -995,6 +995,7 @@ ChatCommand const* ChatHandler::FindCommand(char const* text)
* @param parentCommand Output arg for optional return parent command for command arg.
* @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 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:
*
Expand All @@ -1013,7 +1014,7 @@ ChatCommand const* ChatHandler::FindCommand(char const* text)
* parentCommand have parent of command in command arg or NULL
* 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 = "";

Expand All @@ -1029,15 +1030,23 @@ ChatCommandSearchResult ChatHandler::FindCommand(ChatCommand* table, char const*
// search first level command in table
for(uint32 i = 0; table[i].Name != NULL; ++i)
{
if (!hasStringAbbr(table[i].Name, cmd.c_str()))
continue;

if (exactlyName)
{
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
if (table[i].ChildCommands != NULL)
{
char const* oldchildtext = text;
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)
{
Expand Down Expand Up @@ -1200,7 +1209,7 @@ bool ChatHandler::SetDataForCommandInTable(ChatCommand *commandTable, const char
ChatCommand* command = NULL;
std::string cmdName;

ChatCommandSearchResult res = FindCommand(commandTable, text, command, NULL, &cmdName, true);
ChatCommandSearchResult res = FindCommand(commandTable, text, command, NULL, &cmdName, true, true);

switch(res)
{
Expand Down
2 changes: 1 addition & 1 deletion src/game/Chat.h
Expand Up @@ -111,7 +111,7 @@ class ChatHandler
void ExecuteCommand(const char* text);
bool ShowHelpForCommand(ChatCommand *table, const char* 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);
ChatCommand* getCommandTable();
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "10402"
#define REVISION_NR "10403"
#endif // __REVISION_NR_H__

0 comments on commit 4bbb824

Please sign in to comment.