diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 2b73803d8c..21af57e5a4 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -8020,9 +8020,9 @@ ACMD_FUNC(fakename) if( sd->fakename[0] ) { sd->fakename[0] = '\0'; - clif_charnameack(0, &sd->bl); + clif_name_area(&sd->bl); if (sd->disguise) - clif_charnameack(sd->fd, &sd->bl); + clif_name_self(&sd->bl); clif_displaymessage(sd->fd, msg_txt(sd,1307)); // Returned to real name. return 0; } @@ -8038,9 +8038,9 @@ ACMD_FUNC(fakename) } safestrncpy(sd->fakename, message, sizeof(sd->fakename)); - clif_charnameack(0, &sd->bl); + clif_name_area(&sd->bl); if (sd->disguise) // Another packet should be sent so the client updates the name for sd - clif_charnameack(sd->fd, &sd->bl); + clif_name_self(&sd->bl); clif_displaymessage(sd->fd, msg_txt(sd,1310)); // Fake name enabled. return 0; diff --git a/src/map/clif.c b/src/map/clif.c index 466a56eb70..62c2cd83ff 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -7989,14 +7989,16 @@ void clif_guild_created(struct map_session_data *sd,int flag) /// mode: /// &0x01 = allow invite /// &0x10 = allow expel -void clif_guild_belonginfo(struct map_session_data *sd, struct guild *g) +void clif_guild_belonginfo(struct map_session_data *sd) { int ps,fd; + struct guild* g; + nullpo_retv(sd); - nullpo_retv(g); + nullpo_retv(g = sd->guild); fd=sd->fd; - ps=guild_getposition(g,sd); + ps=guild_getposition(sd); WFIFOHEAD(fd,packet_len(0x16c)); WFIFOW(fd,0)=0x16c; WFIFOL(fd,2)=g->guild_id; @@ -8402,12 +8404,13 @@ void clif_guild_skillinfo(struct map_session_data* sd) /// Sends guild notice to client (ZC_GUILD_NOTICE). /// 016f .60B .120B -void clif_guild_notice(struct map_session_data* sd, struct guild* g) +void clif_guild_notice(struct map_session_data* sd) { int fd; + struct guild* g; nullpo_retv(sd); - nullpo_retv(g); + nullpo_retv(g = sd->guild); fd = sd->fd; @@ -9240,14 +9243,16 @@ void clif_refresh(struct map_session_data *sd) /// Updates the object's (bl) name on client. +/// Used to update when a char leaves a party/guild. [Skotlex] +/// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent. /// 0095 .L .24B (ZC_ACK_REQNAME) /// 0195 .L .24B .24B .24B .24B (ZC_ACK_REQNAMEALL) /// 0a30 .L .24B .24B .24B .24B .L (ZC_ACK_REQNAMEALL2) -void clif_charnameack (int fd, struct block_list *bl) -{ +void clif_name( struct block_list* src, struct block_list *bl, send_target target ){ unsigned char buf[106]; int cmd = 0x95; + nullpo_retv(src); nullpo_retv(bl); WBUFW(buf,0) = cmd; @@ -9267,7 +9272,7 @@ void clif_charnameack (int fd, struct block_list *bl) #endif //Requesting your own "shadow" name. [Skotlex] - if( sd->fd == fd && sd->disguise ){ + if( src == bl && target == SELF && sd->disguise ){ WBUFL(buf,2) = -bl->id; } @@ -9293,12 +9298,13 @@ void clif_charnameack (int fd, struct block_list *bl) } if( sd->guild ){ - int i; + int position; - ARR_FIND(0, sd->guild->max_member, i, sd->guild->member[i].account_id == sd->status.account_id && sd->guild->member[i].char_id == sd->status.char_id); + // Will get the position of the guild the player is in + position = guild_getposition(sd); safestrncpy(WBUFCP(buf,54), sd->guild->name,NAME_LENGTH); - safestrncpy(WBUFCP(buf,78), sd->guild->position[i].name, NAME_LENGTH); + safestrncpy(WBUFCP(buf,78), sd->guild->position[position].name, NAME_LENGTH); }else{ //Assume no guild. WBUFB(buf,54) = 0; WBUFB(buf,78) = 0; @@ -9365,76 +9371,13 @@ void clif_charnameack (int fd, struct block_list *bl) safestrncpy(WBUFCP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH); break; default: - ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id); + ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id); return; } - // if no receipient specified just update nearby clients - if (fd == 0) - clif_send(buf, packet_len(cmd), bl, AREA); - else { - WFIFOHEAD(fd, packet_len(cmd)); - memcpy(WFIFOP(fd, 0), buf, packet_len(cmd)); - WFIFOSET(fd, packet_len(cmd)); - } + clif_send(buf, packet_len(cmd), src, target); } - -//Used to update when a char leaves a party/guild. [Skotlex] -//Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent. -void clif_charnameupdate (struct map_session_data *ssd) -{ - unsigned char buf[103]; - int cmd = 0x195, ps = -1; - struct party_data *p = NULL; - struct guild *g = NULL; - - nullpo_retv(ssd); - - if( ssd->fakename[0] ) - return; //No need to update as the party/guild was not displayed anyway. - - WBUFW(buf,0) = cmd; - WBUFL(buf,2) = ssd->bl.id; - - safestrncpy(WBUFCP(buf,6), ssd->status.name, NAME_LENGTH); - - if (!battle_config.display_party_name) { - if (ssd->status.party_id > 0 && ssd->status.guild_id > 0 && (g = ssd->guild) != NULL) - p = party_search(ssd->status.party_id); - }else{ - if (ssd->status.party_id > 0) - p = party_search(ssd->status.party_id); - } - - if( ssd->status.guild_id > 0 && (g = ssd->guild) != NULL ) - { - int i; - ARR_FIND(0, g->max_member, i, g->member[i].account_id == ssd->status.account_id && g->member[i].char_id == ssd->status.char_id); - if( i < g->max_member ) ps = g->member[i].position; - } - - if( p ) - safestrncpy(WBUFCP(buf,30), p->party.name, NAME_LENGTH); - else - WBUFB(buf,30) = 0; - - if( g && ps >= 0 && ps < MAX_GUILDPOSITION ) - { - safestrncpy(WBUFCP(buf,54), g->name,NAME_LENGTH); - safestrncpy(WBUFCP(buf,78), g->position[ps].name, NAME_LENGTH); - } - else - { - WBUFB(buf,54) = 0; - WBUFB(buf,78) = 0; - } - - // Update nearby clients - clif_send(buf, packet_len(cmd), &ssd->bl, AREA); -} - - /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP). /// 01ff <id>.L <x>.W <y>.W /// @@ -10308,7 +10251,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd) #endif if (sd->guild && battle_config.guild_notice_changemap == 1) - clif_guild_notice(sd, sd->guild); // Displays after VIP + clif_guild_notice(sd); // Displays after VIP if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) && (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) ) @@ -10367,7 +10310,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd) if( channel_config.map_enable && channel_config.map_autojoin && !map[sd->bl.m].flag.chmautojoin && !map[sd->bl.m].instance_id ) channel_mjoin(sd); //join new map } else if (sd->guild && (battle_config.guild_notice_changemap == 2 || guild_notice)) - clif_guild_notice(sd, sd->guild); // Displays at end + clif_guild_notice(sd); // Displays at end mail_clear(sd); @@ -10676,7 +10619,7 @@ void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd) } */ - clif_charnameack(fd, bl); + clif_name(&sd->bl,bl,SELF); } diff --git a/src/map/clif.h b/src/map/clif.h index 03049c5dcb..eb90ba2e9a 100644 --- a/src/map/clif.h +++ b/src/map/clif.h @@ -672,8 +672,9 @@ void clif_wis_message(int fd, const char* nick, const char* mes, int mes_len); void clif_wis_end(int fd, int result); void clif_solved_charname(int fd, int charid, const char* name); -void clif_charnameack(int fd, struct block_list *bl); -void clif_charnameupdate(struct map_session_data *ssd); +void clif_name( struct block_list* src, struct block_list *bl, send_target target ); +#define clif_name_self(bl) clif_name( (bl), (bl), SELF ) +#define clif_name_area(bl) clif_name( (bl), (bl), AREA ) void clif_use_card(struct map_session_data *sd,int idx); void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag); @@ -731,7 +732,7 @@ void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp); // guild void clif_guild_created(struct map_session_data *sd,int flag); -void clif_guild_belonginfo(struct map_session_data *sd, struct guild *g); +void clif_guild_belonginfo(struct map_session_data *sd); void clif_guild_masterormember(struct map_session_data *sd); void clif_guild_basicinfo(struct map_session_data *sd); void clif_guild_allianceinfo(struct map_session_data *sd); @@ -747,7 +748,7 @@ void clif_guild_positionchanged(struct guild *g,int idx); void clif_guild_memberpositionchanged(struct guild *g,int idx); void clif_guild_emblem(struct map_session_data *sd,struct guild *g); void clif_guild_emblem_area(struct block_list* bl); -void clif_guild_notice(struct map_session_data* sd, struct guild* g); +void clif_guild_notice(struct map_session_data* sd); void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len); void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name); void clif_guild_allianceack(struct map_session_data *sd,int flag); diff --git a/src/map/guild.c b/src/map/guild.c index 52b2d423c0..0715c6593a 100644 --- a/src/map/guild.c +++ b/src/map/guild.c @@ -241,11 +241,11 @@ int guild_getindex(struct guild *g,uint32 account_id,uint32 char_id) { } /// lookup: player sd -> member position -int guild_getposition(struct guild* g, struct map_session_data* sd) { +int guild_getposition(struct map_session_data* sd) { int i; + struct guild *g; - if( g == NULL && (g=sd->guild) == NULL ) - return -1; + nullpo_retr( -1, g = sd->guild ); ARR_FIND( 0, g->max_member, i, g->member[i].account_id == sd->status.account_id && g->member[i].char_id == sd->status.char_id ); return( i < g->max_member ) ? g->member[i].position : -1; @@ -505,7 +505,7 @@ int guild_recv_info(struct guild *sg) { //Also set the guild master flag. sd->guild = g; sd->state.gmaster_flag = 1; - clif_charnameupdate(sd); // [LuzZza] + clif_name_area(&sd->bl); // [LuzZza] clif_guild_masterormember(sd); } } else { @@ -521,7 +521,7 @@ int guild_recv_info(struct guild *sg) { for(i=bm=m=0;i<g->max_member;i++){ if(g->member[i].account_id>0){ sd = g->member[i].sd = guild_sd_check(g->guild_id, g->member[i].account_id, g->member[i].char_id); - if (sd) clif_charnameupdate(sd); // [LuzZza] + if (sd) clif_name_area(&sd->bl); // [LuzZza] m++; }else g->member[i].sd=NULL; @@ -552,8 +552,8 @@ int guild_recv_info(struct guild *sg) { clif_guild_skillinfo(sd); //Submit information skills if (guild_new) { // Send information and affiliation if unsent - clif_guild_belonginfo(sd, g); - clif_guild_notice(sd, g); + clif_guild_belonginfo(sd); + clif_guild_notice(sd); sd->guild_emblem_id = g->emblem_id; } if (g->instance_id != 0) @@ -588,7 +588,7 @@ int guild_invite(struct map_session_data *sd, struct map_session_data *tsd) { if(tsd==NULL || g==NULL) return 0; - if( (i=guild_getposition(g,sd))<0 || !(g->position[i].mode&0x0001) ) + if( (i=guild_getposition(sd))<0 || !(g->position[i].mode&0x0001) ) return 0; //Invite permission. if(!battle_config.invite_request_check) { @@ -742,8 +742,8 @@ int guild_member_added(int guild_id,uint32 account_id,uint32 char_id,int flag) { sd->guild_emblem_id = g->emblem_id; sd->guild = g; //Packets which were sent in the previous 'guild_sent' implementation. - clif_guild_belonginfo(sd,g); - clif_guild_notice(sd,g); + clif_guild_belonginfo(sd); + clif_guild_notice(sd); //TODO: send new emblem info to others @@ -800,7 +800,7 @@ int guild_expulsion(struct map_session_data* sd, int guild_id, uint32 account_id if(sd->status.guild_id!=guild_id) return 0; - if( (ps=guild_getposition(g,sd))<0 || !(g->position[ps].mode&0x0010) ) + if( (ps=guild_getposition(sd))<0 || !(g->position[ps].mode&0x0010) ) return 0; //Expulsion permission //Can't leave inside guild castles. @@ -883,7 +883,7 @@ int guild_member_withdraw(int guild_id, uint32 account_id, uint32 char_id, int f } } - clif_charnameupdate(sd); //Update display name [Skotlex] + clif_name_area(&sd->bl); //Update display name [Skotlex] status_change_end(&sd->bl,SC_LEADERSHIP,INVALID_TIMER); status_change_end(&sd->bl,SC_GLORYWOUNDS,INVALID_TIMER); status_change_end(&sd->bl,SC_SOULCOLD,INVALID_TIMER); @@ -960,7 +960,7 @@ int guild_send_memberinfoshort(struct map_session_data *sd,int online) { // clea } if(sd->state.connect_new) { //Note that this works because it is invoked in parse_LoadEndAck before connect_new is cleared. - clif_guild_belonginfo(sd,g); + clif_guild_belonginfo(sd); sd->guild_emblem_id = g->emblem_id; } return 0; @@ -1074,7 +1074,7 @@ int guild_memberposition_changed(struct guild *g,int idx,int pos) { // Update char position in client [LuzZza] if(g->member[idx].sd != NULL) - clif_charnameupdate(g->member[idx].sd); + clif_name_area(&g->member[idx].sd->bl); return 0; } @@ -1108,7 +1108,7 @@ int guild_position_changed(int guild_id,int idx,struct guild_position *p) { // Update char name in client [LuzZza] for(i=0;i<g->max_member;i++) if(g->member[i].position == idx && g->member[i].sd != NULL) - clif_charnameupdate(g->member[i].sd); + clif_name_area(&g->member[i].sd->bl); return 0; } @@ -1138,7 +1138,7 @@ int guild_notice_changed(int guild_id,const char *mes1,const char *mes2) { for(i=0;i<g->max_member;i++){ struct map_session_data *sd = g->member[i].sd; if(sd != NULL) - clif_guild_notice(sd,g); + clif_guild_notice(sd); } return 0; } @@ -1176,7 +1176,7 @@ int guild_emblem_changed(int len,int guild_id,int emblem_id,const char *data) { for(i=0;i<g->max_member;i++){ if((sd=g->member[i].sd)!=NULL){ sd->guild_emblem_id=emblem_id; - clif_guild_belonginfo(sd,g); + clif_guild_belonginfo(sd); clif_guild_emblem(sd,g); clif_guild_emblem_area(&sd->bl); } @@ -1248,7 +1248,7 @@ unsigned int guild_payexp(struct map_session_data *sd,unsigned int exp) { if (sd->status.guild_id == 0 || (g = sd->guild) == NULL || - (per = guild_getposition(g,sd)) < 0 || + (per = guild_getposition(sd)) < 0 || (per = g->position[per].exp_mode) < 1) return 0; @@ -1729,7 +1729,7 @@ int guild_broken(int guild_id,int flag) { sd->guild = NULL; sd->state.gmaster_flag = 0; clif_guild_broken(g->member[i].sd,0); - clif_charnameupdate(sd); // [LuzZza] + clif_name_area(&sd->bl); // [LuzZza] status_change_end(&sd->bl,SC_LEADERSHIP,INVALID_TIMER); status_change_end(&sd->bl,SC_GLORYWOUNDS,INVALID_TIMER); status_change_end(&sd->bl,SC_SOULCOLD,INVALID_TIMER); diff --git a/src/map/guild.h b/src/map/guild.h index fd5215aa1a..3e05373134 100644 --- a/src/map/guild.h +++ b/src/map/guild.h @@ -40,7 +40,7 @@ struct guild_castle* guild_mapindex2gc(short mapindex); struct map_session_data *guild_getavailablesd(struct guild *g); int guild_getindex(struct guild *g,uint32 account_id,uint32 char_id); -int guild_getposition(struct guild *g, struct map_session_data *sd); +int guild_getposition(struct map_session_data *sd); unsigned int guild_payexp(struct map_session_data *sd,unsigned int exp); int guild_getexp(struct map_session_data *sd,int exp); // [Celest] diff --git a/src/map/homunculus.c b/src/map/homunculus.c index 5808262e9f..c3de36d98b 100644 --- a/src/map/homunculus.c +++ b/src/map/homunculus.c @@ -959,7 +959,7 @@ void hom_change_name_ack(struct map_session_data *sd, char* name, int flag) return; } safestrncpy(hd->homunculus.name,name,NAME_LENGTH); - clif_charnameack (0,&hd->bl); + clif_name_area(&hd->bl); hd->homunculus.rename_flag = 1; clif_hominfo(sd,hd,0); } diff --git a/src/map/mob.c b/src/map/mob.c index 3b5a571339..76eee531ad 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -2244,7 +2244,7 @@ void mob_damage(struct mob_data *md, struct block_list *src, int damage) } if (battle_config.show_mob_info&3) - clif_charnameack(0, &md->bl); + clif_name_area(&md->bl); #if PACKETVER >= 20120404 if( battle_config.monster_hp_bars_info){ @@ -2912,7 +2912,7 @@ void mob_revive(struct mob_data *md, unsigned int hp) skill_unit_move(&md->bl,tick,1); mobskill_use(md, tick, MSC_SPAWN); if (battle_config.show_mob_info&3) - clif_charnameack (0, &md->bl); + clif_name_area(&md->bl); } int mob_guardian_guildchange(struct mob_data *md) @@ -3045,7 +3045,7 @@ int mob_class_change (struct mob_data *md, int mob_id) md->target_id = md->attacked_id = md->norm_attacked_id = 0; //Need to update name display. - clif_charnameack(0, &md->bl); + clif_name_area(&md->bl); return 0; } @@ -3055,7 +3055,7 @@ int mob_class_change (struct mob_data *md, int mob_id) void mob_heal(struct mob_data *md,unsigned int heal) { if (battle_config.show_mob_info&3) - clif_charnameack (0, &md->bl); + clif_name_area(&md->bl); #if PACKETVER >= 20120404 if( battle_config.monster_hp_bars_info){ int i; diff --git a/src/map/npc.c b/src/map/npc.c index c4da18d04a..174de92949 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -3516,7 +3516,7 @@ void npc_setdisplayname(struct npc_data* nd, const char* newname) safestrncpy(nd->name, newname, sizeof(nd->name)); if( map[nd->bl.m].users ) - clif_charnameack(0, &nd->bl); + clif_name_area(&nd->bl); } /// Changes the display class of the npc. diff --git a/src/map/party.c b/src/map/party.c index 29e6732b51..aa8c68f714 100644 --- a/src/map/party.c +++ b/src/map/party.c @@ -332,7 +332,7 @@ int party_recv_info(struct party* sp, uint32 char_id) if( sd == NULL ) continue;// not online - clif_charnameupdate(sd); //Update other people's display. [Skotlex] + clif_name_area(&sd->bl); //Update other people's display. [Skotlex] clif_party_member_info(p,sd); // Only send this on party creation, otherwise it will be sent by party_send_movemap [Lemongrass] if( sd->party_creating ){ @@ -536,7 +536,7 @@ int party_member_added(int party_id,uint32 account_id,uint32 char_id, int flag) clif_party_hp(sd); clif_party_xy(sd); - clif_charnameupdate(sd); //Update char name's display [Skotlex] + clif_name_area(&sd->bl); //Update char name's display [Skotlex] if( p->instance_id ) instance_reqinfo(sd,p->instance_id); @@ -647,7 +647,7 @@ int party_member_withdraw(int party_id, uint32 account_id, uint32 char_id, char #endif sd->status.party_id = 0; - clif_charnameupdate(sd); //Update name display [Skotlex] + clif_name_area(&sd->bl); //Update name display [Skotlex] //TODO: hp bars should be cleared too if( p->instance_id ) { diff --git a/src/map/pc.c b/src/map/pc.c index 95ce955600..ef43cfd97b 100755 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -7642,7 +7642,7 @@ int pc_dead(struct map_session_data *sd,struct block_list *src) if( battle_config.show_mob_info&4 ) {// update name with new level - clif_charnameack(0, &md->bl); + clif_name_area(&md->bl); } } src = battle_get_master(src); // Maybe Player Summon diff --git a/src/map/pet.c b/src/map/pet.c index c77ccaf312..35a2bbff56 100644 --- a/src/map/pet.c +++ b/src/map/pet.c @@ -838,7 +838,7 @@ int pet_change_name_ack(struct map_session_data *sd, char* name, int flag) } memcpy(pd->pet.name, name, NAME_LENGTH); - clif_charnameack (0,&pd->bl); + clif_name_area(&pd->bl); pd->pet.rename_flag = 1; clif_pet_equip_area(pd); clif_send_petstatus(sd); diff --git a/src/map/script.c b/src/map/script.c index 2e09f1312c..49f0f2609f 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -17232,8 +17232,8 @@ BUILDIN_FUNC(setunitdata) switch (type) { case UMOB_SIZE: md->status.size = (unsigned char)value; break; case UMOB_LEVEL: md->level = (unsigned short)value; break; - case UMOB_HP: status_set_hp(bl, (unsigned int)value, 0); clif_charnameack(0, &md->bl); break; - case UMOB_MAXHP: status_set_maxhp(bl, (unsigned int)value, 0); clif_charnameack(0, &md->bl); break; + case UMOB_HP: status_set_hp(bl, (unsigned int)value, 0); clif_name_area(&md->bl); break; + case UMOB_MAXHP: status_set_maxhp(bl, (unsigned int)value, 0); clif_name_area(&md->bl); break; case UMOB_MASTERAID: md->master_id = value; break; case UMOB_MAPID: if (mapname) value = map_mapname2mapid(mapname); unit_warp(bl, (short)value, 0, 0, CLR_TELEPORT); break; case UMOB_X: if (!unit_walktoxy(bl, (short)value, md->bl.y, 2)) unit_movepos(bl, (short)value, md->bl.y, 0, 0); break; @@ -17637,7 +17637,7 @@ BUILDIN_FUNC(setunitname) ShowWarning("buildin_setunitname: Unknown object type!\n"); return SCRIPT_CMD_FAILURE; } - clif_charnameack(0, bl); // Send update to client. + clif_name_area(bl); // Send update to client. return SCRIPT_CMD_SUCCESS; } @@ -18893,7 +18893,7 @@ BUILDIN_FUNC(bg_monster_set_team) mob_stop_attack(md); mob_stop_walking(md, 0); md->target_id = md->attacked_id = 0; - clif_charnameack(0, &md->bl); + clif_name_area(&md->bl); return SCRIPT_CMD_SUCCESS; }