summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2018-12-15 21:05:52 +0300
committerAndrei Karas <akaras@inbox.ru>2018-12-15 21:05:52 +0300
commit95c8d0751bcf73998c43550ee951014930f334e0 (patch)
tree12ab4204dd047c970f8fb04db4a611955cda583d /src
parent6f3eb860d7b82634736c3b35d827c4abb70e5ecb (diff)
downloadhercules-95c8d0751bcf73998c43550ee951014930f334e0.tar.gz
hercules-95c8d0751bcf73998c43550ee951014930f334e0.tar.bz2
hercules-95c8d0751bcf73998c43550ee951014930f334e0.tar.xz
hercules-95c8d0751bcf73998c43550ee951014930f334e0.zip
Improve packet ZC_NPC_MARKET_OPEN
Diffstat (limited to 'src')
-rw-r--r--src/map/clif.c35
-rw-r--r--src/map/packets_struct.h33
2 files changed, 36 insertions, 32 deletions
diff --git a/src/map/clif.c b/src/map/clif.c
index b0698fefd..4e4e5ab8c 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -92,8 +92,9 @@ static struct ZC_STORE_ITEMLIST_EQUIP storelist_equip;
static struct packet_viewequip_ack viewequip_list;
#if PACKETVER >= 20131223
static struct packet_npc_market_result_ack npcmarket_result;
-static struct packet_npc_market_open npcmarket_open;
#endif
+// temporart buffer for send big packets
+char packet_buf[0xffff];
//#define DUMP_UNKNOWN_PACKET
//#define DUMP_INVALID_PACKET
@@ -19871,31 +19872,31 @@ static void clif_parse_NPCShopClosed(int fd, struct map_session_data *sd)
/* NPC Market (by Ind after an extensive debugging of the packet, only possible thanks to Yommy <3) */
static void clif_npc_market_open(struct map_session_data *sd, struct npc_data *nd)
{
-#if PACKETVER >= 20131223
- struct npc_item_list *shop;
- unsigned short shop_size, i, c;
-
+#if PACKETVER_MAIN_NUM >= 20131120 || PACKETVER_RE_NUM >= 20131106 || defined(PACKETVER_ZERO)
nullpo_retv(sd);
nullpo_retv(nd);
- shop = nd->u.scr.shop->item;
- shop_size = nd->u.scr.shop->items;
- npcmarket_open.PacketType = npcmarketopenType;
+ struct npc_item_list *shop = nd->u.scr.shop->item;
+ const int shop_size = nd->u.scr.shop->items;
- for(i = 0, c = 0; i < shop_size; i++) {
+ int c = 0;
+ int maxCount = (sizeof(packet_buf) - sizeof(struct PACKET_ZC_NPC_MARKET_OPEN)) / sizeof(struct PACKET_ZC_NPC_MARKET_OPEN_sub);
+ struct PACKET_ZC_NPC_MARKET_OPEN *packet = (struct PACKET_ZC_NPC_MARKET_OPEN*)&packet_buf[0];
+ packet->packetType = HEADER_ZC_NPC_MARKET_OPEN;
+
+ for (int i = 0; i < shop_size && c < maxCount; i++) {
struct item_data *id = NULL;
if (shop[i].nameid && (id = itemdb->exists(shop[i].nameid)) != NULL) {
- npcmarket_open.list[c].nameid = shop[i].nameid;
- npcmarket_open.list[c].price = shop[i].value;
- npcmarket_open.list[c].qty = shop[i].qty;
- npcmarket_open.list[c].type = itemtype(id->type);
- npcmarket_open.list[c].view = ( id->view_id > 0 ) ? id->view_id : id->nameid;
+ packet->list[c].nameid = shop[i].nameid;
+ packet->list[c].price = shop[i].value;
+ packet->list[c].qty = shop[i].qty;
+ packet->list[c].type = itemtype(id->type);
+ packet->list[c].weight = id->weight;
c++;
}
}
- npcmarket_open.PacketLength = 4 + ( sizeof(npcmarket_open.list[0]) * c );
-
- clif->send(&npcmarket_open,npcmarket_open.PacketLength,&sd->bl,SELF);
+ packet->packetLength = sizeof(struct PACKET_ZC_NPC_MARKET_OPEN) + sizeof(struct PACKET_ZC_NPC_MARKET_OPEN_sub) * c;
+ clif->send(packet, packet->packetLength, &sd->bl, SELF);
#endif
}
diff --git a/src/map/packets_struct.h b/src/map/packets_struct.h
index 26e6343d7..9b82d82b9 100644
--- a/src/map/packets_struct.h
+++ b/src/map/packets_struct.h
@@ -1391,26 +1391,29 @@ struct packet_npc_market_result_ack {
} list[MAX_INVENTORY];/* assuming MAX_INVENTORY is max since you can't hold more than MAX_INVENTORY items thus cant buy that many at once. */
} __attribute__((packed));
-struct packet_npc_market_open {
- int16 PacketType;
- int16 PacketLength;
- /* inner struct figured by Ind after some annoying hour of debugging (data Thanks to Yommy) */
- struct {
+#if PACKETVER_MAIN_NUM >= 20131120 || PACKETVER_RE_NUM >= 20131106 || defined(PACKETVER_ZERO)
+/* inner struct figured by Ind after some annoying hour of debugging (data Thanks to Yommy) */
+struct PACKET_ZC_NPC_MARKET_OPEN_sub {
#if PACKETVER_MAIN_NUM >= 20181121 || PACKETVER_RE_NUM >= 20180704 || PACKETVER_ZERO_NUM >= 20181114
- uint32 nameid;
+ uint32 nameid;
#else
- uint16 nameid;
+ uint16 nameid;
#endif
- uint8 type;
- uint32 price;
- uint32 qty;
- uint16 view;
- // It seems that the client doesn't have any hard-coded limit for this list
- // it's possible to send up to 1890 items without dropping a packet that's
- // too large [Panikon]
- } list[1000];/* TODO: whats the actual max of this? */
+ uint8 type;
+ uint32 price;
+ uint32 qty;
+ uint16 weight;
} __attribute__((packed));
+struct PACKET_ZC_NPC_MARKET_OPEN {
+ int16 packetType;
+ int16 packetLength;
+ struct PACKET_ZC_NPC_MARKET_OPEN_sub list[];
+} __attribute__((packed));
+
+DEFINE_PACKET_HEADER(ZC_NPC_MARKET_OPEN, 0x09d5);
+#endif
+
struct packet_wis_end {
int16 PacketType;
int8 result;