summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/map/atcommand.c191
-rw-r--r--src/map/charcommand.c152
-rw-r--r--src/map/chrif.c40
-rw-r--r--src/map/guild.c51
-rw-r--r--src/map/irc.c30
-rw-r--r--src/map/map.c72
-rw-r--r--src/map/party.c45
-rw-r--r--src/map/script.c219
8 files changed, 394 insertions, 406 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 689780909..588eff87b 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -565,8 +565,9 @@ int atcommand_jump(const int fd, struct map_session_data* sd, const char* comman
int atcommand_who3(const int fd, struct map_session_data* sd, const char* command, const char* message)
{
char temp0[100];
- struct map_session_data *pl_sd, **pl_allsd;
- int i, j, count, users;
+ struct map_session_data *pl_sd;
+ struct s_mapiterator* iter;
+ int j, count;
int pl_GM_level, GM_level;
char match_text[100];
char player_name[NAME_LENGTH];
@@ -584,40 +585,42 @@ int atcommand_who3(const int fd, struct map_session_data* sd, const char* comman
count = 0;
GM_level = pc_isGM(sd);
- pl_allsd = map_getallusers(&users);
- for (i = 0; i < users; i++) {
- if ((pl_sd = pl_allsd[i])) {
- pl_GM_level = pc_isGM(pl_sd);
- if (!((battle_config.hide_GM_session || (pl_sd->sc.option & OPTION_INVISIBLE)) && (pl_GM_level > GM_level))) { // you can look only lower or same level
- memcpy(player_name, pl_sd->status.name, NAME_LENGTH);
- for (j = 0; player_name[j]; j++)
- player_name[j] = TOLOWER(player_name[j]);
- if (strstr(player_name, match_text) != NULL) { // search with no case sensitive
- if (battle_config.who_display_aid > 0 && pc_isGM(sd) >= battle_config.who_display_aid) {
- sprintf(atcmd_output, "(CID:%d/AID:%d) ", pl_sd->status.char_id, pl_sd->status.account_id);
- } else {
- atcmd_output[0]=0;
- }
- //Player name
- sprintf(temp0, msg_txt(333), pl_sd->status.name);
- strcat(atcmd_output,temp0);
- //Player title, if exists
- if (pl_GM_level > 0) {
- //sprintf(temp0, "(%s) ", player_title_txt(pl_GM_level) );
- sprintf(temp0, msg_txt(334), player_title_txt(pl_GM_level) );
- strcat(atcmd_output,temp0);
- }
- //Players Location: map x y
- sprintf(temp0, msg_txt(338), mapindex_id2name(pl_sd->mapindex), pl_sd->bl.x, pl_sd->bl.y);
- strcat(atcmd_output,temp0);
+ iter = mapit_getallusers();
+ for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
+ {
+ pl_GM_level = pc_isGM(pl_sd);
+ if(!( (battle_config.hide_GM_session || (pl_sd->sc.option & OPTION_INVISIBLE)) && pl_GM_level > GM_level ))
+ {// you can look only lower or same level
+ memcpy(player_name, pl_sd->status.name, NAME_LENGTH);
+ for (j = 0; player_name[j]; j++)
+ player_name[j] = TOLOWER(player_name[j]);
+ if (strstr(player_name, match_text) != NULL) { // search with no case sensitive
- clif_displaymessage(fd, atcmd_output);
- count++;
+ if (battle_config.who_display_aid > 0 && pc_isGM(sd) >= battle_config.who_display_aid) {
+ sprintf(atcmd_output, "(CID:%d/AID:%d) ", pl_sd->status.char_id, pl_sd->status.account_id);
+ } else {
+ atcmd_output[0]=0;
+ }
+ //Player name
+ sprintf(temp0, msg_txt(333), pl_sd->status.name);
+ strcat(atcmd_output,temp0);
+ //Player title, if exists
+ if (pl_GM_level > 0) {
+ //sprintf(temp0, "(%s) ", player_title_txt(pl_GM_level) );
+ sprintf(temp0, msg_txt(334), player_title_txt(pl_GM_level) );
+ strcat(atcmd_output,temp0);
}
+ //Players Location: map x y
+ sprintf(temp0, msg_txt(338), mapindex_id2name(pl_sd->mapindex), pl_sd->bl.x, pl_sd->bl.y);
+ strcat(atcmd_output,temp0);
+
+ clif_displaymessage(fd, atcmd_output);
+ count++;
}
}
}
+ mapit_free(iter);
if (count == 0)
clif_displaymessage(fd, msg_txt(28)); // No player found.
@@ -637,8 +640,9 @@ int atcommand_who3(const int fd, struct map_session_data* sd, const char* comman
int atcommand_who2(const int fd, struct map_session_data* sd, const char* command, const char* message)
{
char temp0[100];
- struct map_session_data *pl_sd, **pl_allsd;
- int i, j, count, users;
+ struct map_session_data *pl_sd;
+ struct s_mapiterator* iter;
+ int j, count;
int pl_GM_level, GM_level;
char match_text[100];
char player_name[NAME_LENGTH];
@@ -656,35 +660,37 @@ int atcommand_who2(const int fd, struct map_session_data* sd, const char* comman
count = 0;
GM_level = pc_isGM(sd);
- pl_allsd = map_getallusers(&users);
- for (i = 0; i < users; i++) {
- if ((pl_sd = pl_allsd[i])) {
- pl_GM_level = pc_isGM(pl_sd);
- if (!((battle_config.hide_GM_session || (pl_sd->sc.option & OPTION_INVISIBLE)) && (pl_GM_level > GM_level))) { // you can look only lower or same level
- memcpy(player_name, pl_sd->status.name, NAME_LENGTH);
- for (j = 0; player_name[j]; j++)
- player_name[j] = TOLOWER(player_name[j]);
- if (strstr(player_name, match_text) != NULL) { // search with no case sensitive
- //Players Name
- //sprintf(atcmd_output, "Name: %s ", pl_sd->status.name);
- sprintf(atcmd_output, msg_txt(333), pl_sd->status.name);
- //Player title, if exists
- if (pl_GM_level > 0) {
- //sprintf(temp0, "(%s) ", player_title_txt(pl_GM_level) );
- sprintf(temp0, msg_txt(334), player_title_txt(pl_GM_level) );
- strcat(atcmd_output,temp0);
- }
- //Players Base Level / Job name
- //sprintf(temp0, "| L:%d/%d | Job: %s", pl_sd->status.base_level, pl_sd->status.job_level, job_name(pl_sd->status.class_) );
- sprintf(temp0, msg_txt(337), pl_sd->status.base_level, pl_sd->status.job_level, job_name(pl_sd->status.class_) );
- strcat(atcmd_output,temp0);
- clif_displaymessage(fd, atcmd_output);
- count++;
+ iter = mapit_getallusers();
+ for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
+ {
+ pl_GM_level = pc_isGM(pl_sd);
+ if(!( (battle_config.hide_GM_session || (pl_sd->sc.option & OPTION_INVISIBLE)) && (pl_GM_level > GM_level) ))
+ {// you can look only lower or same level
+ memcpy(player_name, pl_sd->status.name, NAME_LENGTH);
+ for (j = 0; player_name[j]; j++)
+ player_name[j] = TOLOWER(player_name[j]);
+ if (strstr(player_name, match_text) != NULL) { // search with no case sensitive
+ //Players Name
+ //sprintf(atcmd_output, "Name: %s ", pl_sd->status.name);
+ sprintf(atcmd_output, msg_txt(333), pl_sd->status.name);
+ //Player title, if exists
+ if (pl_GM_level > 0) {
+ //sprintf(temp0, "(%s) ", player_title_txt(pl_GM_level) );
+ sprintf(temp0, msg_txt(334), player_title_txt(pl_GM_level) );
+ strcat(atcmd_output,temp0);
}
+ //Players Base Level / Job name
+ //sprintf(temp0, "| L:%d/%d | Job: %s", pl_sd->status.base_level, pl_sd->status.job_level, job_name(pl_sd->status.class_) );
+ sprintf(temp0, msg_txt(337), pl_sd->status.base_level, pl_sd->status.job_level, job_name(pl_sd->status.class_) );
+ strcat(atcmd_output,temp0);
+
+ clif_displaymessage(fd, atcmd_output);
+ count++;
}
}
}
+ mapit_free(iter);
if (count == 0)
clif_displaymessage(fd, msg_txt(28)); // No player found.
@@ -704,8 +710,9 @@ int atcommand_who2(const int fd, struct map_session_data* sd, const char* comman
int atcommand_who(const int fd, struct map_session_data* sd, const char* command, const char* message)
{
char temp0[100];
- struct map_session_data *pl_sd, **pl_allsd;
- int i, j, count, users;
+ struct map_session_data *pl_sd;
+ struct s_mapiterator* iter;
+ int j, count;
int pl_GM_level, GM_level;
char match_text[100];
char player_name[NAME_LENGTH];
@@ -726,44 +733,44 @@ int atcommand_who(const int fd, struct map_session_data* sd, const char* command
count = 0;
GM_level = pc_isGM(sd);
- pl_allsd = map_getallusers(&users);
- for (i = 0; i < users; i++) {
- if ((pl_sd = pl_allsd[i])) {
- pl_GM_level = pc_isGM(pl_sd);
- if (!((battle_config.hide_GM_session || (pl_sd->sc.option & OPTION_INVISIBLE)) && (pl_GM_level > GM_level))) { // you can look only lower or same level
- memcpy(player_name, pl_sd->status.name, NAME_LENGTH);
- for (j = 0; player_name[j]; j++)
- player_name[j] = TOLOWER(player_name[j]);
- if (strstr(player_name, match_text) != NULL) { // search with no case sensitive
- g = guild_search(pl_sd->status.guild_id);
- p = party_search(pl_sd->status.party_id);
- //Players Name
- //sprintf(atcmd_output, "Name: %s ", pl_sd->status.name);
- sprintf(atcmd_output, msg_txt(333), pl_sd->status.name);
- //Player title, if exists
- if (pl_GM_level > 0) {
- //sprintf(temp0, "(%s) ", player_title_txt(pl_GM_level) );
- sprintf(temp0, msg_txt(334), player_title_txt(pl_GM_level) );
- strcat(atcmd_output,temp0);
- }
- //Players Party if exists
- if (p != NULL) {
- //sprintf(temp0," | Party: '%s'", p->name);
- sprintf(temp0, msg_txt(335), p->party.name);
- strcat(atcmd_output,temp0);
- }
- //Players Guild if exists
- if (g != NULL) {
- //sprintf(temp0," | Guild: '%s'", g->name);
- sprintf(temp0, msg_txt(336), g->name);
- strcat(atcmd_output,temp0);
- }
- clif_displaymessage(fd, atcmd_output);
- count++;
+
+ iter = mapit_getallusers();
+ for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
+ {
+ pl_GM_level = pc_isGM(pl_sd);
+ if(!( (battle_config.hide_GM_session || (pl_sd->sc.option & OPTION_INVISIBLE)) && pl_GM_level > GM_level ))
+ {// you can look only lower or same level
+ memcpy(player_name, pl_sd->status.name, NAME_LENGTH);
+ for (j = 0; player_name[j]; j++)
+ player_name[j] = TOLOWER(player_name[j]);
+ if (strstr(player_name, match_text) != NULL) { // search with no case sensitive
+ g = guild_search(pl_sd->status.guild_id);
+ p = party_search(pl_sd->status.party_id);
+ //Players Name
+ sprintf(atcmd_output, msg_txt(333), pl_sd->status.name);
+ //Player title, if exists
+ if (pl_GM_level > 0) {
+ sprintf(temp0, msg_txt(334), player_title_txt(pl_GM_level) );
+ strcat(atcmd_output,temp0);
+ }
+ //Players Party if exists
+ if (p != NULL) {
+ //sprintf(temp0," | Party: '%s'", p->name);
+ sprintf(temp0, msg_txt(335), p->party.name);
+ strcat(atcmd_output,temp0);
+ }
+ //Players Guild if exists
+ if (g != NULL) {
+ //sprintf(temp0," | Guild: '%s'", g->name);
+ sprintf(temp0, msg_txt(336), g->name);
+ strcat(atcmd_output,temp0);
}
+ clif_displaymessage(fd, atcmd_output);
+ count++;
}
}
}
+ mapit_free(iter);
if (count == 0)
clif_displaymessage(fd, msg_txt(28)); // No player found.
diff --git a/src/map/charcommand.c b/src/map/charcommand.c
index 2e8c90b89..8971df7c3 100644
--- a/src/map/charcommand.c
+++ b/src/map/charcommand.c
@@ -409,51 +409,6 @@ int charcommand_save(const int fd, struct map_session_data* sd, const char* comm
}
/*==========================================
- *
- *------------------------------------------*/
-//** Character Stats All by fritz
-int charcommand_stats_all(const int fd, struct map_session_data* sd, const char* command, const char* message)
-{
- char output[1024], gmlevel[1024];
- int i;
- int count, users;
- struct map_session_data *pl_sd, **pl_allsd;
-
- memset(output, '\0', sizeof(output));
- memset(gmlevel, '\0', sizeof(gmlevel));
-
- count = 0;
- pl_allsd = map_getallusers(&users);
- for(i = 0; i < users; i++) {
- if ((pl_sd = pl_allsd[i]))
- {
- if (pc_isGM(pl_sd) > 0)
- sprintf(gmlevel, "| GM Lvl: %d", pc_isGM(pl_sd));
- else
- sprintf(gmlevel, " ");
-
- sprintf(output, "Name: %s | BLvl: %d | Job: %s (Lvl: %d) | HP: %d/%d | SP: %d/%d", pl_sd->status.name, pl_sd->status.base_level, job_name(pl_sd->status.class_), pl_sd->status.job_level, pl_sd->status.hp, pl_sd->status.max_hp, pl_sd->status.sp, pl_sd->status.max_sp);
- clif_displaymessage(fd, output);
- sprintf(output, "STR: %d | AGI: %d | VIT: %d | INT: %d | DEX: %d | LUK: %d | Zeny: %d %s", pl_sd->status.str, pl_sd->status.agi, pl_sd->status.vit, pl_sd->status.int_, pl_sd->status.dex, pl_sd->status.luk, pl_sd->status.zeny, gmlevel);
- clif_displaymessage(fd, output);
- clif_displaymessage(fd, "--------");
- count++;
- }
- }
-
- if (count == 0)
- clif_displaymessage(fd, msg_txt(28)); // No player found.
- else if (count == 1)
- clif_displaymessage(fd, msg_txt(29)); // 1 player found.
- else {
- sprintf(output, msg_txt(30), count); // %d players found.
- clif_displaymessage(fd, output);
- }
-
- return 0;
-}
-
-/*==========================================
* CharSpiritBall Function by PalasX
*------------------------------------------*/
int charcommand_spiritball(const int fd, struct map_session_data* sd,const char* command, const char* message)
@@ -790,63 +745,68 @@ int charcommand_item(const int fd, struct map_session_data* sd, const char* comm
(item_data = itemdb_exists(atoi(item_name))) != NULL)
item_id = item_data->nameid;
- if (item_id >= 500) {
- get_count = number;
- // check pet egg
- pet_id = search_petDB_index(item_id, PET_EGG);
- if (item_data->type == 4 || item_data->type == 5 ||
- item_data->type == 7 || item_data->type == 8) {
- get_count = 1;
- }
- if ((pl_sd = map_nick2sd(character)) != NULL) {
- if (pc_isGM(sd) >= pc_isGM(pl_sd)) { // you can look items only lower or same level
- for (i = 0; i < number; i += get_count) {
- // if pet egg
- if (pet_id >= 0) {
- pl_sd->catch_target_class = pet_db[pet_id].class_;
- intif_create_pet(pl_sd->status.account_id, pl_sd->status.char_id,
- (short)pet_db[pet_id].class_, (short)mob_db(pet_db[pet_id].class_)->lv,
- (short)pet_db[pet_id].EggID, 0, (short)pet_db[pet_id].intimate,
- 100, 0, 1, pet_db[pet_id].jname);
- // if not pet egg
- } else {
- memset(&item_tmp, 0, sizeof(item_tmp));
- item_tmp.nameid = item_id;
- item_tmp.identify = 1;
-
- if ((flag = pc_additem(pl_sd, &item_tmp, get_count)))
- clif_additem(pl_sd, 0, 0, flag);
- }
- }
+ if (item_id < 500) {
+ clif_displaymessage(fd, msg_txt(19)); // Invalid item ID or name.
+ return -1;
+ }
- //Logs (A)dmins items [Lupus]
- if(log_config.enable_logs&0x400)
- log_pick_pc(sd, "A", item_tmp.nameid, number, &item_tmp);
+ get_count = number;
+ // check pet egg
+ pet_id = search_petDB_index(item_id, PET_EGG);
+ if (item_data->type == 4 || item_data->type == 5 ||
+ item_data->type == 7 || item_data->type == 8) {
+ get_count = 1;
+ }
- clif_displaymessage(fd, msg_txt(18)); // Item created.
- } else {
- clif_displaymessage(fd, msg_txt(81)); // Your GM level don't authorise you to do this action on this player.
- return -1;
- }
- } else if(/* from jA's @giveitem */strcmpi(character,"all")==0 || strcmpi(character,"everyone")==0){
- struct map_session_data **pl_allsd;
- int users;
- pl_allsd = map_getallusers(&users);
- for (i = 0; i < users; i++) {
- if ((pl_sd = pl_allsd[i])) {
- charcommand_giveitem_sub(pl_sd,item_data,number);
- snprintf(tmp_cmdoutput, sizeof(tmp_cmdoutput), "You got %s %d.", item_name,number);
- clif_displaymessage(pl_sd->fd, tmp_cmdoutput);
+ if ((pl_sd = map_nick2sd(character)) == NULL)
+ {
+ if (pc_isGM(sd) < pc_isGM(pl_sd))
+ {// you can give items only to lower or same level
+ clif_displaymessage(fd, msg_txt(81)); // Your GM level don't authorise you to do this action on this player.
+ return -1;
+ }
+ else
+ {
+ for (i = 0; i < number; i += get_count) {
+ // if pet egg
+ if (pet_id >= 0) {
+ pl_sd->catch_target_class = pet_db[pet_id].class_;
+ intif_create_pet(pl_sd->status.account_id, pl_sd->status.char_id,
+ (short)pet_db[pet_id].class_, (short)mob_db(pet_db[pet_id].class_)->lv,
+ (short)pet_db[pet_id].EggID, 0, (short)pet_db[pet_id].intimate,
+ 100, 0, 1, pet_db[pet_id].jname);
+ // if not pet egg
+ } else {
+ memset(&item_tmp, 0, sizeof(item_tmp));
+ item_tmp.nameid = item_id;
+ item_tmp.identify = 1;
+
+ if ((flag = pc_additem(pl_sd, &item_tmp, get_count)))
+ clif_additem(pl_sd, 0, 0, flag);
}
}
- snprintf(tmp_cmdoutput, sizeof(tmp_cmdoutput), "%s received %s %d.","Everyone",item_name,number);
- clif_displaymessage(fd, tmp_cmdoutput);
- } else {
- clif_displaymessage(fd, msg_txt(3)); // Character not found.
- return -1;
+
+ //Logs (A)dmins items [Lupus]
+ if(log_config.enable_logs&0x400)
+ log_pick_pc(sd, "A", item_tmp.nameid, number, &item_tmp);
+
+ clif_displaymessage(fd, msg_txt(18)); // Item created.
+ }
+ } else
+ if (strcmpi(character,"all")==0 || strcmpi(character,"everyone")==0) {
+ struct s_mapiterator* iter = mapit_getallusers();
+ for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
+ {
+ charcommand_giveitem_sub(pl_sd,item_data,number);
+ snprintf(tmp_cmdoutput, sizeof(tmp_cmdoutput), "You got %s %d.", item_name,number);
+ clif_displaymessage(pl_sd->fd, tmp_cmdoutput);
}
+ mapit_free(iter);
+
+ snprintf(tmp_cmdoutput, sizeof(tmp_cmdoutput), "%s received %s %d.","Everyone",item_name,number);
+ clif_displaymessage(fd, tmp_cmdoutput);
} else {
- clif_displaymessage(fd, msg_txt(19)); // Invalid item ID or name.
+ clif_displaymessage(fd, msg_txt(3)); // Character not found.
return -1;
}
diff --git a/src/map/chrif.c b/src/map/chrif.c
index c5ee538ea..e88ee3c5d 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -1326,12 +1326,16 @@ int ping_char_server(int tid, unsigned int tick, int id, int data)
// unused
int send_usercount_tochar(int tid, unsigned int tick, int id, int data)
{
- int count;
+ int count = 0;
+ struct s_mapiterator* iter;
chrif_check(-1);
-
- map_getallusers(&count);
-
+
+ iter = mapit_getallusers();
+ for( mapit_first(iter); mapit_exists(iter); mapit_next(iter) )
+ count++;
+ mapit_free(iter);
+
WFIFOHEAD(char_fd,4);
WFIFOW(char_fd,0) = 0x2afe;
WFIFOW(char_fd,2) = count;
@@ -1345,22 +1349,32 @@ int send_usercount_tochar(int tid, unsigned int tick, int id, int data)
*------------------------------------------*/
int send_users_tochar(void)
{
- int count, users=0, i;
- struct map_session_data **all_sd;
+ int users = 0, i = 0;
+ struct map_session_data* sd;
+ struct s_mapiterator* iter;
chrif_check(-1);
- all_sd = map_getallusers(&count);
+ // get user count (TODO: improve this)
+ iter = mapit_getallusers();
+ for( mapit_first(iter); mapit_exists(iter); mapit_next(iter) )
+ users++;
+ mapit_free(iter);
+
+ // build the packet
WFIFOHEAD(char_fd, 6+8*users);
WFIFOW(char_fd,0) = 0x2aff;
- for (i = 0; i < count; i++) {
- WFIFOL(char_fd,6+8*users) = all_sd[i]->status.account_id;
- WFIFOL(char_fd,6+8*users+4) = all_sd[i]->status.char_id;
- users++;
+ iter = mapit_getallusers();
+ for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) )
+ {
+ WFIFOL(char_fd,6+8*i) = sd->status.account_id;
+ WFIFOL(char_fd,6+8*i+4) = sd->status.char_id;
+ i++;
}
- WFIFOW(char_fd,2) = 6 + 8 * users;
+ mapit_free(iter);
+ WFIFOW(char_fd,2) = 6 + 8*users;
WFIFOW(char_fd,4) = users;
- WFIFOSET(char_fd,6+8*users);
+ WFIFOSET(char_fd, 6+8*users);
return 0;
}
diff --git a/src/map/guild.c b/src/map/guild.c
index b5cb708ee..a9670400a 100644
--- a/src/map/guild.c
+++ b/src/map/guild.c
@@ -470,43 +470,48 @@ int guild_npc_request_info(int guild_id,const char *event)
// 所属キャラの確認
int guild_check_member(struct guild *g)
{
- int i, j, users;
- struct map_session_data *sd, **all_sd;
+ int i;
+ struct map_session_data *sd;
+ struct s_mapiterator* iter;
nullpo_retr(0, g);
- all_sd = map_getallusers(&users);
-
- for(i=0;i<users;i++){
- sd=all_sd[i];
- if(sd->status.guild_id==g->guild_id){
- j=guild_getindex(g,sd->status.account_id,sd->status.char_id);
- if (j < 0) {
- sd->status.guild_id=0;
- sd->state.guild_sent=0;
- sd->guild_emblem_id=0;
- ShowWarning("guild: check_member %d[%s] is not member\n",sd->status.account_id,sd->status.name);
- }
+ iter = mapit_getallusers();
+ for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) )
+ {
+ if( sd->status.guild_id != g->guild_id )
+ continue;
+
+ i = guild_getindex(g,sd->status.account_id,sd->status.char_id);
+ if (i < 0) {
+ sd->status.guild_id=0;
+ sd->state.guild_sent=0;
+ sd->guild_emblem_id=0;
+ ShowWarning("guild: check_member %d[%s] is not member\n",sd->status.account_id,sd->status.name);
}
}
+ mapit_free(iter);
+
return 0;
}
+
// 情報所得失敗(そのIDのキャラを全部未所属にする)
int guild_recv_noinfo(int guild_id)
{
- int i, users;
- struct map_session_data *sd, **all_sd;
+ struct map_session_data *sd;
+ struct s_mapiterator* iter;
- all_sd = map_getallusers(&users);
-
- for(i=0;i<users;i++){
- if((sd=all_sd[i])){
- if(sd->status.guild_id==guild_id)
- sd->status.guild_id=0;
- }
+ iter = mapit_getallusers();
+ for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) )
+ {
+ if( sd->status.guild_id == guild_id )
+ sd->status.guild_id = 0; // erase guild
}
+ mapit_free(iter);
+
return 0;
}
+
// 情報所得
int guild_recv_info(struct guild *sg)
{
diff --git a/src/map/irc.c b/src/map/irc.c
index 88ada1311..f217d9de2 100644
--- a/src/map/irc.c
+++ b/src/map/irc.c
@@ -184,8 +184,6 @@ void irc_parse_sub(int fd, char *incoming_string)
int i=0;
- struct map_session_data **allsd;
-
memset(source,'\0',256);
memset(command,'\0',256);
memset(target,'\0',256);
@@ -266,25 +264,41 @@ void irc_parse_sub(int fd, char *incoming_string)
else // Number of users online
if(strcmpi(cmdname,"users")==0)
{
- int users;
- map_getallusers(&users);
+ int users = 0;
+ struct s_mapiterator* iter;
+
+ iter = mapit_getallusers();
+ for( mapit_first(iter); mapit_exists(iter); mapit_next(iter) )
+ users++;
+ mapit_free(iter);
+
sprintf(send_string, "PRIVMSG %s :Users Online: %d", irc_channel, users);
irc_send(send_string);
}
else // List all users online
if(strcmpi(cmdname,"who")==0)
{
- int users;
- allsd = map_getallusers(&users);
+ int users = 0;
+ struct s_mapiterator* iter;
+ struct map_session_data* sd;
+
+ iter = mapit_getallusers();
+ for( mapit_first(iter); mapit_exists(iter); mapit_next(iter) )
+ users++;
+ mapit_free(iter);
+
if(users > 0)
{
sprintf(send_string,"NOTICE %s :%d Users Online",source_nick,users);
irc_send(send_string);
- for(i = 0; i < users; i++)
+
+ iter = mapit_getallusers();
+ for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) )
{
- sprintf(send_string,"NOTICE %s :Name: \"%s\"",source_nick,allsd[i]->status.name);
+ sprintf(send_string,"NOTICE %s :Name: \"%s\"",source_nick,sd->status.name);
irc_send(send_string);
}
+ mapit_free(iter);
}
else
{
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();
diff --git a/src/map/party.c b/src/map/party.c
index fedd5ce1e..7928a3ad3 100644
--- a/src/map/party.c
+++ b/src/map/party.c
@@ -159,30 +159,29 @@ int party_request_info(int party_id)
}
/// Checks if each char having a party actually belongs to that party.
-/// If check fails, the char is marked as 'not in a party'.
+/// If check fails, the char gets marked as 'not in a party'.
int party_check_member(struct party *p)
{
- int i, users;
- struct map_session_data *sd, **all_sd;
+ int i;
+ struct map_session_data *sd;
+ struct s_mapiterator* iter;
nullpo_retr(0, p);
- all_sd = map_getallusers(&users);
-
- for(i=0;i<users;i++)
+ iter = mapit_getallusers();
+ for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) )
{
- sd = all_sd[i];
- if( sd && sd->status.party_id == p->party_id )
+ if( sd->status.party_id != p->party_id )
+ continue;
+
+ ARR_FIND( 0, MAX_PARTY, i, p->member[i].account_id == sd->status.account_id && p->member[i].char_id == sd->status.char_id );
+ if( i == MAX_PARTY )
{
- int j;
- ARR_FIND( 0, MAX_PARTY, j, p->member[j].account_id == sd->status.account_id && p->member[j].char_id == sd->status.char_id );
- if( j == MAX_PARTY )
- {
- ShowWarning("party_check_member: '%s' (acc:%d) is not member of party '%s' (id:%d)\n",sd->status.name,sd->status.account_id,p->name,p->party_id);
- sd->status.party_id = 0;
- }
+ ShowWarning("party_check_member: '%s' (acc:%d) is not member of party '%s' (id:%d)\n",sd->status.name,sd->status.account_id,p->name,p->party_id);
+ sd->status.party_id = 0;
}
}
+ mapit_free(iter);
return 0;
}
@@ -190,15 +189,17 @@ int party_check_member(struct party *p)
/// Marks all chars belonging to this party as 'not in a party'.
int party_recv_noinfo(int party_id)
{
- int i, users;
- struct map_session_data *sd, **all_sd;
+ struct map_session_data *sd;
+ struct s_mapiterator* iter;
- all_sd = map_getallusers(&users);
-
- for(i=0;i<users;i++){
- if((sd = all_sd[i]) && sd->status.party_id==party_id)
- sd->status.party_id=0;
+ iter = mapit_getallusers();
+ for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) )
+ {
+ if( sd->status.party_id == party_id )
+ sd->status.party_id = 0; // erase party
}
+ mapit_free(iter);
+
return 0;
}
diff --git a/src/map/script.c b/src/map/script.c
index d10d8c935..3294455a1 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -4318,32 +4318,26 @@ BUILDIN_FUNC(areawarp)
*------------------------------------------*/
BUILDIN_FUNC(warpchar)
{
- int x,y,a,i;
+ int x,y,a;
const char *str;
- TBL_PC *sd, **pl_allsd;
- int users;
+ TBL_PC *sd;
str=script_getstr(st,2);
x=script_getnum(st,3);
y=script_getnum(st,4);
a=script_getnum(st,5);
-
- pl_allsd = map_getallusers(&users);
-
- for(i=0; i<users; i++) {
- sd = pl_allsd[i];
- if(sd->status.char_id == a) {
-
- if(strcmp(str, "Random") == 0)
- pc_randomwarp(sd, 3);
-
- else if(strcmp(str, "SavePoint") == 0)
- pc_setpos(sd, sd->status.save_point.map,sd->status.save_point.x, sd->status.save_point.y, 3);
-
- else
- pc_setpos(sd, mapindex_name2id(str), x, y, 3);
- }
- }
+
+ sd = map_charid2sd(a);
+ if( sd == NULL )
+ return 0;
+
+ if(strcmp(str, "Random") == 0)
+ pc_randomwarp(sd, 3);
+ else
+ if(strcmp(str, "SavePoint") == 0)
+ pc_setpos(sd, sd->status.save_point.map,sd->status.save_point.x, sd->status.save_point.y, 3);
+ else
+ pc_setpos(sd, mapindex_name2id(str), x, y, 3);
return 0;
}
@@ -4459,87 +4453,63 @@ BUILDIN_FUNC(warpguild)
int x,y;
unsigned short mapindex;
const char *str;
- int g;
- int i;
- TBL_PC *pl_sd, **pl_allsd;
- int users;
+ int gid;
TBL_PC *sd;
+ TBL_PC *pl_sd;
+ struct guild* g;
+ struct s_mapiterator* iter;
+ int type;
+
str=script_getstr(st,2);
x=script_getnum(st,3);
y=script_getnum(st,4);
- g=script_getnum(st,5);
+ gid=script_getnum(st,5);
+
sd=script_rid2sd(st);
if( sd == NULL )
return 0;
-
+ g = guild_search(gid);
+ if( g == NULL )
+ return 0;
if(map[sd->bl.m].flag.noreturn || map[sd->bl.m].flag.nowarpto)
return 0;
- if(g < 1)
- return 0;
-
- pl_allsd = map_getallusers(&users);
+ type = ( strcmp(str,"Random")==0 ) ? 0
+ : ( strcmp(str,"SavePointAll")==0 ) ? 1
+ : ( strcmp(str,"SavePoint")==0 ) ? 2
+ : 3;
+ if( type == 3 )
+ mapindex = mapindex_name2id(str);
- if(strcmp(str,"Random")==0)
+ iter = mapit_getallusers();
+ for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
{
-
- for (i = 0; i < users; i++)
+ if( pl_sd->status.guild_id != gid )
+ continue;
+
+ switch( type )
{
- if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
- {
- if(map[pl_sd->bl.m].flag.nowarp)
- continue;
+ case 0: // Random
+ if(!map[pl_sd->bl.m].flag.nowarp)
pc_randomwarp(pl_sd,3);
- }
- }
- }
- else if(strcmp(str,"SavePointAll")==0)
- {
- if(map[sd->bl.m].flag.noreturn)
- return 0;
-
- for (i = 0; i < users; i++)
- {
- if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
- {
- if(map[pl_sd->bl.m].flag.noreturn)
- continue;
+ break;
+ case 1: // SavePointAll
+ if(!map[pl_sd->bl.m].flag.noreturn)
pc_setpos(pl_sd,pl_sd->status.save_point.map,pl_sd->status.save_point.x,pl_sd->status.save_point.y,3);
- }
- }
- }
- else if(strcmp(str,"SavePoint")==0)
- {
- if(map[sd->bl.m].flag.noreturn)
- return 0;
-
- mapindex=sd->status.save_point.map;
- x=sd->status.save_point.x;
- y=sd->status.save_point.y;
- for (i = 0; i < users; i++)
- {
- if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
- {
- if(map[pl_sd->bl.m].flag.noreturn)
- continue;
- pc_setpos(pl_sd,mapindex,x,y,3);
- }
- }
- }
- else
- {
- mapindex = mapindex_name2id(str);
- for (i = 0; i < users; i++)
- {
- if ((pl_sd = pl_allsd[i]) && pl_sd->status.guild_id == g)
- {
- if(map[pl_sd->bl.m].flag.noreturn || map[pl_sd->bl.m].flag.nowarp)
- continue;
+ break;
+ case 2: // SavePoint
+ if(!map[pl_sd->bl.m].flag.noreturn)
+ pc_setpos(pl_sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,3);
+ break;
+ case 3: // m,x,y
+ if(!map[pl_sd->bl.m].flag.noreturn && !map[pl_sd->bl.m].flag.nowarp)
pc_setpos(pl_sd,mapindex,x,y,3);
- }
+ break;
}
}
+ mapit_free(iter);
+
return 0;
}
/*==========================================
@@ -7947,24 +7917,25 @@ BUILDIN_FUNC(getusers)
*------------------------------------------*/
BUILDIN_FUNC(getusersname)
{
- TBL_PC *sd, *pl_sd = NULL, **pl_allsd;
- int i=0,disp_num=1, users;
+ TBL_PC *sd, *pl_sd;
+ int i=0,disp_num=1;
+ struct s_mapiterator* iter;
- sd = script_rid2sd(st);
+ sd = script_rid2sd(st);
if (!sd) return 0;
- pl_allsd = map_getallusers(&users);
-
- for (i=0;i<users;i++)
+ iter = mapit_getallusers();
+ for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
{
- pl_sd = pl_allsd[i];
- if( !(battle_config.hide_GM_session && pc_isGM(pl_sd)) )
- {
- if((disp_num++)%10==0)
- clif_scriptnext(sd,st->oid);
- clif_scriptmes(sd,st->oid,pl_sd->status.name);
- }
+ if( battle_config.hide_GM_session && pc_isGM(pl_sd) )
+ continue; // skip hidden GMs
+
+ if((disp_num++)%10==0)
+ clif_scriptnext(sd,st->oid);
+ clif_scriptmes(sd,st->oid,pl_sd->status.name);
}
+ mapit_free(iter);
+
return 0;
}
/*==========================================
@@ -9023,34 +8994,37 @@ BUILDIN_FUNC(removemapflag)
BUILDIN_FUNC(pvpon)
{
- int m,i,users;
+ int m;
const char *str;
- TBL_PC *pl_sd=NULL, **pl_allsd;
+ TBL_PC* sd = NULL;
+ struct s_mapiterator* iter;
- str=script_getstr(st,2);
+ str = script_getstr(st,2);
m = map_mapname2mapid(str);
- if(m >= 0 && !map[m].flag.pvp) {
- map[m].flag.pvp = 1;
- clif_send0199(m,1);
+ if( m < 0 || map[m].flag.pvp )
+ return 0; // nothing to do
- if(battle_config.pk_mode) // disable ranking functions if pk_mode is on [Valaris]
- return 0;
+ map[m].flag.pvp = 1;
+ clif_send0199(m,1);
- pl_allsd = map_getallusers(&users);
-
- for(i=0;i<users;i++)
- {
- if ((pl_sd = pl_allsd[i]) && m == pl_sd->bl.m && pl_sd->pvp_timer == -1)
- {
- pl_sd->pvp_timer=add_timer(gettick()+200,pc_calc_pvprank_timer,pl_sd->bl.id,0);
- pl_sd->pvp_rank=0;
- pl_sd->pvp_lastusers=0;
- pl_sd->pvp_point=5;
- pl_sd->pvp_won = 0;
- pl_sd->pvp_lost = 0;
- }
- }
+ if(battle_config.pk_mode) // disable ranking functions if pk_mode is on [Valaris]
+ return 0;
+
+ iter = mapit_getallusers();
+ for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) )
+ {
+ if( sd->bl.m != m || sd->pvp_timer != -1 )
+ continue; // not applicable
+
+ sd->pvp_timer = add_timer(gettick()+200,pc_calc_pvprank_timer,sd->bl.id,0);
+ sd->pvp_rank = 0;
+ sd->pvp_lastusers = 0;
+ sd->pvp_point = 5;
+ sd->pvp_won = 0;
+ sd->pvp_lost = 0;
}
+ mapit_free(iter);
+
return 0;
}
@@ -10664,20 +10638,19 @@ BUILDIN_FUNC(dispbottom)
*------------------------------------------*/
BUILDIN_FUNC(recovery)
{
- TBL_PC *sd, **all_sd;
- int i = 0, users;
+ TBL_PC* sd;
+ struct s_mapiterator* iter;
- all_sd = map_getallusers(&users);
-
- for (i = 0; i < users; i++)
+ iter = mapit_getallusers();
+ for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) )
{
- sd = all_sd[i];
if(pc_isdead(sd))
status_revive(&sd->bl, 100, 100);
else
status_percent_heal(&sd->bl, 100, 100);
clif_displaymessage(sd->fd,"You have been recovered!");
}
+ mapit_free(iter);
return 0;
}
/*==========================================