Merge pull request #1563 from rathena/cleanup/npc_name_length

Expand NPC Name Length to 50

Thanks to @cydh!
This commit is contained in:
Lemongrass3110 2016-10-14 09:37:36 +02:00 committed by GitHub
commit 2bde36fb9d
9 changed files with 130 additions and 114 deletions

View File

@ -715,7 +715,7 @@ CREATE TABLE IF NOT EXISTS `mapreg` (
-- --
CREATE TABLE IF NOT EXISTS `market` ( CREATE TABLE IF NOT EXISTS `market` (
`name` varchar(32) NOT NULL DEFAULT '', `name` varchar(50) NOT NULL DEFAULT '',
`nameid` SMALLINT(5) UNSIGNED NOT NULL, `nameid` SMALLINT(5) UNSIGNED NOT NULL,
`price` INT(11) UNSIGNED NOT NULL, `price` INT(11) UNSIGNED NOT NULL,
`amount` SMALLINT(5) UNSIGNED NOT NULL, `amount` SMALLINT(5) UNSIGNED NOT NULL,

View File

@ -0,0 +1,2 @@
ALTER TABLE `market`
MODIFY `name` varchar(50) NOT NULL DEFAULT '';

View File

@ -96,6 +96,8 @@
//Includes null-terminator as it is the length of the array. //Includes null-terminator as it is the length of the array.
#define NAME_LENGTH (23 + 1) #define NAME_LENGTH (23 + 1)
#define PASSWD_LENGTH (32+1) #define PASSWD_LENGTH (32+1)
//NPC names can be longer than it's displayed on client (NAME_LENGTH).
#define NPC_NAME_LENGTH 50
//For item names, which tend to have much longer names. //For item names, which tend to have much longer names.
#define ITEM_NAME_LENGTH 50 #define ITEM_NAME_LENGTH 50
//For Map Names, which the client considers to be 16 in length including the .gat extension //For Map Names, which the client considers to be 16 in length including the .gat extension

View File

@ -1129,9 +1129,9 @@ static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool
#endif #endif
#if PACKETVER >= 20091103 #if PACKETVER >= 20091103
#if PACKETVER >= 20120221 #if PACKETVER >= 20120221
memcpy((char*)WBUFP(buf,64), name, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,64), name, NAME_LENGTH);
#else #else
memcpy((char*)WBUFP(buf,55), name, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,55), name, NAME_LENGTH);
#endif #endif
return WBUFW(buffer,2); return WBUFW(buffer,2);
#else #else
@ -1272,9 +1272,9 @@ static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, un
#endif #endif
#if PACKETVER >= 20091103 #if PACKETVER >= 20091103
#if PACKETVER >= 20120221 #if PACKETVER >= 20120221
memcpy((char*)WBUFP(buf,71), name, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,71), name, NAME_LENGTH);
#else #else
memcpy((char*)WBUFP(buf,62), name, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,62), name, NAME_LENGTH);
#endif #endif
return WBUFW(buffer,2); return WBUFW(buffer,2);
#else #else
@ -1499,7 +1499,7 @@ void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
memset(buf,0,packet_len(cmd)); memset(buf,0,packet_len(cmd));
WBUFW(buf,0) = cmd; WBUFW(buf,0) = cmd;
memcpy(WBUFP(buf,2), hd->homunculus.name, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,2), hd->homunculus.name, NAME_LENGTH);
// Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true) // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
WBUFB(buf,26) = (battle_config.hom_rename ? 0 : hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp ? 0 : 4); WBUFB(buf,26) = (battle_config.hom_rename ? 0 : hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp ? 0 : 4);
WBUFW(buf,27) = hd->homunculus.level; WBUFW(buf,27) = hd->homunculus.level;
@ -4096,15 +4096,16 @@ void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
if(cd->owner->type == BL_NPC){ if(cd->owner->type == BL_NPC){
WFIFOL(fd, 30) = 1; WFIFOL(fd, 30) = 1;
WFIFOL(fd, 8) = 0; WFIFOL(fd, 8) = 0;
memcpy(WFIFOP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH); safestrncpy((char*)WFIFOP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
for (i = 0; i < cd->users; i++) { for (i = 0; i < cd->users; i++) {
WFIFOL(fd, 8+(i+1)*28) = 1; WFIFOL(fd, 8+(i+1)*28) = 1;
memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH); safestrncpy((char*)WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
}
}else{
for (i = 0; i < cd->users; i++) {
WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
safestrncpy((char*)WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
} }
} else
for (i = 0; i < cd->users; i++) {
WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
memcpy(WFIFOP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
} }
WFIFOSET(fd, WFIFOW(fd, 2)); WFIFOSET(fd, WFIFOW(fd, 2));
} }
@ -4121,7 +4122,7 @@ void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
WBUFW(buf, 0) = 0xdc; WBUFW(buf, 0) = 0xdc;
WBUFW(buf, 2) = cd->users; WBUFW(buf, 2) = cd->users;
memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH); safestrncpy((char*)WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS); clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
} }
@ -4140,11 +4141,11 @@ void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
WBUFW(buf, 0) = 0xe1; WBUFW(buf, 0) = 0xe1;
WBUFL(buf, 2) = 1; WBUFL(buf, 2) = 1;
memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH); safestrncpy((char*)WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
WBUFW(buf,30) = 0xe1; WBUFW(buf,30) = 0xe1;
WBUFL(buf,32) = 0; WBUFL(buf,32) = 0;
memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH); safestrncpy((char*)WBUFP(buf,36),sd->status.name,NAME_LENGTH);
clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT); clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
} }
@ -4164,7 +4165,7 @@ void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag
WBUFW(buf, 0) = 0xdd; WBUFW(buf, 0) = 0xdd;
WBUFW(buf, 2) = cd->users-1; WBUFW(buf, 2) = cd->users-1;
memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH); safestrncpy((char*)WBUFP(buf,4),sd->status.name,NAME_LENGTH);
WBUFB(buf,28) = flag; WBUFB(buf,28) = flag;
clif_send(buf,packet_len(0xdd),&sd->bl,CHAT); clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
@ -7218,8 +7219,8 @@ void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
WBUFW(buf,10) = sd->bl.x; WBUFW(buf,10) = sd->bl.x;
WBUFW(buf,12) = sd->bl.y; WBUFW(buf,12) = sd->bl.y;
WBUFB(buf,14) = (p->party.member[i].online)?0:1; WBUFB(buf,14) = (p->party.member[i].online)?0:1;
memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,15), p->party.name, NAME_LENGTH);
memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,39), sd->status.name, NAME_LENGTH);
mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), (char*)WBUFP(buf,63)); mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), (char*)WBUFP(buf,63));
WBUFB(buf,79) = (p->party.item&1)?1:0; WBUFB(buf,79) = (p->party.item&1)?1:0;
WBUFB(buf,80) = (p->party.item&2)?1:0; WBUFB(buf,80) = (p->party.item&2)?1:0;
@ -7244,7 +7245,7 @@ void clif_party_info(struct party_data* p, struct map_session_data *sd)
nullpo_retv(p); nullpo_retv(p);
WBUFW(buf,0) = 0xfb; WBUFW(buf,0) = 0xfb;
memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,4), p->party.name, NAME_LENGTH);
for(i = 0, c = 0; i < MAX_PARTY; i++) for(i = 0, c = 0; i < MAX_PARTY; i++)
{ {
struct party_member* m = &p->party.member[i]; struct party_member* m = &p->party.member[i];
@ -7253,7 +7254,7 @@ void clif_party_info(struct party_data* p, struct map_session_data *sd)
if(party_sd == NULL) party_sd = p->data[i].sd; if(party_sd == NULL) party_sd = p->data[i].sd;
WBUFL(buf,28+c*46) = m->account_id; WBUFL(buf,28+c*46) = m->account_id;
memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28)); mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1; WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1; WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
@ -7311,7 +7312,7 @@ void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
WFIFOHEAD(fd,packet_len(cmd)); WFIFOHEAD(fd,packet_len(cmd));
WFIFOW(fd,0)=cmd; WFIFOW(fd,0)=cmd;
WFIFOL(fd,2)=sd->status.party_id; WFIFOL(fd,2)=sd->status.party_id;
memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH); safestrncpy((char*)WFIFOP(fd,6),p->party.name,NAME_LENGTH);
WFIFOSET(fd,packet_len(cmd)); WFIFOSET(fd,packet_len(cmd));
} }
@ -7685,7 +7686,7 @@ void clif_send_petstatus(struct map_session_data *sd)
pet = &sd->pd->pet; pet = &sd->pd->pet;
WFIFOHEAD(fd,packet_len(0x1a2)); WFIFOHEAD(fd,packet_len(0x1a2));
WFIFOW(fd,0)=0x1a2; WFIFOW(fd,0)=0x1a2;
memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH); safestrncpy((char*)WFIFOP(fd,2),pet->name,NAME_LENGTH);
WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag; WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
WFIFOW(fd,27)=pet->level; WFIFOW(fd,27)=pet->level;
WFIFOW(fd,29)=pet->hungry; WFIFOW(fd,29)=pet->hungry;
@ -8002,7 +8003,7 @@ void clif_guild_belonginfo(struct map_session_data *sd, struct guild *g)
WFIFOL(fd,10)=g->position[ps].mode; WFIFOL(fd,10)=g->position[ps].mode;
WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1); WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
WFIFOL(fd,15)=0; // InterSID (unknown purpose) WFIFOL(fd,15)=0; // InterSID (unknown purpose)
memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH); safestrncpy((char*)WFIFOP(fd,19),g->name,NAME_LENGTH);
WFIFOSET(fd,packet_len(0x16c)); WFIFOSET(fd,packet_len(0x16c));
} }
@ -8130,8 +8131,8 @@ void clif_guild_basicinfo(struct map_session_data *sd) {
WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right) WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up) WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
WFIFOL(fd,42)=g->emblem_id; WFIFOL(fd,42)=g->emblem_id;
memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH); safestrncpy((char*)WFIFOP(fd,46),g->name, NAME_LENGTH);
memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH); safestrncpy((char*)WFIFOP(fd,70),g->master, NAME_LENGTH);
safestrncpy((char*)WFIFOP(fd,94),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles" safestrncpy((char*)WFIFOP(fd,94),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
WFIFOL(fd,110) = 0; // zeny WFIFOL(fd,110) = 0; // zeny
@ -8159,7 +8160,7 @@ void clif_guild_allianceinfo(struct map_session_data *sd)
if(a->guild_id>0){ if(a->guild_id>0){
WFIFOL(fd,c*32+4)=a->opposition; WFIFOL(fd,c*32+4)=a->opposition;
WFIFOL(fd,c*32+8)=a->guild_id; WFIFOL(fd,c*32+8)=a->guild_id;
memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH); safestrncpy((char*)WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
c++; c++;
} }
} }
@ -8204,7 +8205,7 @@ void clif_guild_memberlist(struct map_session_data *sd)
WFIFOL(fd,c*104+26)=m->online; WFIFOL(fd,c*104+26)=m->online;
WFIFOL(fd,c*104+30)=m->position; WFIFOL(fd,c*104+30)=m->position;
memset(WFIFOP(fd,c*104+34),0,50); //[Ind] - This is displayed in the 'note' column but being you can't edit it it's sent empty. memset(WFIFOP(fd,c*104+34),0,50); //[Ind] - This is displayed in the 'note' column but being you can't edit it it's sent empty.
memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH); safestrncpy((char*)WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
c++; c++;
} }
WFIFOW(fd, 2)=c*104+4; WFIFOW(fd, 2)=c*104+4;
@ -8228,7 +8229,7 @@ void clif_guild_positionnamelist(struct map_session_data *sd)
WFIFOW(fd, 0)=0x166; WFIFOW(fd, 0)=0x166;
for(i=0;i<MAX_GUILDPOSITION;i++){ for(i=0;i<MAX_GUILDPOSITION;i++){
WFIFOL(fd,i*28+4)=i; WFIFOL(fd,i*28+4)=i;
memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH); safestrncpy((char*)WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
} }
WFIFOW(fd,2)=i*28+4; WFIFOW(fd,2)=i*28+4;
WFIFOSET(fd,WFIFOW(fd,2)); WFIFOSET(fd,WFIFOW(fd,2));
@ -8290,7 +8291,7 @@ void clif_guild_positionchanged(struct guild *g,int idx)
WBUFL(buf, 8)=g->position[idx].mode; WBUFL(buf, 8)=g->position[idx].mode;
WBUFL(buf,12)=idx; WBUFL(buf,12)=idx;
WBUFL(buf,16)=g->position[idx].exp_mode; WBUFL(buf,16)=g->position[idx].exp_mode;
memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH); safestrncpy((char*)WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
// }* // }*
if( (sd=guild_getavailablesd(g))!=NULL ) if( (sd=guild_getavailablesd(g))!=NULL )
clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD); clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
@ -8436,7 +8437,7 @@ void clif_guild_invite(struct map_session_data *sd,struct guild *g)
WFIFOHEAD(fd,packet_len(0x16a)); WFIFOHEAD(fd,packet_len(0x16a));
WFIFOW(fd,0)=0x16a; WFIFOW(fd,0)=0x16a;
WFIFOL(fd,2)=g->guild_id; WFIFOL(fd,2)=g->guild_id;
memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH); safestrncpy((char*)WFIFOP(fd,6),g->name,NAME_LENGTH);
WFIFOSET(fd,packet_len(0x16a)); WFIFOSET(fd,packet_len(0x16a));
} }
@ -8471,7 +8472,7 @@ void clif_guild_leave(struct map_session_data *sd,const char *name,const char *m
nullpo_retv(sd); nullpo_retv(sd);
WBUFW(buf, 0)=0x15a; WBUFW(buf, 0)=0x15a;
memcpy(WBUFP(buf, 2),name,NAME_LENGTH); safestrncpy((char*)WBUFP(buf, 2),name,NAME_LENGTH);
memcpy(WBUFP(buf,26),mes,40); memcpy(WBUFP(buf,26),mes,40);
clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG); clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
} }
@ -8530,7 +8531,7 @@ void clif_guild_expulsionlist(struct map_session_data* sd)
if( e->account_id > 0 ) if( e->account_id > 0 )
{ {
memcpy(WFIFOP(fd,4 + c*offset), e->name, NAME_LENGTH); safestrncpy((char*)WFIFOP(fd,4 + c*offset), e->name, NAME_LENGTH);
#if PACKETVER < 20100803 #if PACKETVER < 20100803
memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons) memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40); memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
@ -8582,7 +8583,7 @@ void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const
WFIFOHEAD(fd,packet_len(0x171)); WFIFOHEAD(fd,packet_len(0x171));
WFIFOW(fd,0)=0x171; WFIFOW(fd,0)=0x171;
WFIFOL(fd,2)=account_id; WFIFOL(fd,2)=account_id;
memcpy(WFIFOP(fd,6),name,NAME_LENGTH); safestrncpy((char*)WFIFOP(fd,6),name,NAME_LENGTH);
WFIFOSET(fd,packet_len(0x171)); WFIFOSET(fd,packet_len(0x171));
} }
@ -8662,7 +8663,7 @@ void clif_guild_allianceadded(struct guild *g,int idx)
WBUFW(buf,0)=0x185; WBUFW(buf,0)=0x185;
WBUFL(buf,2)=g->alliance[idx].opposition; WBUFL(buf,2)=g->alliance[idx].opposition;
WBUFL(buf,6)=g->alliance[idx].guild_id; WBUFL(buf,6)=g->alliance[idx].guild_id;
memcpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH); safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD); clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
} }
*/ */
@ -8746,7 +8747,7 @@ void clif_callpartner(struct map_session_data *sd)
const char *p = map_charid2nick(sd->status.partner_id); const char *p = map_charid2nick(sd->status.partner_id);
struct map_session_data *p_sd = pc_get_partner(sd); struct map_session_data *p_sd = pc_get_partner(sd);
if( p != NULL && p_sd != NULL && !p_sd->state.autotrade ) if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
memcpy(WBUFP(buf,2), p, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,2), p, NAME_LENGTH);
else else
WBUFB(buf,2) = 0; WBUFB(buf,2) = 0;
} else {// Send zero-length name if no partner, to initialize the client buffer. } else {// Send zero-length name if no partner, to initialize the client buffer.
@ -8784,7 +8785,7 @@ void clif_divorced(struct map_session_data* sd, const char* name)
fd=sd->fd; fd=sd->fd;
WFIFOHEAD(fd,packet_len(0x205)); WFIFOHEAD(fd,packet_len(0x205));
WFIFOW(fd,0)=0x205; WFIFOW(fd,0)=0x205;
memcpy(WFIFOP(fd,2), name, NAME_LENGTH); safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
WFIFOSET(fd, packet_len(0x205)); WFIFOSET(fd, packet_len(0x205));
} }
@ -9264,11 +9265,11 @@ void clif_charnameack (int fd, struct block_list *bl)
if( ssd->fakename[0] ) { if( ssd->fakename[0] ) {
WBUFW(buf, 0) = cmd = 0x195; WBUFW(buf, 0) = cmd = 0x195;
memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0; WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
break; break;
} }
memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
if( ssd->status.party_id ) { if( ssd->status.party_id ) {
p = party_search(ssd->status.party_id); p = party_search(ssd->status.party_id);
@ -9291,14 +9292,14 @@ void clif_charnameack (int fd, struct block_list *bl)
WBUFW(buf, 0) = cmd = 0x195; WBUFW(buf, 0) = cmd = 0x195;
if (p) if (p)
memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,30), p->party.name, NAME_LENGTH);
else else
WBUFB(buf,30) = 0; WBUFB(buf,30) = 0;
if (g && ps >= 0 && ps < MAX_GUILDPOSITION) if (g && ps >= 0 && ps < MAX_GUILDPOSITION)
{ {
memcpy(WBUFP(buf,54), g->name,NAME_LENGTH); safestrncpy((char*)WBUFP(buf,54), g->name,NAME_LENGTH);
memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
} else { //Assume no guild. } else { //Assume no guild.
WBUFB(buf,54) = 0; WBUFB(buf,54) = 0;
WBUFB(buf,78) = 0; WBUFB(buf,78) = 0;
@ -9307,29 +9308,29 @@ void clif_charnameack (int fd, struct block_list *bl)
break; break;
//[blackhole89] //[blackhole89]
case BL_HOM: case BL_HOM:
memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
break; break;
case BL_MER: case BL_MER:
memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
break; break;
case BL_PET: case BL_PET:
memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
break; break;
case BL_NPC: case BL_NPC:
memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
break; break;
case BL_MOB: case BL_MOB:
{ {
struct mob_data *md = (struct mob_data *)bl; struct mob_data *md = (struct mob_data *)bl;
nullpo_retv(md); nullpo_retv(md);
memcpy(WBUFP(buf,6), md->name, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,6), md->name, NAME_LENGTH);
if( md->guardian_data && md->guardian_data->guild_id ) if( md->guardian_data && md->guardian_data->guild_id )
{ {
WBUFW(buf, 0) = cmd = 0x195; WBUFW(buf, 0) = cmd = 0x195;
WBUFB(buf,30) = 0; WBUFB(buf,30) = 0;
memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
} }
else if( battle_config.show_mob_info ) else if( battle_config.show_mob_info )
{ {
@ -9346,7 +9347,7 @@ void clif_charnameack (int fd, struct block_list *bl)
if( str_p != mobhp ) if( str_p != mobhp )
{ {
*(str_p-3) = '\0'; //Remove trailing space + pipe. *(str_p-3) = '\0'; //Remove trailing space + pipe.
memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,30), mobhp, NAME_LENGTH);
WBUFB(buf,54) = 0; WBUFB(buf,54) = 0;
WBUFB(buf,78) = 0; WBUFB(buf,78) = 0;
} }
@ -9354,11 +9355,11 @@ void clif_charnameack (int fd, struct block_list *bl)
} }
break; break;
case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex] case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
// memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH); // safestrncpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
// break; // break;
return; return;
case BL_ELEM: case BL_ELEM:
memcpy(WBUFP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
break; break;
default: default:
ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id); ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
@ -9393,7 +9394,7 @@ void clif_charnameupdate (struct map_session_data *ssd)
WBUFW(buf,0) = cmd; WBUFW(buf,0) = cmd;
WBUFL(buf,2) = ssd->bl.id; WBUFL(buf,2) = ssd->bl.id;
memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
if (!battle_config.display_party_name) { if (!battle_config.display_party_name) {
if (ssd->status.party_id > 0 && ssd->status.guild_id > 0 && (g = ssd->guild) != NULL) if (ssd->status.party_id > 0 && ssd->status.guild_id > 0 && (g = ssd->guild) != NULL)
@ -9411,14 +9412,14 @@ void clif_charnameupdate (struct map_session_data *ssd)
} }
if( p ) if( p )
memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,30), p->party.name, NAME_LENGTH);
else else
WBUFB(buf,30) = 0; WBUFB(buf,30) = 0;
if( g && ps >= 0 && ps < MAX_GUILDPOSITION ) if( g && ps >= 0 && ps < MAX_GUILDPOSITION )
{ {
memcpy(WBUFP(buf,54), g->name,NAME_LENGTH); safestrncpy((char*)WBUFP(buf,54), g->name,NAME_LENGTH);
memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
} }
else else
{ {
@ -11034,7 +11035,7 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd)
set_var(sd,variablename,(char *) split_data[i]); set_var(sd,variablename,(char *) split_data[i]);
} }
safesnprintf(event,sizeof(event),"%s::OnWhisperGlobal", npc->exname); safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
npc_event(sd,event,0); // Calls the NPC label npc_event(sd,event,0); // Calls the NPC label
return; return;
@ -12890,7 +12891,7 @@ void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results,
{ {
pb_ad = results[i]; pb_ad = results[i];
WFIFOL(fd,i*size+5) = pb_ad->index; WFIFOL(fd,i*size+5) = pb_ad->index;
memcpy(WFIFOP(fd,i*size+9),pb_ad->charname,NAME_LENGTH); safestrncpy((char*)WFIFOP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
WFIFOW(fd,i*size+37) = pb_ad->p_detail.level; WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid; WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
@ -12954,7 +12955,7 @@ void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_boo
WBUFW(buf,0) = 0x809; WBUFW(buf,0) = 0x809;
WBUFL(buf,2) = pb_ad->index; WBUFL(buf,2) = pb_ad->index;
memcpy(WBUFP(buf,6),pb_ad->charname,NAME_LENGTH); safestrncpy((char*)WBUFP(buf,6),pb_ad->charname,NAME_LENGTH);
WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
WBUFW(buf,34) = pb_ad->p_detail.level; WBUFW(buf,34) = pb_ad->p_detail.level;
WBUFW(buf,36) = pb_ad->p_detail.mapid; WBUFW(buf,36) = pb_ad->p_detail.mapid;
@ -14003,7 +14004,7 @@ void clif_PMIgnoreList(struct map_session_data* sd)
WFIFOW(fd,0) = 0xd4; WFIFOW(fd,0) = 0xd4;
for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) { for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
memcpy(WFIFOP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH); safestrncpy((char*)WFIFOP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
} }
WFIFOW(fd,2) = 4+i*NAME_LENGTH; WFIFOW(fd,2) = 4+i*NAME_LENGTH;
@ -14118,7 +14119,7 @@ void clif_friendslist_send(struct map_session_data *sd)
for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) { for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id; WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id; WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH); safestrncpy((char*)WFIFOP(fd, 4 + 32 * i + 8), sd->status.friends[i].name, NAME_LENGTH);
} }
if (i) { if (i) {
@ -14152,7 +14153,7 @@ void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_dat
if (f_sd) { if (f_sd) {
WFIFOL(fd,4) = f_sd->status.account_id; WFIFOL(fd,4) = f_sd->status.account_id;
WFIFOL(fd,8) = f_sd->status.char_id; WFIFOL(fd,8) = f_sd->status.char_id;
memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH); safestrncpy((char*)WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
} }
WFIFOSET(fd, packet_len(0x209)); WFIFOSET(fd, packet_len(0x209));
} }
@ -14168,7 +14169,7 @@ void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32
WFIFOW(fd,0) = 0x207; WFIFOW(fd,0) = 0x207;
WFIFOL(fd,2) = account_id; WFIFOL(fd,2) = account_id;
WFIFOL(fd,6) = char_id; WFIFOL(fd,6) = char_id;
memcpy(WFIFOP(fd,10), name, NAME_LENGTH); safestrncpy((char*)WFIFOP(fd,10), name, NAME_LENGTH);
WFIFOSET(fd,packet_len(0x207)); WFIFOSET(fd,packet_len(0x207));
} }
@ -14264,7 +14265,7 @@ void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
f_sd->status.friends[i].account_id = sd->status.account_id; f_sd->status.friends[i].account_id = sd->status.account_id;
f_sd->status.friends[i].char_id = sd->status.char_id; f_sd->status.friends[i].char_id = sd->status.char_id;
memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH); safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
clif_friendslist_reqack(f_sd, sd, 0); clif_friendslist_reqack(f_sd, sd, 0);
if (battle_config.friend_auto_add) { if (battle_config.friend_auto_add) {
@ -14282,7 +14283,7 @@ void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
sd->status.friends[i].account_id = f_sd->status.account_id; sd->status.friends[i].account_id = f_sd->status.account_id;
sd->status.friends[i].char_id = f_sd->status.char_id; sd->status.friends[i].char_id = f_sd->status.char_id;
memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH); safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
clif_friendslist_reqack(sd, f_sd, 0); clif_friendslist_reqack(sd, f_sd, 0);
} }
} }
@ -14397,15 +14398,15 @@ void clif_blacksmith(struct map_session_data* sd)
if (strcmp(smith_fame_list[i].name, "-") == 0 && if (strcmp(smith_fame_list[i].name, "-") == 0 &&
(name = map_charid2nick(smith_fame_list[i].id)) != NULL) (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
{ {
strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH); safestrncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
} else } else
strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH); safestrncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
} else } else
strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5); safestrncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame; WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
} }
for(;i < 10; i++) { //In case the MAX is less than 10. for(;i < 10; i++) { //In case the MAX is less than 10.
strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12); safestrncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
WFIFOL(fd, 242 + i * 4) = 0; WFIFOL(fd, 242 + i * 4) = 0;
} }
@ -14450,15 +14451,15 @@ void clif_alchemist(struct map_session_data* sd)
if (strcmp(chemist_fame_list[i].name, "-") == 0 && if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
(name = map_charid2nick(chemist_fame_list[i].id)) != NULL) (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
{ {
memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH); safestrncpy((char*)WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
} else } else
memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH); safestrncpy((char*)WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
} else } else
memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH); safestrncpy((char*)WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame; WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
} }
for(;i < 10; i++) { //In case the MAX is less than 10. for(;i < 10; i++) { //In case the MAX is less than 10.
memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH); safestrncpy((char*)WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
WFIFOL(fd, 242 + i * 4) = 0; WFIFOL(fd, 242 + i * 4) = 0;
} }
@ -14503,15 +14504,15 @@ void clif_taekwon(struct map_session_data* sd)
if (strcmp(taekwon_fame_list[i].name, "-") == 0 && if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
(name = map_charid2nick(taekwon_fame_list[i].id)) != NULL) (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
{ {
memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH); safestrncpy((char*)WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
} else } else
memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH); safestrncpy((char*)WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
} else } else
memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH); safestrncpy((char*)WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame; WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
} }
for(;i < 10; i++) { //In case the MAX is less than 10. for(;i < 10; i++) { //In case the MAX is less than 10.
memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH); safestrncpy((char*)WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
WFIFOL(fd, 242 + i * 4) = 0; WFIFOL(fd, 242 + i * 4) = 0;
} }
WFIFOSET(fd, packet_len(0x226)); WFIFOSET(fd, packet_len(0x226));
@ -14549,7 +14550,7 @@ void clif_ranking_pk(struct map_session_data* sd)
WFIFOHEAD(fd,packet_len(0x238)); WFIFOHEAD(fd,packet_len(0x238));
WFIFOW(fd,0) = 0x238; WFIFOW(fd,0) = 0x238;
for(i=0;i<10;i++){ for(i=0;i<10;i++){
memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH); safestrncpy((char*)WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
WFIFOL(fd,i*4+242) = 0; WFIFOL(fd,i*4+242) = 0;
} }
WFIFOSET(fd, packet_len(0x238)); WFIFOSET(fd, packet_len(0x238));
@ -14926,7 +14927,7 @@ void clif_Mail_refreshinbox(struct map_session_data *sd)
WFIFOL(fd,8+73*j) = msg->id; WFIFOL(fd,8+73*j) = msg->id;
memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH); memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD); WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH); safestrncpy((char*)WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
WFIFOL(fd,77+73*j) = (uint32)msg->timestamp; WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
j++; j++;
} }
@ -15785,7 +15786,7 @@ void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *sr
WFIFOW(fd,0) = 0x1f6; WFIFOW(fd,0) = 0x1f6;
WFIFOL(fd,2) = src->status.account_id; WFIFOL(fd,2) = src->status.account_id;
WFIFOL(fd,6) = p_id; WFIFOL(fd,6) = p_id;
memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH); safestrncpy((char*)WFIFOP(fd,10), src->status.name, NAME_LENGTH);
WFIFOSET(fd,34); WFIFOSET(fd,34);
} }
@ -15980,7 +15981,7 @@ void clif_quest_send_list(struct map_session_data *sd)
offset += 2; offset += 2;
WFIFOW(fd, offset) = qi->objectives[j].count; WFIFOW(fd, offset) = qi->objectives[j].count;
offset += 2; offset += 2;
memcpy(WFIFOP(fd, offset), mob->jname, NAME_LENGTH); safestrncpy(WFIFOP(fd, offset), mob->jname, NAME_LENGTH);
offset += NAME_LENGTH; offset += NAME_LENGTH;
} }
} }
@ -16033,7 +16034,7 @@ void clif_quest_send_mission(struct map_session_data *sd)
WFIFOL(fd, i*104+22+j*30) = qi->objectives[j].mob; WFIFOL(fd, i*104+22+j*30) = qi->objectives[j].mob;
WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j]; WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
mob = mob_db(qi->objectives[j].mob); mob = mob_db(qi->objectives[j].mob);
memcpy(WFIFOP(fd, i*104+28+j*30), mob->jname, NAME_LENGTH); safestrncpy((char*)WFIFOP(fd, i*104+28+j*30), mob->jname, NAME_LENGTH);
} }
} }
@ -16062,7 +16063,7 @@ void clif_quest_add(struct map_session_data *sd, struct quest *qd)
WFIFOL(fd, i*30+17) = qi->objectives[i].mob; WFIFOL(fd, i*30+17) = qi->objectives[i].mob;
WFIFOW(fd, i*30+21) = qd->count[i]; WFIFOW(fd, i*30+21) = qd->count[i];
mob = mob_db(qi->objectives[i].mob); mob = mob_db(qi->objectives[i].mob);
memcpy(WFIFOP(fd, i*30+23), mob->jname, NAME_LENGTH); safestrncpy((char*)WFIFOP(fd, i*30+23), mob->jname, NAME_LENGTH);
} }
WFIFOSET(fd, packet_len(0x2b3)); WFIFOSET(fd, packet_len(0x2b3));
@ -16393,7 +16394,7 @@ void clif_bg_hp(struct map_session_data *sd) {
WBUFW(buf,0) = cmd; WBUFW(buf,0) = cmd;
WBUFL(buf,2) = sd->status.account_id; WBUFL(buf,2) = sd->status.account_id;
#if PACKETVER < 20140613 #if PACKETVER < 20140613
memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH);
if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex] if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100); WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
WBUFW(buf,32) = 100; WBUFW(buf,32) = 100;
@ -16423,7 +16424,7 @@ void clif_bg_xy(struct map_session_data *sd)
WBUFW(buf,0)=0x2df; WBUFW(buf,0)=0x2df;
WBUFL(buf,2)=sd->status.account_id; WBUFL(buf,2)=sd->status.account_id;
memcpy(WBUFP(buf,6), sd->status.name, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH);
WBUFW(buf,30)=sd->status.class_; WBUFW(buf,30)=sd->status.class_;
WBUFW(buf,32)=sd->bl.x; WBUFW(buf,32)=sd->bl.x;
WBUFW(buf,34)=sd->bl.y; WBUFW(buf,34)=sd->bl.y;
@ -16461,7 +16462,7 @@ void clif_bg_message(struct battleground_data *bg, int src_id, const char *name,
WBUFW(buf,0) = 0x2dc; WBUFW(buf,0) = 0x2dc;
WBUFW(buf,2) = len + NAME_LENGTH + 8; WBUFW(buf,2) = len + NAME_LENGTH + 8;
WBUFL(buf,4) = src_id; WBUFL(buf,4) = src_id;
memcpy(WBUFP(buf,8), name, NAME_LENGTH); safestrncpy((char*)WBUFP(buf,8), name, NAME_LENGTH);
memcpy(WBUFP(buf,32), mes, len); memcpy(WBUFP(buf,32), mes, len);
clif_send(buf,WBUFW(buf,2), &sd->bl, BG); clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
@ -17796,17 +17797,17 @@ void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, i
if (strcmp(list[i].name, "-") == 0 && if (strcmp(list[i].name, "-") == 0 &&
(name = map_charid2nick(list[i].id)) != NULL) (name = map_charid2nick(list[i].id)) != NULL)
{ {
strncpy((char *)(WBUFP(buf,idx + 24 * i)), name, NAME_LENGTH); safestrncpy((char *)(WBUFP(buf,idx + 24 * i)), name, NAME_LENGTH);
} else { } else {
strncpy((char *)(WBUFP(buf,idx + 24 * i)), list[i].name, NAME_LENGTH); safestrncpy((char *)(WBUFP(buf,idx + 24 * i)), list[i].name, NAME_LENGTH);
} }
} else { } else {
strncpy((char *)(WBUFP(buf, idx + 24 * i)), "None", 5); safestrncpy((char *)(WBUFP(buf, idx + 24 * i)), "None", 5);
} }
WBUFL(buf, idx+24*10 + i * 4) = list[i].fame; //points WBUFL(buf, idx+24*10 + i * 4) = list[i].fame; //points
} }
for(;i < 10; i++) { //In case the MAX is less than 10. for(;i < 10; i++) { //In case the MAX is less than 10.
strncpy((char *)(WBUFP(buf, idx + 24 * i)), "Unavailable", 12); safestrncpy((char *)(WBUFP(buf, idx + 24 * i)), "Unavailable", 12);
WBUFL(buf, idx+24*10 + i * 4) = 0; WBUFL(buf, idx+24*10 + i * 4) = 0;
} }
} }

View File

@ -211,8 +211,8 @@ enum e_mapid {
#define CHATROOM_PASS_SIZE (8 + 1) #define CHATROOM_PASS_SIZE (8 + 1)
//Max allowed chat text length //Max allowed chat text length
#define CHAT_SIZE_MAX (255 + 1) #define CHAT_SIZE_MAX (255 + 1)
//24 for npc name + 24 for label + 2 for a "::" and 1 for EOS // <NPC_NAME_LENGTH> for npc name + 2 for a "::" + <NAME_LENGTH> for label + 1 for EOS
#define EVENT_NAME_LENGTH ( NAME_LENGTH * 2 + 3 ) #define EVENT_NAME_LENGTH ( NPC_NAME_LENGTH + 2 + NAME_LENGTH + 1 )
#define DEFAULT_AUTOSAVE_INTERVAL 5*60*1000 #define DEFAULT_AUTOSAVE_INTERVAL 5*60*1000

View File

@ -44,7 +44,7 @@ static int npc_cache_mob=0;
#if PACKETVER >= 20131223 #if PACKETVER >= 20131223
struct s_npc_market { struct s_npc_market {
struct npc_item_list *list; struct npc_item_list *list;
char exname[NAME_LENGTH+1]; char exname[NPC_NAME_LENGTH+1];
uint16 count; uint16 count;
}; };
static DBMap *NPCMarketDB; /// Stock persistency! Temporary market stocks from `market` table. struct s_npc_market, key: NPC exname static DBMap *NPCMarketDB; /// Stock persistency! Temporary market stocks from `market` table. struct s_npc_market, key: NPC exname
@ -336,6 +336,14 @@ static int npc_event_export(struct npc_data *nd, int i)
if ((lname[0] == 'O' || lname[0] == 'o') && (lname[1] == 'N' || lname[1] == 'n')) { if ((lname[0] == 'O' || lname[0] == 'o') && (lname[1] == 'N' || lname[1] == 'n')) {
struct event_data *ev; struct event_data *ev;
char buf[EVENT_NAME_LENGTH]; char buf[EVENT_NAME_LENGTH];
// NPC:<name> the prefix uses 4 characters
if( !strncasecmp( lname, script_config.onwhisper_event_name, NAME_LENGTH ) && strlen(nd->exname) > ( NAME_LENGTH - 4 ) ){
// The client only allows that many character so that NPC could not be whispered by unmodified clients
ShowWarning( "Whisper event in npc '"CL_WHITE"%s"CL_RESET"' was ignored, because it's name is too long.\n", nd->exname );
return 0;
}
snprintf(buf, ARRAYLENGTH(buf), "%s::%s", nd->exname, lname); snprintf(buf, ARRAYLENGTH(buf), "%s::%s", nd->exname, lname);
// generate the data and insert it // generate the data and insert it
CREATE(ev, struct event_data, 1); CREATE(ev, struct event_data, 1);
@ -430,7 +438,7 @@ int npc_event_doall(const char* name)
int npc_event_doall_id(const char* name, int rid) int npc_event_doall_id(const char* name, int rid)
{ {
int c = 0; int c = 0;
char buf[64]; char buf[EVENT_NAME_LENGTH];
safesnprintf(buf, sizeof(buf), "::%s", name); safesnprintf(buf, sizeof(buf), "::%s", name);
ev_db->foreach(ev_db,npc_event_doall_sub,&c,buf,rid); ev_db->foreach(ev_db,npc_event_doall_sub,&c,buf,rid);
return c; return c;
@ -445,7 +453,7 @@ int npc_event_do_clock(int tid, unsigned int tick, int id, intptr_t data)
static struct tm ev_tm_b; // tracks previous execution time static struct tm ev_tm_b; // tracks previous execution time
time_t timer; time_t timer;
struct tm* t; struct tm* t;
char buf[64]; char buf[EVENT_NAME_LENGTH];
int c = 0; int c = 0;
timer = time(NULL); timer = time(NULL);
@ -2222,27 +2230,27 @@ static void npc_parsename(struct npc_data* nd, const char* name, const char* sta
{ {
const char* p; const char* p;
struct npc_data* dnd;// duplicate npc struct npc_data* dnd;// duplicate npc
char newname[NAME_LENGTH]; char newname[NPC_NAME_LENGTH+1];
// parse name // parse name
p = strstr(name,"::"); p = strstr(name,"::");
if( p ) { // <Display name>::<Unique name> if( p ) { // <Display name>::<Unique name>
size_t len = p-name; size_t len = p-name;
if( len > NAME_LENGTH ) { if( len > NPC_NAME_LENGTH ) {
ShowWarning("npc_parsename: Display name of '%s' is too long (len=%u) in file '%s', line'%d'. Truncating to %u characters.\n", name, (unsigned int)len, filepath, strline(buffer,start-buffer), NAME_LENGTH); ShowWarning("npc_parsename: Display name of '%s' is too long (len=%u) in file '%s', line'%d'. Truncating to %u characters.\n", name, (unsigned int)len, filepath, strline(buffer,start-buffer), NPC_NAME_LENGTH);
safestrncpy(nd->name, name, sizeof(nd->name)); safestrncpy(nd->name, name, sizeof(nd->name));
} else { } else {
memcpy(nd->name, name, len); memcpy(nd->name, name, len);
memset(nd->name+len, 0, sizeof(nd->name)-len); memset(nd->name+len, 0, sizeof(nd->name)-len);
} }
len = strlen(p+2); len = strlen(p+2);
if( len > NAME_LENGTH ) if( len > NPC_NAME_LENGTH )
ShowWarning("npc_parsename: Unique name of '%s' is too long (len=%u) in file '%s', line'%d'. Truncating to %u characters.\n", name, (unsigned int)len, filepath, strline(buffer,start-buffer), NAME_LENGTH); ShowWarning("npc_parsename: Unique name of '%s' is too long (len=%u) in file '%s', line'%d'. Truncating to %u characters.\n", name, (unsigned int)len, filepath, strline(buffer,start-buffer), NPC_NAME_LENGTH);
safestrncpy(nd->exname, p+2, sizeof(nd->exname)); safestrncpy(nd->exname, p+2, sizeof(nd->exname));
} else {// <Display name> } else {// <Display name>
size_t len = strlen(name); size_t len = strlen(name);
if( len > NAME_LENGTH ) if( len > NPC_NAME_LENGTH )
ShowWarning("npc_parsename: Name '%s' is too long (len=%u) in file '%s', line'%d'. Truncating to %u characters.\n", name, (unsigned int)len, filepath, strline(buffer,start-buffer), NAME_LENGTH); ShowWarning("npc_parsename: Name '%s' is too long (len=%u) in file '%s', line'%d'. Truncating to %u characters.\n", name, (unsigned int)len, filepath, strline(buffer,start-buffer), NPC_NAME_LENGTH);
safestrncpy(nd->name, name, sizeof(nd->name)); safestrncpy(nd->name, name, sizeof(nd->name));
safestrncpy(nd->exname, name, sizeof(nd->exname)); safestrncpy(nd->exname, name, sizeof(nd->exname));
} }
@ -2773,9 +2781,9 @@ int npc_convertlabel_db(DBKey key, DBData *data, va_list ap)
len = p-lname; len = p-lname;
// here we check if the label fit into the buffer // here we check if the label fit into the buffer
if( len > 23 ) if( len > NAME_LENGTH )
{ {
ShowError("npc_parse_script: label name longer than 23 chars! '%s'\n (%s)", lname, filepath); ShowError("npc_parse_script: label name longer than %d chars! '%s'\n (%s)", NAME_LENGTH, lname, filepath);
return 0; return 0;
} }
@ -3152,7 +3160,7 @@ const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const ch
} }
int npc_duplicate4instance(struct npc_data *snd, int16 m) { int npc_duplicate4instance(struct npc_data *snd, int16 m) {
char newname[NAME_LENGTH]; char newname[NPC_NAME_LENGTH+1];
if( map[m].instance_id == 0 ) if( map[m].instance_id == 0 )
return 1; return 1;
@ -3393,7 +3401,7 @@ static void npc_market_fromsql(void) {
if (!(market = (struct s_npc_market *)strdb_get(NPCMarketDB,data))) { if (!(market = (struct s_npc_market *)strdb_get(NPCMarketDB,data))) {
CREATE(market, struct s_npc_market, 1); CREATE(market, struct s_npc_market, 1);
market->count = 0; market->count = 0;
safestrncpy(market->exname, data, strlen(data)+1); safestrncpy(market->exname, data, NPC_NAME_LENGTH);
strdb_put(NPCMarketDB, market->exname, market); strdb_put(NPCMarketDB, market->exname, market);
} }
@ -3550,7 +3558,7 @@ int npc_do_atcmd_event(struct map_session_data* sd, const char* command, const c
int l; int l;
ARR_FIND( 0, MAX_EVENTQUEUE, l, sd->eventqueue[l][0] == '\0' ); ARR_FIND( 0, MAX_EVENTQUEUE, l, sd->eventqueue[l][0] == '\0' );
if( l < MAX_EVENTQUEUE ) { if( l < MAX_EVENTQUEUE ) {
safestrncpy(sd->eventqueue[l],eventname,50); //Event enqueued. safestrncpy(sd->eventqueue[l],eventname,EVENT_NAME_LENGTH); //Event enqueued.
return 0; return 0;
} }
@ -4380,9 +4388,9 @@ void npc_read_event_script(void)
DBIterator* iter; DBIterator* iter;
DBKey key; DBKey key;
DBData *data; DBData *data;
char name[EVENT_NAME_LENGTH];
char name[64]="::"; safesnprintf(name,EVENT_NAME_LENGTH,"::%s",config[i].event_name);
safestrncpy(name+2,config[i].event_name,62);
script_event[i].event_count = 0; script_event[i].event_count = 0;
iter = db_iterator(ev_db); iter = db_iterator(ev_db);
@ -4627,11 +4635,11 @@ void do_init_npc(void){
for( i = MAX_NPC_CLASS2_START; i < MAX_NPC_CLASS2_END; i++ ) for( i = MAX_NPC_CLASS2_START; i < MAX_NPC_CLASS2_END; i++ )
npc_viewdb2[i - MAX_NPC_CLASS2_START].class_ = i; npc_viewdb2[i - MAX_NPC_CLASS2_START].class_ = i;
ev_db = strdb_alloc((DBOptions)(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA),2*NAME_LENGTH+2+1); ev_db = strdb_alloc((DBOptions)(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA), EVENT_NAME_LENGTH);
npcname_db = strdb_alloc(DB_OPT_BASE,NAME_LENGTH); npcname_db = strdb_alloc(DB_OPT_BASE, NPC_NAME_LENGTH+1);
npc_path_db = strdb_alloc(DB_OPT_BASE|DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA,80); npc_path_db = strdb_alloc(DB_OPT_BASE|DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA,80);
#if PACKETVER >= 20131223 #if PACKETVER >= 20131223
NPCMarketDB = strdb_alloc(DB_OPT_BASE, NAME_LENGTH+1); NPCMarketDB = strdb_alloc(DB_OPT_BASE, NPC_NAME_LENGTH+1);
npc_market_fromsql(); npc_market_fromsql();
#endif #endif

View File

@ -17,7 +17,7 @@ struct npc_timerevent_list {
}; };
struct npc_label_list { struct npc_label_list {
char name[NAME_LENGTH]; char name[NAME_LENGTH+1];
int pos; int pos;
}; };
@ -44,8 +44,8 @@ struct npc_data {
struct status_change sc; //They can't have status changes, but.. they want the visual opt values. struct status_change sc; //They can't have status changes, but.. they want the visual opt values.
struct npc_data *master_nd; struct npc_data *master_nd;
short class_,speed,instance_id; short class_,speed,instance_id;
char name[NAME_LENGTH+1];// display name char name[NPC_NAME_LENGTH+1];// display name
char exname[NAME_LENGTH+1];// unique npc name char exname[NPC_NAME_LENGTH+1];// unique npc name
int chat_id,touching_id; int chat_id,touching_id;
unsigned int next_walktime; unsigned int next_walktime;

View File

@ -185,6 +185,7 @@ struct Script_Config script_config = {
1, // warn_func_mismatch_argtypes 1, // warn_func_mismatch_argtypes
1, 65535, 2048, //warn_func_mismatch_paramnum/check_cmdcount/check_gotocount 1, 65535, 2048, //warn_func_mismatch_paramnum/check_cmdcount/check_gotocount
0, INT_MAX, // input_min_value/input_max_value 0, INT_MAX, // input_min_value/input_max_value
// NOTE: None of these event labels should be longer than <NAME_LENGTH> characters
"OnPCDieEvent", //die_event_name "OnPCDieEvent", //die_event_name
"OnPCKillEvent", //kill_pc_event_name "OnPCKillEvent", //kill_pc_event_name
"OnNPCKillEvent", //kill_mob_event_name "OnNPCKillEvent", //kill_mob_event_name
@ -196,6 +197,7 @@ struct Script_Config script_config = {
"OnPCStatCalcEvent", //stat_calc_event_name "OnPCStatCalcEvent", //stat_calc_event_name
"OnTouch_", //ontouch_name (runs on first visible char to enter area, picks another char if the first char leaves) "OnTouch_", //ontouch_name (runs on first visible char to enter area, picks another char if the first char leaves)
"OnTouch", //ontouch2_name (run whenever a char walks into the OnTouch area) "OnTouch", //ontouch2_name (run whenever a char walks into the OnTouch area)
"OnWhisperGlobal", //onwhisper_event_name (is executed when a player sends a whisper message to the NPC)
}; };
static jmp_buf error_jump; static jmp_buf error_jump;

View File

@ -160,6 +160,7 @@ extern struct Script_Config {
const char* ontouch_name; const char* ontouch_name;
const char* ontouch2_name; const char* ontouch2_name;
const char* onwhisper_event_name;
} script_config; } script_config;
typedef enum c_op { typedef enum c_op {