From e8affc41f106503b530abaa7faa20d6e63b727b8 Mon Sep 17 00:00:00 2001 From: Smokexyz Date: Fri, 28 Apr 2017 05:57:39 +0800 Subject: Add storage_data reception, parsing and sending to/from the map-server. Remove loading and saving of storage_data through char.c Re-declaration of structure storage_data as a vector. Re-code of portions in the map-server using storage_data. A new approach is taken by saving the loaded storage data from sql into memory for the duration of the session, thereby removing the need of querying the database to re-load all items everytime a storage save routine is issued from the map-server. Saving of storage items is done through a new function that significantly reduces the number of queries compared to char_memitemdata_tosql(), and therefore run-time speed. This method potentially reduces the number of update and delete queries from MAX_STORAGE (which could be >= 600) times to literally 1. Storage items are stored in a dynamically allocated array and handled accordingly. struct mmo_charstatus size reduces by 34,800 bytes. Update pc_checkitem() with masks for item checks. `sd->state.itemcheck` has been changed to `sd->itemcheck` of type `enum pc_checkitem_types` `battle/items.conf` has been updated to reflect configuration changes. Further updates to assert a successful reception of storage data in related functions. --- src/map/clif.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) (limited to 'src/map/clif.c') diff --git a/src/map/clif.c b/src/map/clif.c index f1400a5d4..d31cc70e9 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -4187,12 +4187,13 @@ void clif_storageitemremoved(struct map_session_data* sd, int index, int amount) nullpo_retv(sd); - fd=sd->fd; - WFIFOHEAD(fd,packet_len(0xf6)); - WFIFOW(fd,0)=0xf6; // Storage item removed - WFIFOW(fd,2)=index+1; - WFIFOL(fd,4)=amount; - WFIFOSET(fd,packet_len(0xf6)); + fd = sd->fd; + + WFIFOHEAD(fd, packet_len(0xf6)); + WFIFOW(fd, 0) = 0xf6; // Storage item removed + WFIFOW(fd, 2) = index + 1; + WFIFOL(fd, 4) = amount; + WFIFOSET(fd, packet_len(0xf6)); } /// Closes storage (ZC_CLOSE_STORE). @@ -8429,9 +8430,11 @@ void clif_refresh_storagewindow(struct map_session_data *sd) nullpo_retv(sd); // Notify the client that the storage is open if (sd->state.storage_flag == STORAGE_FLAG_NORMAL) { - storage->sortitem(sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items)); - clif->storagelist(sd, sd->status.storage.items, ARRAYLENGTH(sd->status.storage.items)); - clif->updatestorageamount(sd, sd->status.storage.storage_amount, MAX_STORAGE); + if (sd->storage.aggregate > 0) { + storage->sortitem(VECTOR_DATA(sd->storage.item), VECTOR_LENGTH(sd->storage.item)); + clif->storagelist(sd, VECTOR_DATA(sd->storage.item), VECTOR_LENGTH(sd->storage.item)); + } + clif->updatestorageamount(sd, sd->storage.aggregate, MAX_STORAGE); } // Notify the client that the gstorage is open otherwise it will // remain locked forever and nobody will be able to access it @@ -9338,7 +9341,7 @@ void clif_parse_LoadEndAck(int fd, struct map_session_data *sd) { sd->state.warping = 0; sd->state.dialog = 0;/* reset when warping, client dialog will go missing */ - // look + // Character Looks #if PACKETVER < 4 clif->changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon); clif->changelook(&sd->bl,LOOK_SHIELD,sd->status.shield); @@ -9348,21 +9351,26 @@ void clif_parse_LoadEndAck(int fd, struct map_session_data *sd) { if(sd->vd.cloth_color) clif->refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF); + if (sd->vd.body_style) clif->refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF); - // item - clif->inventorylist(sd); // inventory list first, otherwise deleted items in pc->checkitem show up as 'unknown item' - pc->checkitem(sd); - // cart + // Send character inventory to the client. + // call this before pc->checkitem() so that the client isn't called to delete a non-existent item. + clif->inventorylist(sd); + + // Send the cart inventory, counts & weight to the client. if(pc_iscarton(sd)) { clif->cartlist(sd); - clif->updatestatus(sd,SP_CARTINFO); + clif->updatestatus(sd, SP_CARTINFO); } - // weight - clif->updatestatus(sd,SP_WEIGHT); - clif->updatestatus(sd,SP_MAXWEIGHT); + // Check for and delete unavailable/disabled items. + pc->checkitem(sd); + + // Send the character's weight to the client. + clif->updatestatus(sd, SP_WEIGHT); + clif->updatestatus(sd, SP_MAXWEIGHT); // guild // (needs to go before clif_spawn() to show guild emblems correctly) -- cgit v1.2.3-70-g09d2