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://svn.code.sf.net/p/rathena/svn/trunk@12683 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
parent
0ce34d51a4
commit
62cc01866b
@ -239,7 +239,7 @@ unsigned int get_percentage(const unsigned int A, const unsigned int B)
|
|||||||
|
|
||||||
if( result > UINT_MAX )
|
if( result > UINT_MAX )
|
||||||
{
|
{
|
||||||
ShowError("get_percentage(): result percentage too high! (A=%u,B=%u,result=%g)", A, B, result);
|
ShowError("get_percentage(): result percentage too high! (A=%u,B=%u,result=%g)\n", A, B, result);
|
||||||
return UINT_MAX;
|
return UINT_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
* @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)
|
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 users_all;
|
||||||
|
|
||||||
|
users_db = uidb_alloc(DB_OPT_BASE);
|
||||||
users_all = 0;
|
users_all = 0;
|
||||||
|
|
||||||
users_db->clear(users_db, NULL);
|
// count users on each map
|
||||||
clif_foreachclient(atcommand_users_sub1);
|
{
|
||||||
users_db->foreach(users_db,atcommand_users_sub2,sd);
|
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);
|
sprintf(buf,"all: %d",users_all);
|
||||||
clif_displaymessage(fd,buf);
|
clif_displaymessage(fd,buf);
|
||||||
|
|
||||||
|
users_db->destroy(users_db,NULL);
|
||||||
|
|
||||||
return 0;
|
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++) {
|
for (i = 0; i < count; i++) {
|
||||||
item_data = item_array[i];
|
item_data = item_array[i];
|
||||||
sprintf(atcmd_output, "Item: '%s'[%d]",
|
sprintf(atcmd_output, "Item: '%s'[%d]", item_data->jname,item_data->slot);
|
||||||
item_data->jname,item_data->slot);
|
|
||||||
clif_displaymessage(fd, atcmd_output);
|
clif_displaymessage(fd, atcmd_output);
|
||||||
|
|
||||||
if (item_data->mob[0].chance == 0) {
|
if (item_data->mob[0].chance == 0) {
|
||||||
@ -8701,14 +8714,12 @@ int atcommand_config_read(const char* cfgName)
|
|||||||
|
|
||||||
void do_init_atcommand()
|
void do_init_atcommand()
|
||||||
{
|
{
|
||||||
users_db = uidb_alloc(DB_OPT_BASE);
|
|
||||||
add_timer_func_list(atshowmobs_timer, "atshowmobs_timer");
|
add_timer_func_list(atshowmobs_timer, "atshowmobs_timer");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_final_atcommand()
|
void do_final_atcommand()
|
||||||
{
|
{
|
||||||
users_db->destroy(users_db,NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -160,29 +160,6 @@ uint16 clif_getport(void)
|
|||||||
return map_port;
|
return map_port;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*==========================================
|
|
||||||
* ‘S‚Ä‚Ìclient‚ɑ΂µ‚Äfunc()ŽÀ<EFBFBD>s
|
|
||||||
*------------------------------------------*/
|
|
||||||
int clif_foreachclient(int (*func)(struct map_session_data*, va_list),...) //recoded by sasuke, bug when player count gets higher [Kevin]
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
va_list ap;
|
|
||||||
struct map_session_data *sd;
|
|
||||||
|
|
||||||
va_start(ap,func);
|
|
||||||
|
|
||||||
for(i = 0; i < fd_max; i++) {
|
|
||||||
if ( session[i] && session[i]->func_parse == clif_parse) {
|
|
||||||
sd = (struct map_session_data*)session[i]->session_data;
|
|
||||||
if ( sd && sd->state.active )
|
|
||||||
func(sd, ap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
va_end(ap);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*==========================================
|
/*==========================================
|
||||||
* clif_send‚ÅAREA*Žw’莞—p
|
* clif_send‚ÅAREA*Žw’莞—p
|
||||||
*------------------------------------------*/
|
*------------------------------------------*/
|
||||||
@ -6339,7 +6316,7 @@ int clif_guild_emblem(struct map_session_data *sd,struct guild *g)
|
|||||||
/// Sends update of the guild id/emblem id to everyone in the area.
|
/// Sends update of the guild id/emblem id to everyone in the area.
|
||||||
void clif_guild_emblem_area(struct block_list* bl)
|
void clif_guild_emblem_area(struct block_list* bl)
|
||||||
{
|
{
|
||||||
char buf[12];
|
uint8 buf[12];
|
||||||
|
|
||||||
nullpo_retv(bl);
|
nullpo_retv(bl);
|
||||||
|
|
||||||
@ -7916,7 +7893,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Notify everyone that this char logged in [Skotlex].
|
// Notify everyone that this char logged in [Skotlex].
|
||||||
clif_foreachclient(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
|
map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
|
||||||
|
|
||||||
//Login Event
|
//Login Event
|
||||||
npc_script_event(sd, NPCE_LOGIN);
|
npc_script_event(sd, NPCE_LOGIN);
|
||||||
|
@ -402,7 +402,6 @@ void clif_send_quest_delete(struct map_session_data * sd, int quest_id);
|
|||||||
void clif_send_quest_status(struct map_session_data * sd, int quest_id, bool active);
|
void clif_send_quest_status(struct map_session_data * sd, int quest_id, bool active);
|
||||||
|
|
||||||
|
|
||||||
int clif_foreachclient(int (*)(struct map_session_data*,va_list),...);
|
|
||||||
int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type);
|
int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type);
|
||||||
int do_final_clif(void);
|
int do_final_clif(void);
|
||||||
int do_init_clif(void);
|
int do_init_clif(void);
|
||||||
|
@ -906,7 +906,7 @@ int mapif_parse_WisToGM(int fd)
|
|||||||
safestrncpy(Wisp_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
|
safestrncpy(Wisp_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
|
||||||
safestrncpy(message, (char*)RFIFOP(fd,30), mes_len);
|
safestrncpy(message, (char*)RFIFOP(fd,30), mes_len);
|
||||||
// information is sended to all online GM
|
// information is sended to all online GM
|
||||||
clif_foreachclient(mapif_parse_WisToGM_sub, min_gm_level, Wisp_name, message, mes_len);
|
map_foreachpc(mapif_parse_WisToGM_sub, min_gm_level, Wisp_name, message, mes_len);
|
||||||
|
|
||||||
if (message != mbuf)
|
if (message != mbuf)
|
||||||
aFree(message);
|
aFree(message);
|
||||||
|
@ -1739,12 +1739,22 @@ struct block_list * map_id2bl(int id)
|
|||||||
return bl;
|
return bl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void map_foreachpc(int (*func)(DBKey,void*,va_list),...)
|
void map_foreachpc(int (*func)(struct map_session_data* sd, va_list args), ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
DBIterator* iter;
|
||||||
va_start(ap,func);
|
struct map_session_data* sd;
|
||||||
pc_db->vforeach(pc_db,func,ap);
|
va_list args, argscopy;
|
||||||
va_end(ap);
|
|
||||||
|
va_start(args,func);
|
||||||
|
iter = pc_db->iterator(pc_db);
|
||||||
|
for( sd = (struct map_session_data*)iter->first(iter,NULL); iter->exists(iter); sd = (struct map_session_data*)iter->next(iter,NULL) )
|
||||||
|
{
|
||||||
|
va_copy(argscopy,args);
|
||||||
|
func(sd, argscopy);
|
||||||
|
va_end(argscopy);
|
||||||
|
}
|
||||||
|
iter->destroy(iter);
|
||||||
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void map_foreachmob(int (*func)(DBKey,void*,va_list),...)
|
void map_foreachmob(int (*func)(DBKey,void*,va_list),...)
|
||||||
@ -3120,10 +3130,8 @@ void do_final(void)
|
|||||||
ShowStatus("Successfully terminated.\n");
|
ShowStatus("Successfully terminated.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int map_abort_sub(DBKey key,void * data,va_list ap)
|
static int map_abort_sub(struct map_session_data* sd, va_list ap)
|
||||||
{
|
{
|
||||||
struct map_session_data *sd = (TBL_PC*)data;
|
|
||||||
|
|
||||||
chrif_save(sd,1);
|
chrif_save(sd,1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -562,7 +562,7 @@ int map_eraseipport(unsigned short map, uint32 ip, uint16 port);
|
|||||||
int map_eraseallipport(void);
|
int map_eraseallipport(void);
|
||||||
void map_addiddb(struct block_list *);
|
void map_addiddb(struct block_list *);
|
||||||
void map_deliddb(struct block_list *bl);
|
void map_deliddb(struct block_list *bl);
|
||||||
void map_foreachpc(int (*func)(DBKey,void*,va_list),...);
|
void map_foreachpc(int (*func)(struct map_session_data* sd, va_list args), ...);
|
||||||
void map_foreachmob(int (*func)(DBKey,void*,va_list),...);
|
void map_foreachmob(int (*func)(DBKey,void*,va_list),...);
|
||||||
int map_foreachiddb(int (*)(DBKey,void*,va_list),...);
|
int map_foreachiddb(int (*)(DBKey,void*,va_list),...);
|
||||||
struct map_session_data * map_nick2sd(const char*);
|
struct map_session_data * map_nick2sd(const char*);
|
||||||
|
@ -1766,7 +1766,7 @@ static int mob_ai_hard(int tid, unsigned int tick, int id, intptr data)
|
|||||||
if (battle_config.mob_ai&0x20)
|
if (battle_config.mob_ai&0x20)
|
||||||
map_foreachmob(mob_ai_sub_lazy,tick);
|
map_foreachmob(mob_ai_sub_lazy,tick);
|
||||||
else
|
else
|
||||||
clif_foreachclient(mob_ai_sub_foreachclient,tick);
|
map_foreachpc(mob_ai_sub_foreachclient,tick);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -6996,7 +6996,7 @@ int map_day_timer(int tid, unsigned int tick, int id, intptr data)
|
|||||||
return 0; //Already day.
|
return 0; //Already day.
|
||||||
|
|
||||||
night_flag = 0; // 0=day, 1=night [Yor]
|
night_flag = 0; // 0=day, 1=night [Yor]
|
||||||
clif_foreachclient(pc_daynight_timer_sub);
|
map_foreachpc(pc_daynight_timer_sub);
|
||||||
strcpy(tmp_soutput, (data == 0) ? msg_txt(502) : msg_txt(60)); // The day has arrived!
|
strcpy(tmp_soutput, (data == 0) ? msg_txt(502) : msg_txt(60)); // The day has arrived!
|
||||||
intif_GMmessage(tmp_soutput, strlen(tmp_soutput) + 1, 0);
|
intif_GMmessage(tmp_soutput, strlen(tmp_soutput) + 1, 0);
|
||||||
return 0;
|
return 0;
|
||||||
@ -7017,7 +7017,7 @@ int map_night_timer(int tid, unsigned int tick, int id, intptr data)
|
|||||||
return 0; //Already nigth.
|
return 0; //Already nigth.
|
||||||
|
|
||||||
night_flag = 1; // 0=day, 1=night [Yor]
|
night_flag = 1; // 0=day, 1=night [Yor]
|
||||||
clif_foreachclient(pc_daynight_timer_sub);
|
map_foreachpc(pc_daynight_timer_sub);
|
||||||
strcpy(tmp_soutput, (data == 0) ? msg_txt(503) : msg_txt(59)); // The night has fallen...
|
strcpy(tmp_soutput, (data == 0) ? msg_txt(503) : msg_txt(59)); // The night has fallen...
|
||||||
intif_GMmessage(tmp_soutput, strlen(tmp_soutput) + 1, 0);
|
intif_GMmessage(tmp_soutput, strlen(tmp_soutput) + 1, 0);
|
||||||
return 0;
|
return 0;
|
||||||
@ -7093,7 +7093,7 @@ int duel_showinfo(const unsigned int did, struct map_session_data* sd)
|
|||||||
duel_list[did].members_count + duel_list[did].invites_count);
|
duel_list[did].members_count + duel_list[did].invites_count);
|
||||||
|
|
||||||
clif_disp_onlyself(sd, output, strlen(output));
|
clif_disp_onlyself(sd, output, strlen(output));
|
||||||
clif_foreachclient(duel_showinfo_sub, sd, &p);
|
map_foreachpc(duel_showinfo_sub, sd, &p);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -7155,7 +7155,7 @@ int duel_leave(const unsigned int did, struct map_session_data* sd)
|
|||||||
duel_list[did].members_count--;
|
duel_list[did].members_count--;
|
||||||
|
|
||||||
if(duel_list[did].members_count == 0) {
|
if(duel_list[did].members_count == 0) {
|
||||||
clif_foreachclient(duel_leave_sub, did);
|
map_foreachpc(duel_leave_sub, did);
|
||||||
duel_count--;
|
duel_count--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -971,7 +971,7 @@ static int pet_ai_sub_foreachclient(struct map_session_data *sd,va_list ap)
|
|||||||
|
|
||||||
static int pet_ai_hard(int tid, unsigned int tick, int id, intptr data)
|
static int pet_ai_hard(int tid, unsigned int tick, int id, intptr data)
|
||||||
{
|
{
|
||||||
clif_foreachclient(pet_ai_sub_foreachclient,tick);
|
map_foreachpc(pet_ai_sub_foreachclient,tick);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -9151,12 +9151,11 @@ BUILDIN_FUNC(emotion)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int buildin_maprespawnguildid_sub_pc(DBKey key, void *data, va_list ap)
|
static int buildin_maprespawnguildid_sub_pc(struct map_session_data* sd, va_list ap)
|
||||||
{
|
{
|
||||||
int m=va_arg(ap,int);
|
int m=va_arg(ap,int);
|
||||||
int g_id=va_arg(ap,int);
|
int g_id=va_arg(ap,int);
|
||||||
int flag=va_arg(ap,int);
|
int flag=va_arg(ap,int);
|
||||||
TBL_PC *sd = (TBL_PC*)data;
|
|
||||||
|
|
||||||
if(!sd || sd->bl.m != m)
|
if(!sd || sd->bl.m != m)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1860,7 +1860,7 @@ int unit_free(struct block_list *bl, int clrtype)
|
|||||||
duel_reject(sd->duel_invite, sd);
|
duel_reject(sd->duel_invite, sd);
|
||||||
|
|
||||||
// Notify friends that this char logged out. [Skotlex]
|
// Notify friends that this char logged out. [Skotlex]
|
||||||
clif_foreachclient(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 0);
|
map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 0);
|
||||||
party_send_logout(sd);
|
party_send_logout(sd);
|
||||||
guild_send_memberinfoshort(sd,0);
|
guild_send_memberinfoshort(sd,0);
|
||||||
pc_cleareventtimer(sd);
|
pc_cleareventtimer(sd);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user