diff options
Diffstat (limited to 'src/map/clif.c')
-rw-r--r-- | src/map/clif.c | 95 |
1 files changed, 53 insertions, 42 deletions
diff --git a/src/map/clif.c b/src/map/clif.c index a04ac0e27..e51c59461 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -578,12 +578,12 @@ int clif_send(const void* buf, int len, struct block_list* bl, enum send_target struct hQueue *queue = &script->hq[sd->bg_queue.arena->queue_id]; for( i = 0; i < queue->size; i++ ) { - struct map_session_data * sd = NULL; + struct map_session_data *qsd = NULL; - if( queue->item[i] > 0 && ( sd = map->id2sd(queue->item[i]) ) ) { - WFIFOHEAD(sd->fd,len); - memcpy(WFIFOP(sd->fd,0), buf, len); - WFIFOSET(sd->fd,len); + if( queue->item[i] > 0 && ( qsd = map->id2sd(queue->item[i]) ) ) { + WFIFOHEAD(qsd->fd,len); + memcpy(WFIFOP(qsd->fd,0), buf, len); + WFIFOSET(qsd->fd,len); } } } @@ -930,6 +930,8 @@ void clif_set_unit_idle(struct block_list* bl, struct map_session_data *tsd, enu struct view_data* vd = status->get_viewdata(bl); struct packet_idle_unit p; int g_id = status->get_guild_id(bl); + + nullpo_retv(bl); #if PACKETVER < 20091103 if( !pcdb_checkid(vd->class_) ) { @@ -1060,6 +1062,8 @@ void clif_spawn_unit(struct block_list* bl, enum send_target target) { struct packet_spawn_unit p; int g_id = status->get_guild_id(bl); + nullpo_retv(bl); + #if PACKETVER < 20091103 if( !pcdb_checkid(vd->class_) ) { clif->spawn_unit2(bl,target); @@ -1123,6 +1127,7 @@ void clif_spawn_unit(struct block_list* bl, enum send_target target) { } #endif if( disguised(bl) ) { + nullpo_retv(sd); if( sd->status.class_ != sd->disguise ) clif->send(&p,sizeof(p),bl,target); #if PACKETVER >= 20091103 @@ -1146,6 +1151,8 @@ void clif_set_unit_walking(struct block_list* bl, struct map_session_data *tsd, struct view_data* vd = status->get_viewdata(bl); struct packet_unit_walking p; int g_id = status->get_guild_id(bl); + + nullpo_retv(bl); sd = BL_CAST(BL_PC, bl); @@ -1831,7 +1838,7 @@ void clif_selllist(struct map_session_data *sd) /// - append this text void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes) { int fd = sd->fd; - int slen = strlen(mes) + 9; + size_t slen = strlen(mes) + 9; sd->state.dialog = 1; @@ -1943,7 +1950,7 @@ void clif_sendfakenpc(struct map_session_data *sd, int npcid) { /// TODO investigate behavior of other windows [FlavioJS] void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes) { int fd = sd->fd; - int slen = strlen(mes) + 9; + size_t slen = strlen(mes) + 9; struct block_list *bl = NULL; if (!sd->state.using_fake_npc && (npcid == npc->fake_nd->bl.id || ((bl = map->id2bl(npcid)) && (bl->m!=sd->bl.m || @@ -2714,7 +2721,7 @@ void read_channels_config(void) { if( (colors = config_setting_get_member(settings, "colors")) != NULL ) { int color_count = config_setting_length(colors); - CREATE( hChSys.colors, unsigned long, color_count ); + CREATE( hChSys.colors, unsigned int, color_count ); CREATE( hChSys.colors_name, char *, color_count ); for(i = 0; i < color_count; i++) { config_setting_t *color = config_setting_get_elem(colors, i); @@ -2723,7 +2730,7 @@ void read_channels_config(void) { safestrncpy(hChSys.colors_name[i], config_setting_name(color), HCHSYS_NAME_LENGTH); - hChSys.colors[i] = strtoul(config_setting_get_string_elem(colors,i),NULL,0); + hChSys.colors[i] = (unsigned int)strtoul(config_setting_get_string_elem(colors,i),NULL,0); hChSys.colors[i] = (hChSys.colors[i] & 0x0000FF) << 16 | (hChSys.colors[i] & 0x00FF00) | (hChSys.colors[i] & 0xFF0000) >> 16;//RGB to BGR } hChSys.colors_count = color_count; @@ -3141,7 +3148,7 @@ void clif_changelook(struct block_list *bl,int type,int val) sd = BL_CAST(BL_PC, bl); sc = status->get_sc(bl); vd = status->get_viewdata(bl); - //nullpo_ret(vd); + if( vd ) //temp hack to let Warp Portal change appearance switch(type) { case LOOK_WEAPON: @@ -3250,6 +3257,7 @@ void clif_changelook(struct block_list *bl,int type,int val) WBUFW(buf,0)=0x1d7; WBUFL(buf,2)=bl->id; if(type == LOOK_WEAPON || type == LOOK_SHIELD) { + nullpo_retv(vd); WBUFB(buf,6)=LOOK_WEAPON; WBUFW(buf,7)=vd->weapon; WBUFW(buf,9)=vd->shield; @@ -3258,7 +3266,7 @@ void clif_changelook(struct block_list *bl,int type,int val) WBUFL(buf,7)=val; } clif->send(buf,packet_len(0x1d7),bl,target); - if( disguised(bl) && ((TBL_PC*)sd)->fontcolor ) { + if( disguised(bl) && sd && sd->fontcolor ) { WBUFL(buf,2)=-bl->id; clif->send(buf,packet_len(0x1d7),bl,SELF); } @@ -4696,6 +4704,7 @@ int clif_outsight(struct block_list *bl,va_list ap) tsd = BL_CAST(BL_PC, tbl); if (tsd && tsd->fd) { //tsd has lost sight of the bl object. + nullpo_ret(bl); switch(bl->type){ case BL_PC: if (sd->vd.class_ != INVISIBLE_CLASS) @@ -4728,6 +4737,7 @@ int clif_outsight(struct block_list *bl,va_list ap) } } if (sd && sd->fd) { //sd is watching tbl go out of view. + nullpo_ret(tbl); if (((vd=status->get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS) && !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->option&OPTION_INVISIBLE))) clif->clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd); @@ -4750,6 +4760,7 @@ int clif_insight(struct block_list *bl,va_list ap) tsd = BL_CAST(BL_PC, tbl); if (tsd && tsd->fd) { //Tell tsd that bl entered into his view + nullpo_ret(bl); switch(bl->type) { case BL_ITEM: clif->getareachar_item(tsd,(struct flooritem_data*)bl); @@ -5528,7 +5539,7 @@ void clif_displaymessage(const int fd, const char* mes) { if( fd == -2 ) { ShowInfo("HCP: %s\n",mes); } else if ( fd > 0 ) { - int len; + size_t len; if ( ( len = strnlen(mes, 255) ) > 0 ) { // don't send a void message (it's not displaying on the client chat). @help can send void line. WFIFOHEAD(fd, 5 + len); @@ -5554,7 +5565,7 @@ void clif_displaymessage2(const int fd, const char* mes) { line = strtok(message, "\n"); while(line != NULL) { // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client) - int len = strnlen(line, 255); + size_t len = strnlen(line, 255); if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line. if( fd == -2 ) { @@ -5606,7 +5617,7 @@ void clif_displaymessage_sprintf(const int fd, const char* mes, ...) { } /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST). /// 009a <packet len>.W <message>.?B -void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target) +void clif_broadcast(struct block_list* bl, const char* mes, size_t len, int type, enum send_target target) { int lp = (type&BC_COLOR_MASK) ? 4 : 0; unsigned char *buf = (unsigned char*)aMalloc((4 + lp + len)*sizeof(unsigned char)); @@ -5630,7 +5641,7 @@ void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, e *------------------------------------------*/ void clif_GlobalMessage(struct block_list* bl, const char* message) { char buf[256]; - int len; + size_t len; nullpo_retv(bl); if(!message) @@ -5653,7 +5664,7 @@ void clif_GlobalMessage(struct block_list* bl, const char* message) { /// Send broadcast message with font formatting (ZC_BROADCAST2). /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B -void clif_broadcast2(struct block_list* bl, const char* mes, int len, unsigned long fontColor, short fontType, short fontSize, short fontAlign, short fontY, enum send_target target) +void clif_broadcast2(struct block_list* bl, const char* mes, size_t len, unsigned int fontColor, short fontType, short fontSize, short fontAlign, short fontY, enum send_target target) { unsigned char *buf = (unsigned char*)aMalloc((16 + len)*sizeof(unsigned char)); @@ -5829,7 +5840,7 @@ void clif_upgrademessage(int fd, int result, int item_id) /// Whisper is transmitted to the destination player (ZC_WHISPER). /// 0097 <packet len>.W <nick>.24B <message>.?B /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104) -void clif_wis_message(int fd, const char* nick, const char* mes, int mes_len) { +void clif_wis_message(int fd, const char* nick, const char* mes, size_t mes_len) { #if PACKETVER < 20091104 WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4); WFIFOW(fd,0) = 0x97; @@ -8053,14 +8064,14 @@ void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_sess /*========================================== * *------------------------------------------*/ -void clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len) { +void clif_disp_onlyself(struct map_session_data *sd, const char *mes, size_t len) { clif->disp_message(&sd->bl, mes, len, SELF); } /*========================================== * Displays a message using the guild-chat colors to the specified targets. [Skotlex] *------------------------------------------*/ -void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target) +void clif_disp_message(struct block_list* src, const char* mes, size_t len, enum send_target target) { unsigned char buf[256]; @@ -8317,7 +8328,7 @@ void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, sen // Modification of clif_messagecolor to send colored messages to players to chat log only (doesn't display overhead) /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B int clif_colormes(int fd, enum clif_colors color, const char* msg) { - unsigned short msg_len = strlen(msg) + 1; + size_t msg_len = strlen(msg) + 1; WFIFOHEAD(fd,msg_len + 12); WFIFOW(fd,0) = 0x2C1; @@ -8332,8 +8343,8 @@ int clif_colormes(int fd, enum clif_colors color, const char* msg) { /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT). /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B -void clif_messagecolor(struct block_list* bl, unsigned long color, const char* msg) { - unsigned short msg_len = strlen(msg) + 1; +void clif_messagecolor(struct block_list* bl, unsigned int color, const char* msg) { + size_t msg_len = strlen(msg) + 1; uint8 buf[256]; color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR @@ -8657,7 +8668,7 @@ void clif_slide(struct block_list *bl, int x, int y) void clif_disp_overhead(struct block_list *bl, const char* mes) { unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap) - int len_mes = strlen(mes)+1; //Account for \0 + size_t len_mes = strlen(mes)+1; //Account for \0 if (len_mes > sizeof(buf)-8) { ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes); @@ -8946,9 +8957,10 @@ void clif_viewequip_fail(struct map_session_data* sd) /// Returns true if the packet was parsed successfully. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00 /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00 -bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_) { +bool clif_process_message(struct map_session_data *sd, int format, char **name_, size_t *namelen_, char **message_, size_t *messagelen_) { char *text, *name, *message; - unsigned int packetlen, textlen, namelen, messagelen; + unsigned int packetlen, textlen; + size_t namelen, messagelen; int fd = sd->fd; *name_ = NULL; @@ -9604,7 +9616,7 @@ void clif_parse_Hotkey(int fd, struct map_session_data *sd) { /// Displays cast-like progress bar (ZC_PROGRESS). /// 02f0 <color>.L <time>.L -void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second) +void clif_progressbar(struct map_session_data * sd, unsigned int color, unsigned int second) { int fd = sd->fd; @@ -9766,10 +9778,10 @@ int clif_undisguise_timer(int tid, int64 tick, int id, intptr_t data) { void clif_parse_GlobalMessage(int fd, struct map_session_data* sd) { const char* text = (char*)RFIFOP(fd,4); - int textlen = RFIFOW(fd,2) - 4; + size_t textlen = RFIFOW(fd,2) - 4; char *name, *message, *fakename = NULL; - int namelen, messagelen; + size_t namelen, messagelen; bool is_fake; @@ -10274,7 +10286,7 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd) int i; char *target, *message; - int namelen, messagelen; + size_t namelen, messagelen; // validate packet and retrieve name and message if( !clif->process_message(sd, 1, &target, &namelen, &message, &messagelen) ) @@ -10354,7 +10366,7 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd) channel = (struct hChSysCh *)g->channel; } if( channel || (channel = strdb_get(clif->channel_db,chname)) ) { - unsigned char k; + int k; for( k = 0; k < sd->channel_count; k++ ) { if( sd->channels[k] == channel ) break; @@ -10364,7 +10376,6 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd) } else if( channel->pass[0] == '\0' && !(channel->banned && idb_exists(channel->banned, sd->status.account_id)) ) { if( channel->type == hChSys_ALLY ) { struct guild *g = sd->guild, *sg = NULL; - int k; for (k = 0; k < MAX_GUILDALLIANCE; k++) { if( g->alliance[k].opposition == 0 && g->alliance[k].guild_id && (sg = guild->search(g->alliance[k].guild_id) ) ) { if( !(((struct hChSysCh*)sg->channel)->banned && idb_exists(((struct hChSysCh*)sg->channel)->banned, sd->status.account_id))) @@ -12097,7 +12108,7 @@ void clif_parse_PartyMessage(int fd, struct map_session_data* sd) int textlen = RFIFOW(fd,2) - 4; char *name, *message; - int namelen, messagelen; + size_t namelen, messagelen; // validate packet and retrieve name and message if( !clif->process_message(sd, 0, &name, &namelen, &message, &messagelen) ) @@ -12629,7 +12640,7 @@ void clif_PartyBookingFailedRecall(int fd, struct map_session_data *sd) void clif_parse_PartyBookingRefuseVolunteer(int fd, struct map_session_data *sd) { #ifdef PARTY_RECRUIT - unsigned long aid = RFIFOL(fd, 2); + unsigned int aid = RFIFOL(fd, 2); clif->PartyBookingRefuseVolunteer(aid, sd); #else @@ -12638,7 +12649,7 @@ void clif_parse_PartyBookingRefuseVolunteer(int fd, struct map_session_data *sd) } /// 08fa <index>.L -void clif_PartyBookingRefuseVolunteer(unsigned long aid, struct map_session_data *sd) +void clif_PartyBookingRefuseVolunteer(unsigned int aid, struct map_session_data *sd) { #ifdef PARTY_RECRUIT unsigned char buf[2+6]; @@ -13035,7 +13046,7 @@ bool clif_validate_emblem(const uint8 *emblem, unsigned long emblem_len) { /// 0153 <packet len>.W <emblem data>.?B void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd) { - unsigned long emblem_len = RFIFOW(fd,2)-4; + unsigned int emblem_len = RFIFOW(fd,2)-4; const uint8* emblem = RFIFOP(fd,4); if( !emblem_len || !sd->state.gmaster_flag ) @@ -13157,7 +13168,7 @@ void clif_parse_GuildMessage(int fd, struct map_session_data* sd) int textlen = RFIFOW(fd,2) - 4; char *name, *message; - int namelen, messagelen; + size_t namelen, messagelen; // validate packet and retrieve name and message if( !clif->process_message(sd, 0, &name, &namelen, &message, &messagelen) ) @@ -14761,7 +14772,7 @@ void clif_Mail_read(struct map_session_data *sd, int mail_id) struct mail_message *msg = &sd->mail.inbox.msg[i]; struct item *item = &msg->item; struct item_data *data; - int msg_len = strlen(msg->body), len; + size_t msg_len = strlen(msg->body), len; if( msg_len == 0 ) { strcpy(msg->body, "(no message)"); @@ -16087,7 +16098,7 @@ void clif_bg_xy_remove(struct map_session_data *sd) /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT). /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B -void clif_bg_message(struct battleground_data *bgd, int src_id, const char *name, const char *mes, int len) +void clif_bg_message(struct battleground_data *bgd, int src_id, const char *name, const char *mes, size_t len) { struct map_session_data *sd; unsigned char *buf; @@ -16116,7 +16127,7 @@ void clif_parse_BattleChat(int fd, struct map_session_data* sd) int textlen = RFIFOW(fd,2) - 4; char *name, *message; - int namelen, messagelen; + size_t namelen, messagelen; if( !clif->process_message(sd, 0, &name, &namelen, &message, &messagelen) ) return; @@ -16994,7 +17005,7 @@ void clif_parse_debug(int fd,struct map_session_data *sd) { } ShowDebug("Packet debug of 0x%04X (length %d), %s session #%d, %d/%d (AID/CID)\n", cmd, packet_len, sd->state.active ? "authed" : "unauthed", fd, sd->status.account_id, sd->status.char_id); } else { - packet_len = RFIFOREST(fd); + packet_len = (int)RFIFOREST(fd); ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd); } @@ -17602,7 +17613,7 @@ void clif_partytickack(struct map_session_data* sd, bool flag) { void clif_ShowScript(struct block_list* bl, const char* message) { char buf[256]; - int len; + size_t len; nullpo_retv(bl); if(!message) @@ -18297,7 +18308,7 @@ int do_init_clif(bool minimal) { * Setup Color Table (saves unnecessary load of strtoul on every call) **/ for(i = 0; i < COLOR_MAX; i++) { - color_table[i] = strtoul(colors[i],NULL,0); + color_table[i] = (unsigned int)strtoul(colors[i],NULL,0); color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR } |