Skip to content
Permalink
Browse files
Added a parameter to map_nick2sd for partial name (#1852)
With this parameter the caller can decide if he wants to enable or disable partial name scan support.
Generally it was disabled in a lot of functions(clif,channel,script commands).
It is still available for some "non-critical" atcommands as well as for all charcommands.
  • Loading branch information
Lemongrass3110 committed Jan 6, 2017
1 parent 55459f3 commit 88aaa9be98c4e9f8494a2012cb3b7700d3b844f5
Showing with 83 additions and 160 deletions.
  1. +2 −0 conf/battle/gm.conf
  2. +28 −28 src/map/atcommand.c
  3. +1 −1 src/map/channel.c
  4. +14 −14 src/map/clif.c
  5. +1 −1 src/map/guild.c
  6. +2 −2 src/map/intif.c
  7. +2 −2 src/map/map.c
  8. +1 −1 src/map/map.h
  9. +32 −111 src/map/script.c
@@ -16,6 +16,8 @@ atcommand_slave_clone_limit: 25
// If 'no', commands require exact player name. If 'yes', entering a partial
// name will work, as long as there's only one match from all players in the
// current map server.
// Some critical atcommands like jail, ban and a few others will still require you to enter the full name.
// It will always work for charcommands when the setting is enabled.
partial_name_scan: yes

// Ban people that try trade dupe.
@@ -507,7 +507,7 @@ ACMD_FUNC(where)
return -1;
}

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))
@@ -536,7 +536,7 @@ ACMD_FUNC(jumpto)
return -1;
}

if((pl_sd=map_nick2sd((char *)message)) == NULL && (pl_sd=map_charid2sd(atoi(message))) == NULL)
if((pl_sd=map_nick2sd((char *)message,true)) == NULL && (pl_sd=map_charid2sd(atoi(message))) == NULL)
{
clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
return -1;
@@ -2892,7 +2892,7 @@ ACMD_FUNC(recall) {
return -1;
}

if((pl_sd=map_nick2sd((char *)message)) == NULL && (pl_sd=map_charid2sd(atoi(message))) == NULL)
if((pl_sd=map_nick2sd((char *)message,true)) == NULL && (pl_sd=map_charid2sd(atoi(message))) == NULL)
{
clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
return -1;
@@ -3228,7 +3228,7 @@ ACMD_FUNC(kick)
return -1;
}

if((pl_sd=map_nick2sd((char *)message)) == NULL && (pl_sd=map_charid2sd(atoi(message))) == NULL)
if((pl_sd=map_nick2sd((char *)message,false)) == NULL && (pl_sd=map_charid2sd(atoi(message))) == NULL)
{
clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
return -1;
@@ -4487,7 +4487,7 @@ ACMD_FUNC(nuke)
return -1;
}

if ((pl_sd = map_nick2sd(atcmd_player_name)) != NULL) {
if ((pl_sd = map_nick2sd(atcmd_player_name,false)) != 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, gettick(), 0);
clif_displaymessage(fd, msg_txt(sd,109)); // Player has been nuked!
@@ -4760,7 +4760,7 @@ ACMD_FUNC(jail)
return -1;
}

if ((pl_sd = map_nick2sd(atcmd_player_name)) == NULL) {
if ((pl_sd = map_nick2sd(atcmd_player_name,false)) == NULL) {
clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
return -1;
}
@@ -4810,7 +4810,7 @@ ACMD_FUNC(unjail)
return -1;
}

if ((pl_sd = map_nick2sd(atcmd_player_name)) == NULL) {
if ((pl_sd = map_nick2sd(atcmd_player_name,false)) == NULL) {
clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
return -1;
}
@@ -4858,7 +4858,7 @@ ACMD_FUNC(jailfor) {
return -1;
}

if ((pl_sd = map_nick2sd(atcmd_player_name)) == NULL) {
if ((pl_sd = map_nick2sd(atcmd_player_name,false)) == NULL) {
clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
return -1;
}
@@ -5416,7 +5416,7 @@ ACMD_FUNC(follow)
return 0;
}

if ( (pl_sd = map_nick2sd((char *)message)) == NULL )
if ( (pl_sd = map_nick2sd((char *)message,true)) == NULL )
{
clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
return -1;
@@ -5674,7 +5674,7 @@ ACMD_FUNC(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_displaymessage(fd, msg_txt(sd,3)); // Character not found.
return -1;
}
@@ -5743,7 +5743,7 @@ ACMD_FUNC(skilltree)
return -1;
}

if ( (pl_sd = map_nick2sd(target)) == NULL )
if ( (pl_sd = map_nick2sd(target,true)) == NULL )
{
clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
return -1;
@@ -5820,7 +5820,7 @@ ACMD_FUNC(marry)
return -1;
}

if ((pl_sd = map_nick2sd(player_name)) == NULL) {
if ((pl_sd = map_nick2sd(player_name,false)) == NULL) {
clif_displaymessage(fd, msg_txt(sd,3));
return -1;
}
@@ -5958,7 +5958,7 @@ ACMD_FUNC(changegm)
return -1;
}

if((pl_sd=map_nick2sd((char *) message)) == NULL || pl_sd->status.guild_id != sd->status.guild_id) {
if((pl_sd=map_nick2sd((char *) message,false)) == NULL || pl_sd->status.guild_id != sd->status.guild_id) {
clif_displaymessage(fd, msg_txt(sd,1184)); // Target character must be online and be a guild member.
return -1;
}
@@ -5981,7 +5981,7 @@ ACMD_FUNC(changeleader)
return -1;
}

if (party_changeleader(sd, map_nick2sd((char *) message),NULL))
if (party_changeleader(sd, map_nick2sd((char *) message,false),NULL))
return 0;
return -1;
}
@@ -6808,7 +6808,7 @@ ACMD_FUNC(trade)
return -1;
}

if ( (pl_sd = map_nick2sd((char *)message)) == NULL )
if ( (pl_sd = map_nick2sd((char *)message,true)) == NULL )
{
clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
return -1;
@@ -6856,7 +6856,7 @@ ACMD_FUNC(unmute)
return -1;
}

if ( (pl_sd = map_nick2sd((char *)message)) == NULL )
if ( (pl_sd = map_nick2sd((char *)message,false)) == NULL )
{
clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
return -1;
@@ -6953,7 +6953,7 @@ ACMD_FUNC(mute)
return -1;
}

if ( (pl_sd = map_nick2sd(atcmd_player_name)) == NULL )
if ( (pl_sd = map_nick2sd(atcmd_player_name,false)) == NULL )
{
clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
return -1;
@@ -8204,7 +8204,7 @@ ACMD_FUNC(showdelay)
ACMD_FUNC(invite)
{
unsigned int did = sd->duel_group;
struct map_session_data *target_sd = map_nick2sd((char *)message);
struct map_session_data *target_sd = map_nick2sd((char *)message,true);

if(did == 0) {
// "Duel: @invite without @duel."
@@ -8277,7 +8277,7 @@ ACMD_FUNC(duel)
duel_create(sd, maxpl);
} else {
struct map_session_data *target_sd;
target_sd = map_nick2sd((char *)message);
target_sd = map_nick2sd((char *)message,true);
if(target_sd != NULL) {
unsigned int newduel;
if((newduel = duel_create(sd, 2)) != -1) {
@@ -8429,7 +8429,7 @@ ACMD_FUNC(clone)
return 0;
}

if((pl_sd=map_nick2sd((char *)message)) == NULL && (pl_sd=map_charid2sd(atoi(message))) == NULL) {
if((pl_sd=map_nick2sd((char *)message,true)) == NULL && (pl_sd=map_charid2sd(atoi(message))) == NULL) {
clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
return 0;
}
@@ -9554,7 +9554,7 @@ ACMD_FUNC(vip) {
return -1;
}

if ((pl_sd = map_nick2sd(atcmd_player_name)) == NULL) {
if ((pl_sd = map_nick2sd(atcmd_player_name,false)) == NULL) {
clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
return -1;
}
@@ -9617,7 +9617,7 @@ ACMD_FUNC(fullstrip) {
return -1;
}

if((tsd=map_nick2sd((char *)message)) == NULL && (tsd=map_id2sd(atoi(message))) == NULL){
if((tsd=map_nick2sd((char *)message,false)) == NULL && (tsd=map_id2sd(atoi(message))) == NULL){
clif_displaymessage(fd, msg_txt(sd,3)); // Character not found.
return -1;
}
@@ -9708,7 +9708,7 @@ ACMD_FUNC(cloneequip) {
if (char_id)
pl_sd = map_charid2sd(char_id);
else
pl_sd = map_nick2sd(atcmd_output);
pl_sd = map_nick2sd(atcmd_output,true);

if (!pl_sd) {
clif_displaymessage(fd, msg_txt(sd, 3));
@@ -9784,7 +9784,7 @@ ACMD_FUNC(clonestat) {
if (char_id)
pl_sd = map_charid2sd(char_id);
else
pl_sd = map_nick2sd(atcmd_output);
pl_sd = map_nick2sd(atcmd_output,true);

if (!pl_sd) {
clif_displaymessage(fd, msg_txt(sd, 3));
@@ -9874,7 +9874,7 @@ ACMD_FUNC(adopt)
return -1;
}

if ((b_sd = map_nick2sd((char *)atcmd_player_name)) == NULL) {
if ((b_sd = map_nick2sd((char *)atcmd_player_name,false)) == NULL) {
clif_displaymessage(fd, msg_txt(sd, 3)); // Character not found.
return -1;
}
@@ -10360,10 +10360,10 @@ bool is_atcommand(const int fd, struct map_session_data* sd, const char* message
if (*message == charcommand_symbol)
is_atcommand = false;

if (is_atcommand) { // #command
if (is_atcommand) { // @command
sprintf(atcmd_msg, "%s", message);
ssd = sd;
} else { // @command
} else { // #command
char charname[NAME_LENGTH];
int n;

@@ -10385,7 +10385,7 @@ bool is_atcommand(const int fd, struct map_session_data* sd, const char* message
return true;
}

ssd = map_nick2sd(charname);
ssd = map_nick2sd(charname,true);
if (ssd == NULL) {
sprintf(output, msg_txt(sd,1389), command); // %s failed. Player not found.
clif_displaymessage(fd, output);
@@ -813,7 +813,7 @@ int channel_pcunbind(struct map_session_data *sd){
int channel_pcban(struct map_session_data *sd, char *chname, char *pname, int flag){
struct Channel *channel;
char output[128];
struct map_session_data *tsd = map_nick2sd(pname);
struct map_session_data *tsd = map_nick2sd(pname,false);

if( channel_chk(chname,NULL,1) ) {
clif_displaymessage(sd->fd, msg_txt(sd,1405));// Channel name must start with '#'.
@@ -6390,7 +6390,7 @@ void clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
safestrncpy(WFIFOCP(fd,28), mes, mes_len);
WFIFOSET(fd,WFIFOW(fd,2));
#else
struct map_session_data *ssd = map_nick2sd(nick);
struct map_session_data *ssd = map_nick2sd(nick,false);

WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
WFIFOW(fd,0) = 0x97;
@@ -11071,7 +11071,7 @@ 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) {
// player is not on this map-server
@@ -12732,7 +12732,7 @@ void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
return;
}

t_sd = map_nick2sd(name);
t_sd = map_nick2sd(name,false);

if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
clif_noask_sub(sd, t_sd, 1);
@@ -13360,7 +13360,7 @@ void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
/// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
void
clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
struct map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));
struct map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),false);

if (clif_sub_guild_invite(fd, sd, t_sd))
return;
@@ -14212,15 +14212,7 @@ void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
struct map_session_data *f_sd;
int i;

f_sd = map_nick2sd(RFIFOCP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]));

// ensure that the request player's friend list is not full
ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);

if( i == MAX_FRIENDS ) {
clif_friendslist_reqack(sd, f_sd, 2);
return;
}
f_sd = map_nick2sd(RFIFOCP(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),false);

// Friend doesn't exist (no player with this name)
if (f_sd == NULL) {
@@ -14232,6 +14224,14 @@ void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
return;
}

// ensure that the request player's friend list is not full
ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);

if( i == MAX_FRIENDS ){
clif_friendslist_reqack(sd, f_sd, 2);
return;
}

// @noask [LuzZza]
if(f_sd->state.noask) {
clif_noask_sub(sd, f_sd, 5);
@@ -14633,7 +14633,7 @@ void clif_parse_Check(int fd, struct map_session_data *sd)

safestrncpy(charname, RFIFOCP(fd,packet_db[sd->packet_ver][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,false) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
{
return;
}
@@ -496,7 +496,7 @@ int guild_recv_info(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 )
@@ -1234,7 +1234,7 @@ int intif_parse_WisMessage(int fd)
id=RFIFOL(fd,4);

safestrncpy(name, RFIFOCP(fd,32), NAME_LENGTH);
sd = map_nick2sd(name);
sd = map_nick2sd(name,false);
if(sd == NULL || strcmp(sd->status.name, name) != 0)
{ //Not found
intif_wis_replay(id,1);
@@ -1272,7 +1272,7 @@ int intif_parse_WisEnd(int fd)

if (battle_config.etc_log)
ShowInfo("intif_parse_wisend: player: %s, flag: %d\n", RFIFOP(fd,2), RFIFOB(fd,26)); // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target
sd = (struct map_session_data *)map_nick2sd(RFIFOCP(fd,2));
sd = (struct map_session_data *)map_nick2sd(RFIFOCP(fd,2),false);
if (sd != NULL)
clif_wis_end(sd->fd, RFIFOB(fd,26));

@@ -2185,7 +2185,7 @@ struct map_session_data* map_charid2sd(int charid)
* (without sensitive case if necessary)
* return map_session_data pointer or NULL
*------------------------------------------*/
struct map_session_data * map_nick2sd(const char *nick)
struct map_session_data * map_nick2sd(const char *nick, bool allow_partial)
{
struct map_session_data* sd;
struct map_session_data* found_sd;
@@ -2202,7 +2202,7 @@ struct map_session_data * map_nick2sd(const char *nick)
found_sd = NULL;
for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) )
{
if( battle_config.partial_name_scan )
if( allow_partial && battle_config.partial_name_scan )
{// partial name search
if( strnicmp(sd->status.name, nick, nicklen) == 0 )
{
@@ -854,7 +854,7 @@ void map_foreachmob(int (*func)(struct mob_data* md, va_list args), ...);
void map_foreachnpc(int (*func)(struct npc_data* nd, va_list args), ...);
void map_foreachregen(int (*func)(struct block_list* bl, va_list args), ...);
void map_foreachiddb(int (*func)(struct block_list* bl, va_list args), ...);
struct map_session_data * map_nick2sd(const char*);
struct map_session_data * map_nick2sd(const char* nick, bool allow_partial);
struct mob_data * map_getmob_boss(int16 m);
struct mob_data * map_id2boss(int id);

0 comments on commit 88aaa9b

Please sign in to comment.