summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/map/clif.c42
-rw-r--r--src/map/clif.h5
2 files changed, 23 insertions, 24 deletions
diff --git a/src/map/clif.c b/src/map/clif.c
index cd3131181..0f8469e64 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -2977,28 +2977,22 @@ 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++ ) {
+ for (int i = 0, normal_count = 0, equip_count = 0; i < items_length; ++i) {
+ struct item_data *itd;
- if( items[i].nameid <= 0 )
- continue;
+ if (items[i].nameid == 0)
+ continue;
- id = itemdb->search(items[i].nameid);
+ 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 +3002,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 +3017,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)
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
**/