diff options
author | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2008-05-02 15:08:14 +0000 |
---|---|---|
committer | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2008-05-02 15:08:14 +0000 |
commit | e67711acbe9d29a2feb9293fccc72cd15603ee76 (patch) | |
tree | 4836c33e941c3aef9ee194fe9e9262f563653474 /src/map/atcommand.c | |
parent | 1d835a4b7374e5f185d666bde1e3b0dbced86bd1 (diff) | |
download | hercules-e67711acbe9d29a2feb9293fccc72cd15603ee76.tar.gz hercules-e67711acbe9d29a2feb9293fccc72cd15603ee76.tar.bz2 hercules-e67711acbe9d29a2feb9293fccc72cd15603ee76.tar.xz hercules-e67711acbe9d29a2feb9293fccc72cd15603ee76.zip |
Replaced the very ineffective clif_foreachclient() with map_foreachpc() since they essentially do the same thing (bugreport:1174).
Rewrote map_foreachpc() so that its callback function signature now uses a more natural 'sd' instead of a DBKey/void* pair.
Rewrote atcommand_users() to use a single function, instead of depending on two helper functions and global objects.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@12683 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/atcommand.c')
-rw-r--r-- | src/map/atcommand.c | 67 |
1 files changed, 39 insertions, 28 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 691035c61..1f69df496 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -6447,37 +6447,51 @@ int atcommand_pettalk(const int fd, struct map_session_data* sd, const char* com /*========================================== * @users - displays the number of players present on each map (percentage) *------------------------------------------*/ - -static DBMap* users_db = NULL; // unsigned int mapindex -> int users -static int users_all; - -static int atcommand_users_sub1(struct map_session_data* sd,va_list va) -{ - int users = (int)(uidb_get(users_db,(unsigned int)sd->mapindex)) + 1; - users_all++; - uidb_put(users_db,(unsigned int)sd->mapindex,(void *)users); - return 0; -} - -static int atcommand_users_sub2(DBKey key,void* val,va_list va) -{ - char buf[256]; - struct map_session_data* sd = va_arg(va,struct map_session_data*); - sprintf(buf,"%s: %d (%d%%)",mapindex_id2name(key.i),(int)val,(int)val * 100 / users_all); - clif_displaymessage(sd->fd,buf); - return 0; -} - int atcommand_users(const int fd, struct map_session_data* sd, const char* command, const char* message) { char buf[256]; + DBMap* users_db; // unsigned int mapindex -> int users + int users_all; + + users_db = uidb_alloc(DB_OPT_BASE); users_all = 0; - users_db->clear(users_db, NULL); - clif_foreachclient(atcommand_users_sub1); - users_db->foreach(users_db,atcommand_users_sub2,sd); + // count users on each map + { + struct s_mapiterator* iter; + struct map_session_data* sd; + + iter = mapit_getallusers(); + for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) ) + { + int users = (int)uidb_get(users_db,sd->mapindex) + 1; + uidb_put(users_db,(unsigned int)sd->mapindex,(void *)users); + users_all++; + } + mapit_free(iter); + } + + // display results for each map + { + DBIterator* iter; + DBKey index; + int users; + + iter = users_db->iterator(users_db); + for( users = (int)iter->first(iter,&index); iter->exists(iter); users = (int)iter->next(iter,&index) ) + { + sprintf(buf,"%s: %d (%d%%)",mapindex_id2name(index.i),users,users * 100 / users_all); + clif_displaymessage(sd->fd,buf); + } + iter->destroy(iter); + } + + // display overall count sprintf(buf,"all: %d",users_all); clif_displaymessage(fd,buf); + + users_db->destroy(users_db,NULL); + return 0; } @@ -7436,8 +7450,7 @@ int atcommand_whodrops(const int fd, struct map_session_data* sd, const char* co } for (i = 0; i < count; i++) { item_data = item_array[i]; - sprintf(atcmd_output, "Item: '%s'[%d]", - item_data->jname,item_data->slot); + sprintf(atcmd_output, "Item: '%s'[%d]", item_data->jname,item_data->slot); clif_displaymessage(fd, atcmd_output); if (item_data->mob[0].chance == 0) { @@ -8701,14 +8714,12 @@ int atcommand_config_read(const char* cfgName) void do_init_atcommand() { - users_db = uidb_alloc(DB_OPT_BASE); add_timer_func_list(atshowmobs_timer, "atshowmobs_timer"); return; } void do_final_atcommand() { - users_db->destroy(users_db,NULL); } |