فهرست منبع

Corrected Storage dirty flag check
* Follow up to ade1b17.

aleos89 8 سال پیش
والد
کامیت
d1cc320769
3فایلهای تغییر یافته به همراه52 افزوده شده و 14 حذف شده
  1. 1 1
      src/map/chrif.c
  2. 5 2
      src/map/intif.c
  3. 46 11
      src/map/storage.c

+ 1 - 1
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);

+ 5 - 2
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) {

+ 46 - 11
src/map/storage.c

@@ -441,22 +441,57 @@ void storage_storagegettocart(struct map_session_data* sd, struct s_storage *sto
 	}
 }
 
+/**
+ * Request to save storage
+ * @param sd: Player who has the storage
+ */
+void storage_storagesave(struct map_session_data *sd)
+{
+	nullpo_retv(sd);
+
+	if (!&sd->storage)
+		return;
+
+	intif_storage_save(sd, &sd->storage);
+}
+
+/**
+ * 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
- * @author : [massdriller] / modified by [Valaris]
- * @param sd : player
+ * @param sd: Player who has the storage
+ * @author [massdriller] / modified by [Valaris]
  */
-void storage_storageclose(struct map_session_data* sd)
+void storage_storageclose(struct map_session_data *sd)
 {
 	nullpo_retv(sd);
 
-	clif_storageclose(sd);
-
-	if (save_settings&CHARSAVE_STORAGE)
-		chrif_save(sd,0);
+	if (!&sd->storage)
+		return;
 
-	sd->state.storage_flag = 0;
+	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);
 }
 
 /**