diff options
author | Haru <haru@dotalux.com> | 2016-02-22 04:09:03 +0100 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2016-02-24 21:02:22 +0100 |
commit | c1e21d7f3665b7e79fd0d5777df99fcfb8f93434 (patch) | |
tree | 7a6f22607ac4e18214cffa1a8582098a686e6af5 /src/map/clif.c | |
parent | 3b9c0daf1bc4d4c8d4c39f3e5e4e25d103ed9b3a (diff) | |
download | hercules-c1e21d7f3665b7e79fd0d5777df99fcfb8f93434.tar.gz hercules-c1e21d7f3665b7e79fd0d5777df99fcfb8f93434.tar.bz2 hercules-c1e21d7f3665b7e79fd0d5777df99fcfb8f93434.tar.xz hercules-c1e21d7f3665b7e79fd0d5777df99fcfb8f93434.zip |
Edited npc->buylist() to use the new struct itemlist
- The npc-side code no longer depends on the client data layout.
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map/clif.c')
-rw-r--r-- | src/map/clif.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/map/clif.c b/src/map/clif.c index eb67723e2..80eb7796a 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -10534,16 +10534,29 @@ void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd) __attribute_ /// 00c8 <packet len>.W { <amount>.W <name id>.W }* void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd) { - int n = (RFIFOW(fd,2)-4) /4; + int n = ((int)RFIFOW(fd,2)-4) / 4; int result; + Assert_retv(n >= 0); + if( sd->state.trading || !sd->npc_shopid || pc_has_permission(sd,PC_PERM_DISABLE_STORE) ) { result = 1; } else { - unsigned short *item_list = aMalloc(sizeof(*item_list) * 2 * n); - memcpy(item_list, RFIFOP(fd,4), sizeof(*item_list) * 2 * n); - result = npc->buylist(sd,n,item_list); - aFree(item_list); + struct itemlist item_list = { 0 }; + int i; + + VECTOR_INIT(item_list); + VECTOR_ENSURE(item_list, n, 1); + for (i = 0; i < n; i++) { + struct itemlist_entry entry = { 0 }; + + entry.amount = RFIFOW(fd, 4 + 4 * i); + entry.id = RFIFOW(fd, 4 + 4 * i + 2); + + VECTOR_PUSH(item_list, entry); + } + result = npc->buylist(sd, &item_list); + VECTOR_CLEAR(item_list); } sd->npc_shopid = 0; //Clear shop data. |