summaryrefslogtreecommitdiff
path: root/src/map/clif.c
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2016-02-22 04:25:34 +0100
committerHaru <haru@dotalux.com>2016-02-24 21:02:22 +0100
commit027dfa3a608bb2986f4c495f20afdeba4e2ad459 (patch)
tree629046feb2d98a8a8fe0bc9e3674b3952a529ecc /src/map/clif.c
parentc1e21d7f3665b7e79fd0d5777df99fcfb8f93434 (diff)
downloadhercules-027dfa3a608bb2986f4c495f20afdeba4e2ad459.tar.gz
hercules-027dfa3a608bb2986f4c495f20afdeba4e2ad459.tar.bz2
hercules-027dfa3a608bb2986f4c495f20afdeba4e2ad459.tar.xz
hercules-027dfa3a608bb2986f4c495f20afdeba4e2ad459.zip
Edited npc->selllist() 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.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/map/clif.c b/src/map/clif.c
index 80eb7796a..07b0b323b 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -10587,15 +10587,30 @@ void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
{
int fail=0,n;
- n = (RFIFOW(fd,2)-4) /4;
+ n = ((int)RFIFOW(fd,2)-4) /4;
+
+ Assert_retv(n >= 0);
if (sd->state.trading || !sd->npc_shopid) {
fail = 1;
} else {
- unsigned short *item_list = aMalloc(sizeof(*item_list) * 2 * n);
- memcpy(item_list, RFIFOP(fd,4), sizeof(*item_list) * 2 * n);
- fail = npc->selllist(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.id = (int)RFIFOW(fd, 4 + 4 * i) - 2;
+ entry.amount = RFIFOW(fd, 4 + 4 * i + 2);
+
+ VECTOR_PUSH(item_list, entry);
+ }
+ fail = npc->selllist(sd, &item_list);
+
+ VECTOR_CLEAR(item_list);
}
sd->npc_shopid = 0; //Clear shop data.