summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2018-07-11 20:53:42 +0300
committerAndrei Karas <akaras@inbox.ru>2018-07-15 20:36:27 +0300
commitaee584e0444ab514ced7787451f281777437912a (patch)
treec0e820f6a940642be4cf0cd346d8c8480acbb483
parent8d5020c5b9d13718c52a1a1a7c3bbe640c83a5b1 (diff)
downloadhercules-aee584e0444ab514ced7787451f281777437912a.tar.gz
hercules-aee584e0444ab514ced7787451f281777437912a.tar.bz2
hercules-aee584e0444ab514ced7787451f281777437912a.tar.xz
hercules-aee584e0444ab514ced7787451f281777437912a.zip
Update packet CZ_SEARCH_STORE_INFO.
-rw-r--r--src/map/clif.c53
-rw-r--r--src/map/packets_struct.h22
-rw-r--r--src/map/searchstore.c10
-rw-r--r--src/map/searchstore.h6
4 files changed, 65 insertions, 26 deletions
diff --git a/src/map/clif.c b/src/map/clif.c
index 45dafc462..54679f065 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -17945,51 +17945,64 @@ static void clif_parse_SearchStoreInfo(int fd, struct map_session_data *sd) __at
/// cannot be searched.
static void clif_parse_SearchStoreInfo(int fd, struct map_session_data *sd)
{
- const unsigned int blocksize = 2;
- const uint8* itemlist;
- const uint8* cardlist;
+ const unsigned int blocksize = sizeof(struct PACKET_CZ_SEARCH_STORE_INFO_item);
+ const struct PACKET_CZ_SEARCH_STORE_INFO_item* itemlist;
+ const struct PACKET_CZ_SEARCH_STORE_INFO_item* cardlist;
unsigned char type;
unsigned int min_price, max_price;
int packet_len, count, item_count, card_count;
- struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
+ int i;
+ const struct PACKET_CZ_SEARCH_STORE_INFO *p = RFIFOP(fd, 0);
+ uint32 *items_list;
+ uint32 *cards_list;
- packet_len = RFIFOW(fd,info->pos[0]);
+ packet_len = p->packetLength;
- if( packet_len < 15 )
+ if (packet_len < sizeof(struct PACKET_CZ_SEARCH_STORE_INFO))
{// minimum packet length
- ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%d, account_id=%d).\n", 15U, packet_len, sd->bl.id);
+ ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%d, account_id=%d).\n", (uint32)sizeof(struct PACKET_CZ_SEARCH_STORE_INFO), packet_len, sd->bl.id);
return;
}
- type = RFIFOB(fd,info->pos[1]);
- max_price = RFIFOL(fd,info->pos[2]);
- min_price = RFIFOL(fd,info->pos[3]);
- item_count = RFIFOB(fd,info->pos[4]);
- card_count = RFIFOB(fd,info->pos[5]);
- itemlist = RFIFOP(fd,info->pos[6]);
+ type = p->searchType;
+ max_price = p->maxPrice;
+ min_price = p->minPrice;
+ item_count = p->itemsCount;
+ card_count = p->cardsCount;
+ itemlist = &p->items[0];
// check, if there is enough data for the claimed count of items
- packet_len-= info->pos[6];
+ packet_len -= sizeof(struct PACKET_CZ_SEARCH_STORE_INFO);
if (packet_len < 0)
return;
- if( packet_len%blocksize )
+ if (packet_len % blocksize)
{
ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %d (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
return;
}
- count = packet_len/blocksize;
+ count = packet_len / blocksize;
- if( count < item_count+card_count )
+ if (count < item_count + card_count)
{
- ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%d, count=%d, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
+ ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%d, count=%d, account_id=%d).\n", item_count + card_count, count, sd->bl.id);
return;
}
- cardlist = RFIFOP(fd, info->pos[6] + blocksize * item_count);
+ cardlist = RFIFOP(fd, sizeof(struct PACKET_CZ_SEARCH_STORE_INFO) + blocksize * item_count);
- searchstore->query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
+ items_list = aMalloc(sizeof(uint32) * item_count);
+ cards_list = aMalloc(sizeof(uint32) * card_count);
+ for (i = 0; i < item_count; i ++) {
+ items_list[i] = itemlist[i].itemId;
+ }
+ for (i = 0; i < card_count; i ++) {
+ cards_list[i] = cardlist[i].itemId;
+ }
+ searchstore->query(sd, type, min_price, max_price, items_list, item_count, cards_list, card_count);
+ aFree(items_list);
+ aFree(cards_list);
}
/// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
diff --git a/src/map/packets_struct.h b/src/map/packets_struct.h
index ab78ed6b9..210e1f6d9 100644
--- a/src/map/packets_struct.h
+++ b/src/map/packets_struct.h
@@ -2524,6 +2524,28 @@ struct PACKET_CZ_PC_BUY_CASH_POINT_ITEM {
#endif
} __attribute__((packed));
+struct PACKET_CZ_SEARCH_STORE_INFO_item {
+#if PACKETVER_RE_NUM >= 20180704
+ uint32 itemId;
+#else
+ uint16 itemId;
+#endif
+} __attribute__((packed));
+
+struct PACKET_CZ_SEARCH_STORE_INFO {
+ int16 packetType;
+ int16 packetLength;
+ uint8 searchType;
+ uint32 maxPrice;
+ uint32 minPrice;
+ uint8 itemsCount;
+ uint8 cardsCount;
+ struct PACKET_CZ_SEARCH_STORE_INFO_item items[]; // items[itemCount]
+/*
+ struct PACKET_CZ_SEARCH_STORE_INFO_item cards[cardCount];
+*/
+} __attribute__((packed));
+
#if !defined(sun) && (!defined(__NETBSD__) || __NetBSD_Version__ >= 600000000) // NetBSD 5 and Solaris don't like pragma pack but accept the packed attribute
#pragma pack(pop)
#endif // not NetBSD < 6 / Solaris
diff --git a/src/map/searchstore.c b/src/map/searchstore.c
index 2243ffe04..6b847eb92 100644
--- a/src/map/searchstore.c
+++ b/src/map/searchstore.c
@@ -96,7 +96,11 @@ static bool searchstore_open(struct map_session_data *sd, unsigned int uses, uns
return true;
}
-static void searchstore_query(struct map_session_data *sd, unsigned char type, unsigned int min_price, unsigned int max_price, const unsigned short *itemlist, unsigned int item_count, const unsigned short *cardlist, unsigned int card_count)
+static void searchstore_query(struct map_session_data *sd,
+ unsigned char type,
+ unsigned int min_price, unsigned int max_price,
+ const uint32 *itemlist, unsigned int item_count,
+ const uint32 *cardlist, unsigned int card_count)
{
unsigned int i;
struct map_session_data* pl_sd;
@@ -137,14 +141,14 @@ static void searchstore_query(struct map_session_data *sd, unsigned char type, u
// validate lists
for( i = 0; i < item_count; i++ ) {
if( !itemdb->exists(itemlist[i]) ) {
- ShowWarning("searchstore_query: Client resolved item %hu is not known.\n", itemlist[i]);
+ ShowWarning("searchstore_query: Client resolved item %u is not known.\n", itemlist[i]);
clif->search_store_info_failed(sd, SSI_FAILED_NOTHING_SEARCH_ITEM);
return;
}
}
for( i = 0; i < card_count; i++ ) {
if( !itemdb->exists(cardlist[i]) ) {
- ShowWarning("searchstore_query: Client resolved card %hu is not known.\n", cardlist[i]);
+ ShowWarning("searchstore_query: Client resolved card %u is not known.\n", cardlist[i]);
clif->search_store_info_failed(sd, SSI_FAILED_NOTHING_SEARCH_ITEM);
return;
}
diff --git a/src/map/searchstore.h b/src/map/searchstore.h
index 634486258..03924c29a 100644
--- a/src/map/searchstore.h
+++ b/src/map/searchstore.h
@@ -60,8 +60,8 @@ enum e_searchstore_failure {
/// information about the search being performed
struct s_search_store_search {
struct map_session_data* search_sd; // sd of the searching player
- const unsigned short* itemlist;
- const unsigned short* cardlist;
+ const uint32* itemlist;
+ const uint32* cardlist;
unsigned int item_count;
unsigned int card_count;
unsigned int min_price;
@@ -101,7 +101,7 @@ typedef bool (*searchstore_searchall_t)(struct map_session_data* sd, const struc
**/
struct searchstore_interface {
bool (*open) (struct map_session_data* sd, unsigned int uses, unsigned short effect);
- void (*query) (struct map_session_data* sd, unsigned char type, unsigned int min_price, unsigned int max_price, const unsigned short* itemlist, unsigned int item_count, const unsigned short* cardlist, unsigned int card_count);
+ void (*query) (struct map_session_data* sd, unsigned char type, unsigned int min_price, unsigned int max_price, const uint32* itemlist, unsigned int item_count, const uint32* cardlist, unsigned int card_count);
bool (*querynext) (struct map_session_data* sd);
void (*next) (struct map_session_data* sd);
void (*clear) (struct map_session_data* sd);