Skip to content

Commit

Permalink
Fix a race condition in the storage saving code
Browse files Browse the repository at this point in the history
Signed-off-by: Haru <haru@dotalux.com>
  • Loading branch information
MishimaHaruna committed Aug 26, 2018
1 parent 4833417 commit 5bb4170
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/map/intif.c
Expand Up @@ -513,7 +513,7 @@ static void intif_parse_account_storage(int fd)
* @packet 0x3011 [out] <packet_len>.W <account_id>.L <struct item[]>.P * @packet 0x3011 [out] <packet_len>.W <account_id>.L <struct item[]>.P
* @param sd [in] pointer to session data. * @param sd [in] pointer to session data.
*/ */
static void intif_send_account_storage(const struct map_session_data *sd) static void intif_send_account_storage(struct map_session_data *sd)
{ {
int len = 0, i = 0, c = 0; int len = 0, i = 0, c = 0;


Expand Down Expand Up @@ -541,6 +541,8 @@ static void intif_send_account_storage(const struct map_session_data *sd)
} }


WFIFOSET(inter_fd, len); WFIFOSET(inter_fd, len);

sd->storage.save = false; // Save request has been sent
} }


/** /**
Expand All @@ -562,10 +564,9 @@ static void intif_parse_account_storage_save_ack(int fd)


if (saved == 0) { if (saved == 0) {
ShowError("intif_parse_account_storage_save_ack: Storage has not been saved! (AID: %d)\n", account_id); ShowError("intif_parse_account_storage_save_ack: Storage has not been saved! (AID: %d)\n", account_id);
sd->storage.save = true; // Flag it as unsaved, to re-attempt later
return; return;
} }

sd->storage.save = false; // Storage has been saved.
} }


//================================================================= //=================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/map/intif.h
Expand Up @@ -68,7 +68,7 @@ struct intif_interface {
int (*saveregistry) (struct map_session_data *sd); int (*saveregistry) (struct map_session_data *sd);
int (*request_registry) (struct map_session_data *sd, int flag); int (*request_registry) (struct map_session_data *sd, int flag);
void (*request_account_storage) (const struct map_session_data *sd); void (*request_account_storage) (const struct map_session_data *sd);
void (*send_account_storage) (const struct map_session_data *sd); void (*send_account_storage) (struct map_session_data *sd);
int (*request_guild_storage) (int account_id, int guild_id); int (*request_guild_storage) (int account_id, int guild_id);
int (*send_guild_storage) (int account_id, struct guild_storage *gstor); int (*send_guild_storage) (int account_id, struct guild_storage *gstor);
int (*create_party) (struct party_member *member, const char *name, int item, int item2); int (*create_party) (struct party_member *member, const char *name, int item, int item2);
Expand Down

0 comments on commit 5bb4170

Please sign in to comment.