diff options
author | Haru <haru@dotalux.com> | 2019-09-23 01:09:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-23 01:09:00 +0200 |
commit | 7121899a562856863984ce90268e9af37769b346 (patch) | |
tree | 8f2c17a1ae78dad6a657866720523d1691f25daf /src/map/map.c | |
parent | ab1127c269daa390f1648f6e8615fe8c209d879e (diff) | |
parent | 20a1f4facea1dc58112b5d2609533dc554b0574b (diff) | |
download | hercules-7121899a562856863984ce90268e9af37769b346.tar.gz hercules-7121899a562856863984ce90268e9af37769b346.tar.bz2 hercules-7121899a562856863984ce90268e9af37769b346.tar.xz hercules-7121899a562856863984ce90268e9af37769b346.zip |
Merge pull request #2523 from MishimaHaruna/name-partial-match
Name partial match
Diffstat (limited to 'src/map/map.c')
-rw-r--r-- | src/map/map.c | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/src/map/map.c b/src/map/map.c index f92be52e9..332bbe75f 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -2268,30 +2268,25 @@ static struct map_session_data *map_charid2sd(int charid) * (without sensitive case if necessary) * return map_session_data pointer or NULL *------------------------------------------*/ -static struct map_session_data *map_nick2sd(const char *nick) +static struct map_session_data *map_nick2sd(const char *nick, bool allow_partial) { - struct map_session_data* sd; - struct map_session_data* found_sd; - struct s_mapiterator* iter; - size_t nicklen; - int qty = 0; - - if( nick == NULL ) + if (nick == NULL) return NULL; - nicklen = strlen(nick); - iter = mapit_getallusers(); + struct s_mapiterator *iter = mapit_getallusers(); + struct map_session_data *found_sd = NULL; + + if (battle_config.partial_name_scan && allow_partial) { + int nicklen = (int)strlen(nick); + int qty = 0; - found_sd = NULL; - for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) { - if( battle_config.partial_name_scan ) - {// partial name search - if( strnicmp(sd->status.name, nick, nicklen) == 0 ) - { + // partial name search + for (struct map_session_data *sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) { + if (strnicmp(sd->status.name, nick, nicklen) == 0) { found_sd = sd; - if( strcmp(sd->status.name, nick) == 0 ) - {// Perfect Match + if (strcmp(sd->status.name, nick) == 0) { + // Perfect Match qty = 1; break; } @@ -2299,17 +2294,20 @@ static struct map_session_data *map_nick2sd(const char *nick) qty++; } } - else if( strcasecmp(sd->status.name, nick) == 0 ) - {// exact search only - found_sd = sd; - break; + + if (qty != 1) + found_sd = NULL; + } else { + // exact search only + for (struct map_session_data *sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) { + if (strcasecmp(sd->status.name, nick) == 0) { + found_sd = sd; + break; + } } } mapit->free(iter); - if( battle_config.partial_name_scan && qty != 1 ) - found_sd = NULL; - return found_sd; } |