diff options
author | Haru <haru@dotalux.com> | 2019-05-05 21:07:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-05 21:07:57 +0200 |
commit | 416acb084a7f04a61c410cbc8b31a85ae90c013f (patch) | |
tree | c471492e93d3ec53b21373c51f2e12afe935a22c /src | |
parent | 892ed5f372f995786facfa8ce833711936754795 (diff) | |
parent | 112b19df8acb95e5599927fc4b505d4ca2e610a4 (diff) | |
download | hercules-416acb084a7f04a61c410cbc8b31a85ae90c013f.tar.gz hercules-416acb084a7f04a61c410cbc8b31a85ae90c013f.tar.bz2 hercules-416acb084a7f04a61c410cbc8b31a85ae90c013f.tar.xz hercules-416acb084a7f04a61c410cbc8b31a85ae90c013f.zip |
Merge pull request #2424 from hemagx/hercules_packet_fixes
Storage item list packet size fix and minor clif.c fixes
Diffstat (limited to 'src')
-rw-r--r-- | src/map/clif.c | 58 | ||||
-rw-r--r-- | src/map/clif.h | 5 |
2 files changed, 30 insertions, 33 deletions
diff --git a/src/map/clif.c b/src/map/clif.c index cd3131181..38d0215d3 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -431,8 +431,13 @@ static int clif_send_actual(int fd, void *buf, int len) *------------------------------------------*/ static bool clif_send(const void *buf, int len, struct block_list *bl, enum send_target type) { + if (type != ALL_CLIENT) + nullpo_retr(false, bl); + nullpo_retr(false, buf); + Assert_retr(false, len > 0); + int i; - struct map_session_data *sd, *tsd; + struct map_session_data *sd = BL_CAST(BL_PC, bl), *tsd; struct party_data *p = NULL; struct guild *g = NULL; struct battleground_data *bgd = NULL; @@ -440,11 +445,6 @@ static bool clif_send(const void *buf, int len, struct block_list *bl, enum send struct s_mapiterator* iter; int area_size; - if( type != ALL_CLIENT ) - nullpo_ret(bl); - - sd = BL_CAST(BL_PC, bl); - if (sd != NULL && pc_isinvisible(sd)) { if (type == AREA || type == BG || type == BG_AREA) type = SELF; @@ -2977,28 +2977,20 @@ static void clif_storageItems(struct map_session_data *sd, enum inventory_type t nullpo_retv(sd); nullpo_retv(items); - int i = 0; - struct item_data *id; - - do { - int normal = 0, equip = 0, k = 0; - - for( ; i < items_length && k < 500; i++, k++ ) { - - if( items[i].nameid <= 0 ) - continue; + for (int i = 0, normal_count = 0, equip_count = 0; i < items_length; ++i) { + if (items[i].nameid == 0) + continue; - id = itemdb->search(items[i].nameid); + struct item_data *itd = itemdb->search(items[i].nameid); - if( !itemdb->isstackable2(id) ) //Non-stackable (Equippable) - clif->item_equip(i+1,&storelist_equip.list[equip++],&items[i],id,id->equip); - else //Stackable (Normal) - clif->item_normal(i+1,&storelist_normal.list[normal++],&items[i],id); - } + if (!itemdb->isstackable2(itd)) + clif->item_equip(i + 1, &storelist_equip.list[equip_count++], &items[i], itd, itd->equip); + else + clif->item_normal(i + 1, &storelist_normal.list[normal_count++], &items[i], itd); - if( normal ) { - storelist_normal.PacketType = storageListNormalType; - storelist_normal.PacketLength = ( sizeof( storelist_normal ) - sizeof( storelist_normal.list ) ) + (sizeof(struct NORMALITEM_INFO) * normal); + if (normal_count > 0 && (normal_count == MAX_STORAGE_ITEM_PACKET_NORMAL || i + 1 == items_length)) { + storelist_normal.PacketType = storageListNormalType; + storelist_normal.PacketLength = (sizeof(storelist_normal) - sizeof(storelist_normal.list)) + (sizeof(struct NORMALITEM_INFO) * normal_count); #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002 storelist_normal.invType = type; @@ -3008,11 +3000,12 @@ static void clif_storageItems(struct map_session_data *sd, enum inventory_type t #endif clif->send(&storelist_normal, storelist_normal.PacketLength, &sd->bl, SELF); + normal_count = 0; } - if( equip ) { - storelist_equip.PacketType = storageListEquipType; - storelist_equip.PacketLength = ( sizeof( storelist_equip ) - sizeof( storelist_equip.list ) ) + (sizeof(struct EQUIPITEM_INFO) * equip); + if (equip_count > 0 && (equip_count == MAX_STORAGE_ITEM_PACKET_EQUIP || i + 1 == items_length)) { + storelist_equip.PacketType = storageListEquipType; + storelist_equip.PacketLength = (sizeof(storelist_equip) - sizeof(storelist_equip.list)) + (sizeof(struct EQUIPITEM_INFO) * equip_count); #if PACKETVER_RE_NUM >= 20180912 || PACKETVER_ZERO_NUM >= 20180919 || PACKETVER_MAIN_NUM >= 20181002 storelist_equip.invType = type; @@ -3022,10 +3015,9 @@ static void clif_storageItems(struct map_session_data *sd, enum inventory_type t #endif clif->send(&storelist_equip, storelist_equip.PacketLength, &sd->bl, SELF); + equip_count = 0; } - - } while ( i < items_length ); - + } } static void clif_cartList(struct map_session_data *sd) @@ -7131,7 +7123,7 @@ static void clif_party_job_and_level(struct map_session_data *sd) WBUFW(buf, 6) = sd->status.class; WBUFW(buf, 8) = sd->status.base_level; - clif_send(buf, packet_len(0xabd), &sd->bl, PARTY); + clif->send(buf, packet_len(0xabd), &sd->bl, PARTY); #endif } @@ -21636,7 +21628,7 @@ static void clif_hat_effect_single(struct block_list *bl, uint16 effectId, bool WBUFB(buf,8) = enable; WBUFL(buf,9) = effectId; - clif_send(buf, 13, bl, AREA); + clif->send(buf, 13, bl, AREA); #endif } diff --git a/src/map/clif.h b/src/map/clif.h index 6c9058cba..b3441f908 100644 --- a/src/map/clif.h +++ b/src/map/clif.h @@ -78,6 +78,11 @@ enum rodex_get_items; #define COLOR_YELLOW 0xffff00U #define COLOR_DEFAULT COLOR_GREEN +#define MAX_STORAGE_ITEM_PACKET_NORMAL ((INT16_MAX - (sizeof(struct ZC_STORE_ITEMLIST_NORMAL) - (sizeof(struct NORMALITEM_INFO) * MAX_ITEMLIST))) / sizeof(struct NORMALITEM_INFO)) +#define MAX_STORAGE_ITEM_PACKET_EQUIP ((INT16_MAX - (sizeof(struct ZC_STORE_ITEMLIST_EQUIP) - (sizeof(struct EQUIPITEM_INFO) * MAX_ITEMLIST))) / sizeof(struct EQUIPITEM_INFO)) +STATIC_ASSERT(MAX_STORAGE_ITEM_PACKET_NORMAL > 0, "Max items per storage item packet for normal items is less than 1, it's most likely to be a bug and shall not be ignored."); +STATIC_ASSERT(MAX_STORAGE_ITEM_PACKET_EQUIP > 0, "Max items per storage item packet for equip items is less than 1, it's most likely to be a bug and shall not be ignored."); + /** * Enumerations **/ |