From 205b602a893cb84e99ab61bafe2b84e0338acf9b Mon Sep 17 00:00:00 2001 From: Haru Date: Sun, 25 Aug 2019 18:41:36 +0200 Subject: Fix several issues caused by the nick partial match feature, when enabled. Partial match is now disabled in all the internal (source) and script lookups, while it's enabled for the lookups requested by atcommands and client. Signed-off-by: Haru --- src/map/atcommand.c | 50 +++++++++++++++++++++++++------------------------- src/map/clif.c | 14 +++++++------- src/map/guild.c | 2 +- src/map/map.c | 23 +++++++++++------------ src/map/map.h | 2 +- src/map/script.c | 16 ++++++++-------- 6 files changed, 53 insertions(+), 54 deletions(-) (limited to 'src') diff --git a/src/map/atcommand.c b/src/map/atcommand.c index b472694c4..968a4282a 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -511,7 +511,7 @@ ACMD(where) return false; } - pl_sd = map->nick2sd(atcmd_player_name); + pl_sd = map->nick2sd(atcmd_player_name, true); if (pl_sd == NULL || strncmp(pl_sd->status.name, atcmd_player_name, NAME_LENGTH) != 0 || (pc_has_permission(pl_sd, PC_PERM_HIDE_SESSION) && pc_get_group_level(pl_sd) > pc_get_group_level(sd) && !pc_has_permission(sd, PC_PERM_WHO_DISPLAY_AID)) @@ -548,7 +548,7 @@ ACMD(jumpto) return false; } - if ((pl_sd=map->nick2sd(message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { + if ((pl_sd=map->nick2sd(message, true)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -2904,7 +2904,7 @@ ACMD(recall) return false; } - if ((pl_sd=map->nick2sd(message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { + if ((pl_sd=map->nick2sd(message, true)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -3229,7 +3229,7 @@ ACMD(kick) return false; } - if ((pl_sd=map->nick2sd(message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { + if ((pl_sd=map->nick2sd(message, true)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -4364,7 +4364,7 @@ ACMD(nuke) return false; } - if ((pl_sd = map->nick2sd(atcmd_player_name)) != NULL) { + if ((pl_sd = map->nick2sd(atcmd_player_name, true)) != NULL) { if (pc_get_group_level(sd) >= pc_get_group_level(pl_sd)) { // you can kill only lower or same GM level skill->castend_nodamage_id(&pl_sd->bl, &pl_sd->bl, NPC_SELFDESTRUCTION, 99, timer->gettick(), 0); clif->message(fd, msg_fd(fd,109)); // Player has been nuked! @@ -4684,7 +4684,7 @@ ACMD(jail) return false; } - if ((pl_sd = map->nick2sd(atcmd_player_name)) == NULL) { + if ((pl_sd = map->nick2sd(atcmd_player_name, true)) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -4736,7 +4736,7 @@ ACMD(unjail) return false; } - if ((pl_sd = map->nick2sd(atcmd_player_name)) == NULL) { + if ((pl_sd = map->nick2sd(atcmd_player_name, true)) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -4815,7 +4815,7 @@ ACMD(jailfor) return false; } - if ((pl_sd = map->nick2sd(atcmd_player_name)) == NULL) { + if ((pl_sd = map->nick2sd(atcmd_player_name, true)) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -5346,7 +5346,7 @@ ACMD(follow) return true; } - if ((pl_sd = map->nick2sd(message)) == NULL) { + if ((pl_sd = map->nick2sd(message, true)) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -5596,7 +5596,7 @@ ACMD(useskill) if (!strcmp(target,"self")) pl_sd = sd; //quick keyword - else if ((pl_sd = map->nick2sd(target)) == NULL) { + else if ((pl_sd = map->nick2sd(target, true)) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -5664,7 +5664,7 @@ ACMD(skilltree) return false; } - if ( (pl_sd = map->nick2sd(target)) == NULL ) { + if ( (pl_sd = map->nick2sd(target, true)) == NULL ) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -5734,7 +5734,7 @@ ACMD(marry) return false; } - if ((pl_sd = map->nick2sd(player_name)) == NULL) { + if ((pl_sd = map->nick2sd(player_name, true)) == NULL) { clif->message(fd, msg_fd(fd,3)); return false; } @@ -5864,7 +5864,7 @@ ACMD(changegm) return false; } - if ((pl_sd=map->nick2sd(message)) == NULL || pl_sd->status.guild_id != sd->status.guild_id) { + if ((pl_sd=map->nick2sd(message, true)) == NULL || pl_sd->status.guild_id != sd->status.guild_id) { clif->message(fd, msg_fd(fd,1184)); // Target character must be online and be a guild member. return false; } @@ -5885,7 +5885,7 @@ ACMD(changeleader) return false; } - if (party->changeleader(sd, map->nick2sd(message))) + if (party->changeleader(sd, map->nick2sd(message, true))) return true; return false; } @@ -6349,7 +6349,7 @@ ACMD(mobsearch) } if (mob_id == atoi(mob_name)) { strcpy(mob_name,mob->db(mob_id)->jname); // DEFAULT_MOB_JNAME - //strcpy(mob_name,mob_db(mob_id)->name); // DEFAULT_MOB_NAME + //strcpy(mob_name,mob->db(mob_id)->name); // DEFAULT_MOB_NAME } snprintf(atcmd_output, sizeof atcmd_output, msg_fd(fd,1220), mob_name, mapindex_id2name(sd->mapindex)); // Mob Search... %s %s @@ -6651,7 +6651,7 @@ ACMD(trade) return false; } - if ((pl_sd = map->nick2sd(message)) == NULL) { + if ((pl_sd = map->nick2sd(message, true)) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -6695,7 +6695,7 @@ ACMD(unmute) return false; } - if ((pl_sd = map->nick2sd(message)) == NULL) { + if ((pl_sd = map->nick2sd(message, true)) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -6775,7 +6775,7 @@ ACMD(mute) return false; } - if ((pl_sd = map->nick2sd(atcmd_player_name)) == NULL) { + if ((pl_sd = map->nick2sd(atcmd_player_name, true)) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -7072,7 +7072,7 @@ ACMD(showmobs) if (mob_id == atoi(mob_name)) { strcpy(mob_name,mob->db(mob_id)->jname); // DEFAULT_MOB_JNAME - //strcpy(mob_name,mob_db(mob_id)->name); // DEFAULT_MOB_NAME + //strcpy(mob_name,mob->db(mob_id)->name); // DEFAULT_MOB_NAME } snprintf(atcmd_output, sizeof atcmd_output, msg_fd(fd,1252), // Mob Search... %s %s @@ -7985,7 +7985,7 @@ ACMD(showdelay) ACMD(invite) { unsigned int did = sd->duel_group; - struct map_session_data *target_sd = map->nick2sd(message); + struct map_session_data *target_sd = map->nick2sd(message, true); if (did == 0) { @@ -8058,7 +8058,7 @@ ACMD(duel) } duel->create(sd, maxpl); } else { - struct map_session_data *target_sd = map->nick2sd(message); + struct map_session_data *target_sd = map->nick2sd(message, true); if (target_sd != NULL) { unsigned int newduel; if ((newduel = duel->create(sd, 2)) != -1) { @@ -8203,7 +8203,7 @@ ACMD(clone) return false; } - if ((pl_sd=map->nick2sd(message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { + if ((pl_sd=map->nick2sd(message, true)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -9321,7 +9321,7 @@ ACMD(channel) return false; } - if (sub4[0] == '\0' || (pl_sd = map->nick2sd(sub4)) == NULL) { + if (sub4[0] == '\0' || (pl_sd = map->nick2sd(sub4, true)) == NULL) { safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1434), sub4);// Player '%s' was not found clif->message(fd, atcmd_output); return false; @@ -9368,7 +9368,7 @@ ACMD(channel) clif->message(fd, atcmd_output); return false; } - if (sub4[0] == '\0' || (pl_sd = map->nick2sd(sub4)) == NULL) { + if (sub4[0] == '\0' || (pl_sd = map->nick2sd(sub4, true)) == NULL) { safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd,1434), sub4);// Player '%s' was not found clif->message(fd, atcmd_output); return false; @@ -10463,7 +10463,7 @@ static bool atcommand_exec(const int fd, struct map_session_data *sd, const char return true; } - ssd = map->nick2sd(charname); + ssd = map->nick2sd(charname, true); if (ssd == NULL) { sprintf(output, msg_fd(fd,1389), command); // %s failed. Player not found. clif->message(fd, output); diff --git a/src/map/clif.c b/src/map/clif.c index 33c003321..0748558fa 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -6458,7 +6458,7 @@ static void clif_wis_message(int fd, const char *nick, const char *mes, int mes_ safestrncpy(WFIFOP(fd,28), mes, mes_len + 1); WFIFOSET(fd,WFIFOW(fd,2)); #else - ssd = map->nick2sd(nick); + ssd = map->nick2sd(nick, false); WFIFOHEAD(fd, mes_len + NAME_LENGTH + 9); WFIFOW(fd,0) = 0x97; @@ -11644,9 +11644,9 @@ static void clif_parse_WisMessage(int fd, struct map_session_data *sd) } // searching destination character - dstsd = map->nick2sd(target); + dstsd = map->nick2sd(target, false); - if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) { + if (dstsd == NULL) { // Character not found (or found through partial match). clif->wis_end(sd->fd, 1); return; @@ -13492,7 +13492,7 @@ static void clif_parse_PartyInvite2(int fd, struct map_session_data *sd) return; } - t_sd = map->nick2sd(name); + t_sd = map->nick2sd(name, true); if(t_sd && t_sd->state.noask) { // @noask [LuzZza] clif->noask_sub(sd, t_sd, 1); @@ -14766,7 +14766,7 @@ static void clif_parse_GuildInvite2(int fd, struct map_session_data *sd) struct map_session_data *t_sd = NULL; safestrncpy(nick, RFIFOP(fd, 2), NAME_LENGTH); - t_sd = map->nick2sd(nick); + t_sd = map->nick2sd(nick, true); clif_sub_guild_invite(fd, sd, t_sd); } @@ -15807,7 +15807,7 @@ static void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd) safestrncpy(nick, RFIFOP(fd,2), NAME_LENGTH); - f_sd = map->nick2sd(nick); + f_sd = map->nick2sd(nick, true); // ensure that the request player's friend list is not full ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0); @@ -16539,7 +16539,7 @@ static void clif_parse_Check(int fd, struct map_session_data *sd) safestrncpy(charname, RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname)); - if( ( pl_sd = map->nick2sd(charname) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) ) { + if ((pl_sd = map->nick2sd(charname, true)) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd)) { return; } diff --git a/src/map/guild.c b/src/map/guild.c index 3191515f7..2faf60e2b 100644 --- a/src/map/guild.c +++ b/src/map/guild.c @@ -654,7 +654,7 @@ static int guild_recv_info(const struct guild *sg) before=*sg; //Perform the check on the user because the first load guild->check_member(sg); - if ((sd = map->nick2sd(sg->master)) != NULL) { + if ((sd = map->nick2sd(sg->master, false)) != NULL) { //If the guild master is online the first time the guild_info is received, //that means he was the first to join, so apply guild skill blocking here. if( battle_config.guild_skill_relog_delay == 1) diff --git a/src/map/map.c b/src/map/map.c index f92be52e9..0f542d812 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -2268,7 +2268,7 @@ static struct map_session_data *map_charid2sd(int charid) * (without sensitive case if necessary) * return map_session_data pointer or NULL *------------------------------------------*/ -static struct map_session_data *map_nick2sd(const char *nick) +static struct map_session_data *map_nick2sd(const char *nick, bool allow_partial) { struct map_session_data* sd; struct map_session_data* found_sd; @@ -2276,7 +2276,7 @@ static struct map_session_data *map_nick2sd(const char *nick) size_t nicklen; int qty = 0; - if( nick == NULL ) + if (nick == NULL) return NULL; nicklen = strlen(nick); @@ -2284,30 +2284,29 @@ static struct map_session_data *map_nick2sd(const char *nick) found_sd = NULL; for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) { - if( battle_config.partial_name_scan ) - {// partial name search - if( strnicmp(sd->status.name, nick, nicklen) == 0 ) - { + if (battle_config.partial_name_scan && allow_partial) { + // partial name search + if (strnicmp(sd->status.name, nick, nicklen) == 0) { found_sd = sd; - if( strcmp(sd->status.name, nick) == 0 ) - {// Perfect Match + if (strcmp(sd->status.name, nick) == 0) { + // Perfect Match qty = 1; break; } qty++; } - } - else if( strcasecmp(sd->status.name, nick) == 0 ) - {// exact search only + } else if (strcasecmp(sd->status.name, nick) == 0) { + // exact search only found_sd = sd; + qty = 1; break; } } mapit->free(iter); - if( battle_config.partial_name_scan && qty != 1 ) + if (battle_config.partial_name_scan && qty != 1) found_sd = NULL; return found_sd; diff --git a/src/map/map.h b/src/map/map.h index 39eb07e4c..6b360e1bc 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -1208,7 +1208,7 @@ END_ZEROED_BLOCK; void (*addiddb) (struct block_list *bl); void (*deliddb) (struct block_list *bl); /* */ - struct map_session_data * (*nick2sd) (const char *nick); + struct map_session_data * (*nick2sd) (const char *nick, bool allow_partial); struct mob_data * (*getmob_boss) (int16 m); struct mob_data * (*id2boss) (int id); uint32 (*race_id2mask) (int race); diff --git a/src/map/script.c b/src/map/script.c index de00f66be..a11d4b080 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -2813,7 +2813,7 @@ static struct map_session_data *script_charid2sd(struct script_state *st, int ch static struct map_session_data *script_nick2sd(struct script_state *st, const char *name) { struct map_session_data *sd; - if ((sd = map->nick2sd(name)) == NULL) { + if ((sd = map->nick2sd(name, false)) == NULL) { ShowWarning("script_nick2sd: Player name '%s' not found!\n", name); script->reportfunc(st); script->reportsrc(st); @@ -8780,7 +8780,7 @@ static BUILDIN(getcharid) struct map_session_data *sd; if (script_hasdata(st, 3)) - sd = map->nick2sd(script_getstr(st, 3)); + sd = map->nick2sd(script_getstr(st, 3), false); else sd = script->rid2sd(st); @@ -16488,7 +16488,7 @@ static BUILDIN(getmapxy) case 0: //Get Character Position if (script_hasdata(st,6)) { if (script_isstringtype(st,6)) - sd = map->nick2sd(script_getstr(st,6)); + sd = map->nick2sd(script_getstr(st,6), false); else sd = map->id2sd(script_getnum(st,6)); } else { @@ -16515,7 +16515,7 @@ static BUILDIN(getmapxy) case 2: //Get Pet Position if (script_hasdata(st,6)) { if (script_isstringtype(st,6)) - sd = map->nick2sd(script_getstr(st,6)); + sd = map->nick2sd(script_getstr(st,6), false); else { bl = map->id2bl(script_getnum(st,6)); break; @@ -16537,7 +16537,7 @@ static BUILDIN(getmapxy) case 4: //Get Homun Position if (script_hasdata(st,6)) { if (script_isstringtype(st,6)) { - sd = map->nick2sd(script_getstr(st,6)); + sd = map->nick2sd(script_getstr(st,6), false); } else { bl = map->id2bl(script_getnum(st,6)); break; @@ -16552,7 +16552,7 @@ static BUILDIN(getmapxy) case 5: //Get Mercenary Position if (script_hasdata(st,6)) { if (script_isstringtype(st,6)) { - sd = map->nick2sd(script_getstr(st,6)); + sd = map->nick2sd(script_getstr(st,6), false); } else { bl = map->id2bl(script_getnum(st,6)); break; @@ -16567,7 +16567,7 @@ static BUILDIN(getmapxy) case 6: //Get Elemental Position if (script_hasdata(st,6)) { if (script_isstringtype(st,6)) { - sd = map->nick2sd(script_getstr(st,6)); + sd = map->nick2sd(script_getstr(st,6), false); } else { bl = map->id2bl(script_getnum(st,6)); break; @@ -23070,7 +23070,7 @@ static BUILDIN(getcharip) /* check if a character name is specified */ if (script_hasdata(st, 2)) { if (script_isstringtype(st, 2)) { - sd = map->nick2sd(script_getstr(st, 2)); + sd = map->nick2sd(script_getstr(st, 2), false); } else { int id = script_getnum(st, 2); sd = (map->id2sd(id) ? map->id2sd(id) : map->charid2sd(id)); -- cgit v1.2.3-70-g09d2