summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec>2008-05-02 15:08:14 +0000
committerultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec>2008-05-02 15:08:14 +0000
commite67711acbe9d29a2feb9293fccc72cd15603ee76 (patch)
tree4836c33e941c3aef9ee194fe9e9262f563653474 /src/map
parent1d835a4b7374e5f185d666bde1e3b0dbced86bd1 (diff)
downloadhercules-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')
-rw-r--r--src/map/atcommand.c67
-rw-r--r--src/map/clif.c27
-rw-r--r--src/map/clif.h1
-rw-r--r--src/map/intif.c2
-rw-r--r--src/map/map.c24
-rw-r--r--src/map/map.h2
-rw-r--r--src/map/mob.c2
-rw-r--r--src/map/pc.c8
-rw-r--r--src/map/pet.c2
-rw-r--r--src/map/script.c3
-rw-r--r--src/map/unit.c2
11 files changed, 67 insertions, 73 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);
}
diff --git a/src/map/clif.c b/src/map/clif.c
index 9e197a945..78277161f 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -161,29 +161,6 @@ uint16 clif_getport(void)
}
/*==========================================
- * 全てのclientに対してfunc()実行
- *------------------------------------------*/
-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*指定時用
*------------------------------------------*/
int clif_send_sub(struct block_list *bl, va_list ap)
@@ -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.
void clif_guild_emblem_area(struct block_list* bl)
{
- char buf[12];
+ uint8 buf[12];
nullpo_retv(bl);
@@ -7916,7 +7893,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
#endif
// 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
npc_script_event(sd, NPCE_LOGIN);
diff --git a/src/map/clif.h b/src/map/clif.h
index 56625d3e5..ee75f1a94 100644
--- a/src/map/clif.h
+++ b/src/map/clif.h
@@ -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);
-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 do_final_clif(void);
int do_init_clif(void);
diff --git a/src/map/intif.c b/src/map/intif.c
index 2d9b1894c..e90b5985f 100644
--- a/src/map/intif.c
+++ b/src/map/intif.c
@@ -906,7 +906,7 @@ int mapif_parse_WisToGM(int fd)
safestrncpy(Wisp_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
safestrncpy(message, (char*)RFIFOP(fd,30), mes_len);
// 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)
aFree(message);
diff --git a/src/map/map.c b/src/map/map.c
index c828ab9c7..1e7a48af7 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -1739,12 +1739,22 @@ struct block_list * map_id2bl(int id)
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;
- va_start(ap,func);
- pc_db->vforeach(pc_db,func,ap);
- va_end(ap);
+ DBIterator* iter;
+ struct map_session_data* sd;
+ va_list args, argscopy;
+
+ 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),...)
@@ -3120,10 +3130,8 @@ void do_final(void)
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);
return 1;
}
diff --git a/src/map/map.h b/src/map/map.h
index 79762fa5b..5bbd41986 100644
--- a/src/map/map.h
+++ b/src/map/map.h
@@ -562,7 +562,7 @@ int map_eraseipport(unsigned short map, uint32 ip, uint16 port);
int map_eraseallipport(void);
void map_addiddb(struct block_list *);
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),...);
int map_foreachiddb(int (*)(DBKey,void*,va_list),...);
struct map_session_data * map_nick2sd(const char*);
diff --git a/src/map/mob.c b/src/map/mob.c
index 69db21af3..b8d833227 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -1766,7 +1766,7 @@ static int mob_ai_hard(int tid, unsigned int tick, int id, intptr data)
if (battle_config.mob_ai&0x20)
map_foreachmob(mob_ai_sub_lazy,tick);
else
- clif_foreachclient(mob_ai_sub_foreachclient,tick);
+ map_foreachpc(mob_ai_sub_foreachclient,tick);
return 0;
}
diff --git a/src/map/pc.c b/src/map/pc.c
index 04b1ea0ef..5f9545651 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -6996,7 +6996,7 @@ int map_day_timer(int tid, unsigned int tick, int id, intptr data)
return 0; //Already day.
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!
intif_GMmessage(tmp_soutput, strlen(tmp_soutput) + 1, 0);
return 0;
@@ -7017,7 +7017,7 @@ int map_night_timer(int tid, unsigned int tick, int id, intptr data)
return 0; //Already nigth.
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...
intif_GMmessage(tmp_soutput, strlen(tmp_soutput) + 1, 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);
clif_disp_onlyself(sd, output, strlen(output));
- clif_foreachclient(duel_showinfo_sub, sd, &p);
+ map_foreachpc(duel_showinfo_sub, sd, &p);
return 0;
}
@@ -7155,7 +7155,7 @@ int duel_leave(const unsigned int did, struct map_session_data* sd)
duel_list[did].members_count--;
if(duel_list[did].members_count == 0) {
- clif_foreachclient(duel_leave_sub, did);
+ map_foreachpc(duel_leave_sub, did);
duel_count--;
}
diff --git a/src/map/pet.c b/src/map/pet.c
index b8a61e093..d80f82aec 100644
--- a/src/map/pet.c
+++ b/src/map/pet.c
@@ -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)
{
- clif_foreachclient(pet_ai_sub_foreachclient,tick);
+ map_foreachpc(pet_ai_sub_foreachclient,tick);
return 0;
}
diff --git a/src/map/script.c b/src/map/script.c
index 4f2bcd1b0..e0c853ba2 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -9151,12 +9151,11 @@ BUILDIN_FUNC(emotion)
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 g_id=va_arg(ap,int);
int flag=va_arg(ap,int);
- TBL_PC *sd = (TBL_PC*)data;
if(!sd || sd->bl.m != m)
return 0;
diff --git a/src/map/unit.c b/src/map/unit.c
index a6e3ec914..1c21c5300 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -1860,7 +1860,7 @@ int unit_free(struct block_list *bl, int clrtype)
duel_reject(sd->duel_invite, sd);
// 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);
guild_send_memberinfoshort(sd,0);
pc_cleareventtimer(sd);