summaryrefslogtreecommitdiff
path: root/src/map/clif.c
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2016-02-22 03:10:04 +0100
committerHaru <haru@dotalux.com>2016-02-24 21:02:17 +0100
commit23f1ef310719081c79aebf3f8921240773f5a507 (patch)
tree1b873269dba4d5b9f88b6db3f215c2d245a6b90b /src/map/clif.c
parentc1ab5a9db773d399c86eb59a3dded649387480c0 (diff)
downloadhercules-23f1ef310719081c79aebf3f8921240773f5a507.tar.gz
hercules-23f1ef310719081c79aebf3f8921240773f5a507.tar.bz2
hercules-23f1ef310719081c79aebf3f8921240773f5a507.tar.xz
hercules-23f1ef310719081c79aebf3f8921240773f5a507.zip
Edited skill->changematerial() and skill->elementalanalysis() to use the new struct itemlist
- The skill-side code no longer depends on the client packet data layout. - Some data validation has been added. Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map/clif.c')
-rw-r--r--src/map/clif.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/map/clif.c b/src/map/clif.c
index 9e0977cc4..9dc42bb07 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -16441,7 +16441,8 @@ void clif_parse_ItemListWindowSelected(int fd, struct map_session_data *sd)
int n = ((int)RFIFOW(fd,2) - 12) / 4;
int type = RFIFOL(fd,4);
int flag = RFIFOL(fd,8); // Button clicked: 0 = Cancel, 1 = OK
- unsigned short *item_list = NULL;
+ struct itemlist item_list = { 0 };
+ int i;
if( sd->state.trading || sd->npc_shopid )
return;
@@ -16459,18 +16460,25 @@ void clif_parse_ItemListWindowSelected(int fd, struct map_session_data *sd)
return; // Prevent hacking.
}
- item_list = aMalloc(sizeof *item_list * 2 * n);
- memcpy(item_list, RFIFOP(fd,12), sizeof *item_list * 2 * n);
+ 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, 12 + 4 * i) - 2; // Inventory index
+ entry.amount = RFIFOW(fd, 12 + 4 * i + 2);
+ VECTOR_PUSH(item_list, entry);
+ }
+
switch( type ) {
case 0: // Change Material
- skill->changematerial(sd,n,item_list);
+ skill->changematerial(sd, &item_list);
break;
case 1: // Level 1: Pure to Rough
case 2: // Level 2: Rough to Pure
- skill->elementalanalysis(sd,n,type,item_list);
+ skill->elementalanalysis(sd, type, &item_list);
break;
}
- aFree(item_list);
+ VECTOR_CLEAR(item_list);
clif_menuskill_clear(sd);
return;