From a7ea318bbf7feb5f7d1ffa9292b23a16c8a3be87 Mon Sep 17 00:00:00 2001 From: xazax-hun Date: Fri, 4 May 2012 21:53:09 +0000 Subject: * Partially reverted r16076. The 2 loops wasn't unnecessary, they use different match strategy. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@16078 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/atcommand.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 24a453cce..741513ca2 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -8780,15 +8780,36 @@ static void atcommand_get_suggestions(struct map_session_data* sd, const char *n else type = COMMAND_CHARCOMMAND; + + // First match the beginnings of the commands for (command_info = dbi_first(atcommand_iter); dbi_exists(atcommand_iter) && count < MAX_SUGGESTIONS; command_info = dbi_next(atcommand_iter)) { - if ( stristr(command_info->command, name) == command_info->command && pc_can_use_command(sd, command_info->command, type) ) { + if ( strstr(command_info->command, name) == command_info->command && pc_can_use_command(sd, command_info->command, type) ) + { suggestions[count] = command_info->command; ++count; } } for (alias_info = dbi_first(alias_iter); dbi_exists(alias_iter) && count < MAX_SUGGESTIONS; alias_info = dbi_next(alias_iter)) { - if ( stristr(alias_info->alias, name) == alias_info->alias && pc_can_use_command(sd, alias_info->command->command, type) ) { + if ( strstr(alias_info->alias, name) == alias_info->alias && pc_can_use_command(sd, alias_info->command->command, type) ) + { + suggestions[count] = alias_info->alias; + ++count; + } + } + + // Fill up the space left, with full matches + for (command_info = dbi_first(atcommand_iter); dbi_exists(atcommand_iter) && count < MAX_SUGGESTIONS; command_info = dbi_next(atcommand_iter)) { + if ( strstr(command_info->command, name) != NULL && pc_can_use_command(sd, command_info->command, type) ) + { + suggestions[count] = command_info->command; + ++count; + } + } + + for (alias_info = dbi_first(alias_iter); dbi_exists(alias_iter) && count < MAX_SUGGESTIONS; alias_info = dbi_next(alias_iter)) { + if ( strstr(alias_info->alias, name) != NULL && pc_can_use_command(sd, alias_info->command->command, type) ) + { suggestions[count] = alias_info->alias; ++count; } -- cgit v1.2.3-70-g09d2