* Cleaned up command @users/#users:

- displays everything on the target user (self for @users)
- uses a static array instead of a temporary DBMap
- displays percentages with precision of 0.01%
- uses safesnprintf instead of sprintf

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@13446 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
FlavioJS 2009-01-13 12:53:11 +00:00
parent 95d25086a6
commit e64c3496a8
4 changed files with 32 additions and 31 deletions

View File

@ -3,6 +3,12 @@ Date Added
AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK. AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK.
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK. IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
2009/01/13
* Cleaned up command @users/#users: [FlavioJS]
- displays everything on the target user (self for @users)
- uses a static array instead of a temporary DBMap
- displays percentages with precision of 0.01%
- uses safesnprintf instead of sprintf
2009/01/12 2009/01/12
* Mobs with nonzero spawn time can now be cached as well (bugreport:1197) * Mobs with nonzero spawn time can now be cached as well (bugreport:1197)
* Fixed dynamic mobs being unloaded without stopping their respawn timer * Fixed dynamic mobs being unloaded without stopping their respawn timer

View File

@ -11,8 +11,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#define MAX_MAPINDEX 2000
struct _indexes { struct _indexes {
char name[MAP_NAME_LENGTH]; //Stores map name char name[MAP_NAME_LENGTH]; //Stores map name
} indexes[MAX_MAPINDEX]; } indexes[MAX_MAPINDEX];

View File

@ -10,6 +10,8 @@ extern char mapindex_cfgfile[80];
//whether to enable auto-adding of maps during run. Not so secure as the map indexes will vary! //whether to enable auto-adding of maps during run. Not so secure as the map indexes will vary!
//#define MAPINDEX_AUTOADD //#define MAPINDEX_AUTOADD
#define MAX_MAPINDEX 2000
//Some definitions for the mayor city maps. //Some definitions for the mayor city maps.
#define MAP_PRONTERA "prontera" #define MAP_PRONTERA "prontera"
#define MAP_GEFFEN "geffen" #define MAP_GEFFEN "geffen"

View File

@ -6463,53 +6463,48 @@ int atcommand_pettalk(const int fd, struct map_session_data* sd, const char* com
return 0; return 0;
} }
/*========================================== /// @users - displays the number of players present on each map (and percentage)
* @users - displays the number of players present on each map (percentage) /// #users displays on the target user instead of self
*------------------------------------------*/
int atcommand_users(const int fd, struct map_session_data* sd, const char* command, const char* message) int atcommand_users(const int fd, struct map_session_data* sd, const char* command, const char* message)
{ {
char buf[256]; char buf[256];
DBMap* users_db; // unsigned int mapindex -> int users int i;
int users[MAX_MAPINDEX];
int users_all; int users_all;
struct s_mapiterator* iter;
users_db = uidb_alloc(DB_OPT_BASE); memset(users, 0, sizeof(users));
users_all = 0; users_all = 0;
// count users on each map // count users on each map
iter = mapit_getallusers();
while( true )
{ {
struct s_mapiterator* iter; struct map_session_data* sd2 = (struct map_session_data*)mapit_next(iter);
struct map_session_data* sd; if( sd2 == NULL )
break;// no more users
iter = mapit_getallusers(); if( sd2->mapindex >= MAX_MAPINDEX )
for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) ) continue;// invalid mapindex
{
int users = (int)uidb_get(users_db,sd->mapindex) + 1; if( users[sd2->mapindex] < INT_MAX ) ++users[sd2->mapindex];
uidb_put(users_db,(unsigned int)sd->mapindex,(void *)users); if( users_all < INT_MAX ) ++users_all;
users_all++;
}
mapit_free(iter);
} }
mapit_free(iter);
// display results for each map // display results for each map
for( i = 0; i < MAX_MAPINDEX; ++i )
{ {
DBIterator* iter; if( users[i] == 0 )
DBKey index; continue;// empty
int users;
iter = users_db->iterator(users_db); safesnprintf(buf, sizeof(buf), "%s: %d (%.2f%%)", mapindex_id2name(i), users[i], (float)(100.0f*users[i]/users_all));
for( users = (int)iter->first(iter,&index); iter->exists(iter); users = (int)iter->next(iter,&index) ) clif_displaymessage(sd->fd, buf);
{
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 // display overall count
sprintf(buf,"all: %d",users_all); safesnprintf(buf, sizeof(buf), "all: %d", users_all);
clif_displaymessage(fd,buf); clif_displaymessage(sd->fd, buf);
users_db->destroy(users_db,NULL);
return 0; return 0;
} }