From d1cc32076998eb147b327a5d4f6cc953d30d8536 Mon Sep 17 00:00:00 2001 From: aleos89 Date: Tue, 15 Nov 2016 16:17:11 -0500 Subject: [PATCH] Corrected Storage dirty flag check * Follow up to ade1b17. --- src/map/chrif.c | 2 +- src/map/intif.c | 7 ++++-- src/map/storage.c | 59 +++++++++++++++++++++++++++++++++++++---------- 3 files changed, 53 insertions(+), 15 deletions(-) diff --git a/src/map/chrif.c b/src/map/chrif.c index 0b106233b4..6d89c3a270 100644 --- a/src/map/chrif.c +++ b/src/map/chrif.c @@ -299,7 +299,7 @@ int chrif_save(struct map_session_data *sd, int flag) { chrif_bsdata_save(sd, (flag && (flag != 3))); - if (sd->state.storage_flag == 1) + if (&sd->storage && sd->storage.dirty) intif_storage_save(sd,&sd->storage); intif_storage_save(sd,&sd->inventory); intif_storage_save(sd,&sd->cart); diff --git a/src/map/intif.c b/src/map/intif.c index 48ad3b0e94..e9a04eac80 100644 --- a/src/map/intif.c +++ b/src/map/intif.c @@ -3162,7 +3162,9 @@ static bool intif_parse_StorageReceived(int fd) p = (struct s_storage *)RFIFOP(fd,10); switch (type) { - case TABLE_INVENTORY: stor = &sd->inventory; break; + case TABLE_INVENTORY: + stor = &sd->inventory; + break; case TABLE_STORAGE: if (p->stor_id == 0) stor = &sd->storage; @@ -3172,7 +3174,8 @@ static bool intif_parse_StorageReceived(int fd) case TABLE_CART: stor = &sd->cart; break; - default: return false; + default: + return false; } if (stor->stor_id == p->stor_id) { diff --git a/src/map/storage.c b/src/map/storage.c index 5f5bc4f1eb..c031e86c8f 100644 --- a/src/map/storage.c +++ b/src/map/storage.c @@ -441,22 +441,57 @@ void storage_storagegettocart(struct map_session_data* sd, struct s_storage *sto } } - /** - * Make player close his storage - * @author : [massdriller] / modified by [Valaris] - * @param sd : player + * Request to save storage + * @param sd: Player who has the storage */ -void storage_storageclose(struct map_session_data* sd) +void storage_storagesave(struct map_session_data *sd) { nullpo_retv(sd); - clif_storageclose(sd); + if (!&sd->storage) + return; - if (save_settings&CHARSAVE_STORAGE) - chrif_save(sd,0); + intif_storage_save(sd, &sd->storage); +} - sd->state.storage_flag = 0; +/** + * Ack of storage has been saved + * @param sd: Player who has the storage + */ +void storage_storagesaved(struct map_session_data *sd) +{ + if (!sd) + return; + + if (&sd->storage) + sd->storage.dirty = false; + if (sd->state.storage_flag == 1) { + sd->state.storage_flag = 0; + clif_storageclose(sd); + } +} + +/** + * Make player close his storage + * @param sd: Player who has the storage + * @author [massdriller] / modified by [Valaris] + */ +void storage_storageclose(struct map_session_data *sd) +{ + nullpo_retv(sd); + + if (!&sd->storage) + return; + + if (sd->storage.dirty) { + intif_storage_save(sd, &sd->storage); + if (sd->state.storage_flag == 1) { + sd->state.storage_flag = 0; + clif_storageclose(sd); + } + } else + storage_storagesaved(sd); } /** @@ -471,10 +506,10 @@ void storage_storage_quit(struct map_session_data* sd, int flag) { nullpo_retv(sd); - if (save_settings&CHARSAVE_STORAGE) - chrif_save(sd,0); + if (!&sd->storage) + return; - sd->state.storage_flag = 0; + intif_storage_save(sd, &sd->storage); } /**