diff options
author | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2008-02-11 17:46:31 +0000 |
---|---|---|
committer | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2008-02-11 17:46:31 +0000 |
commit | c2e7d12b8baff6c190b1a61c175366a6af15326d (patch) | |
tree | becd092d9c0d11065f722991c7caace7502c9535 /src/map/map.c | |
parent | c31be7e56e5c1d4345df7c5baf6fb4f4c412d7aa (diff) | |
download | hercules-c2e7d12b8baff6c190b1a61c175366a6af15326d.tar.gz hercules-c2e7d12b8baff6c190b1a61c175366a6af15326d.tar.bz2 hercules-c2e7d12b8baff6c190b1a61c175366a6af15326d.tar.xz hercules-c2e7d12b8baff6c190b1a61c175366a6af15326d.zip |
Getting rid of map_getallusers(), part 1
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@12195 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/map.c')
-rw-r--r-- | src/map/map.c | 72 |
1 files changed, 43 insertions, 29 deletions
diff --git a/src/map/map.c b/src/map/map.c index cc8de1a3a..c02a896a9 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -1703,39 +1703,51 @@ struct map_session_data* map_charid2sd(int charid) *------------------------------------------*/ struct map_session_data * map_nick2sd(const char *nick) { - int i, users; - struct map_session_data *pl_sd = NULL, **pl_allsd; + struct map_session_data* sd; + struct map_session_data* found_sd; + struct s_mapiterator* iter; + size_t nicklen; - if (nick == NULL) + if( nick == NULL ) return NULL; - pl_allsd = map_getallusers(&users); - if (battle_config.partial_name_scan) + nicklen = strlen(nick); + iter = mapit_getallusers(); + + found_sd = NULL; + for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) { - int qty = 0, nicklen = strlen(nick); - struct map_session_data *sd = NULL; - for (i = 0; i < users; i++) { - pl_sd = pl_allsd[i]; - // Without case sensitive check (increase the number of similar character names found) - if (strnicmp(pl_sd->status.name, nick, nicklen) == 0) { - // Strict comparison (if found, we finish the function immediatly with correct value) - if (strcmp(pl_sd->status.name, nick) == 0) - return pl_sd; - qty++; - sd = pl_sd; + if( battle_config.partial_name_scan ) + {// partial name search + if( strnicmp(sd->status.name, nick, nicklen) == 0 ) + { + if( strcmp(sd->status.name, nick) == 0 ) + {// perfect match found + found_sd = sd; + break; + } + if( found_sd != NULL ) + {// collision + found_sd = NULL; + break; + } + + found_sd = sd; } } - // We return the found index of a similar account ONLY if there is 1 similar character - if (qty == 1) - return sd; - } else { //Exact Search - for (i = 0; i < users; i++) { - if (strcasecmp(pl_allsd[i]->status.name, nick) == 0) - return pl_allsd[i]; + else + {// exact search only + if( strcasecmp(sd->status.name, nick) == 0 ) + { + found_sd = sd; + break; + } } } - //Not found. - return NULL; + + mapit_free(iter); + + return found_sd; } /*========================================== @@ -3134,7 +3146,8 @@ static int cleanup_db_subpc(DBKey key,void *data,va_list va) void do_final(void) { int i, j; - struct map_session_data **pl_allsd; + struct map_session_data* sd; + struct s_mapiterator* iter; ShowStatus("Terminating...\n"); @@ -3143,9 +3156,10 @@ void do_final(void) map_foreachinmap(cleanup_sub, i, BL_ALL); //Scan any remaining players (between maps?) to kick them out. [Skotlex] - pl_allsd = map_getallusers(&j); - for (i = 0; i < j; i++) - map_quit(pl_allsd[i]); + iter = mapit_getallusers(); + for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) ) + map_quit(sd); + mapit_free(iter); id_db->foreach(id_db,cleanup_db_sub); chrif_char_reset_offline(); |