Skip to content

Commit

Permalink
Changes to mapif and merge fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dastgirp committed May 16, 2020
1 parent abb993d commit c2fea08
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
43 changes: 25 additions & 18 deletions src/char/mapif.c
Original file line number Diff line number Diff line change
Expand Up @@ -1816,29 +1816,30 @@ static int mapif_save_guild_storage_ack(int fd, int account_id, int guild_id, in

/**
* Loads the account storage and send to the map server.
* @packet 0x3805 [out] <account_id>.L <struct item[]>.P
* @packet 0x3805 [out] <packet_len>.W <account_id>.L <storage_id>.W <struct item[]>.P
* @param fd [in] file/socket descriptor.
* @param account_id [in] account id of the session.
* @return 1 on success, 0 on failure.
*/
static int mapif_account_storage_load(int fd, int account_id)
static int mapif_account_storage_load(int fd, int account_id, int storage_id, int storage_size)
{
struct storage_data stor = { 0 };
int count = 0, i = 0, len = 0;

Assert_ret(account_id > 0);

VECTOR_INIT(stor.item);
count = inter_storage->fromsql(account_id, &stor);
count = inter_storage->fromsql(account_id, storage_id, &stor, storage_size);

len = 8 + count * sizeof(struct item);
len = 10 + count * sizeof(struct item);

WFIFOHEAD(fd, len);
WFIFOW(fd, 0) = 0x3805;
WFIFOW(fd, 2) = (uint16) len;
WFIFOL(fd, 4) = account_id;
WFIFOW(fd, 8) = storage_id;
for (i = 0; i < count; i++)
memcpy(WFIFOP(fd, 8 + i * sizeof(struct item)), &VECTOR_INDEX(stor.item, i), sizeof(struct item));
memcpy(WFIFOP(fd, 10 + i * sizeof(struct item)), &VECTOR_INDEX(stor.item, i), sizeof(struct item));
WFIFOSET(fd, len);

VECTOR_CLEAR(stor.item);
Expand All @@ -1848,31 +1849,36 @@ static int mapif_account_storage_load(int fd, int account_id)

/**
* Parses account storage load request from map server.
* @packet 0x3010 [in] <account_id>.L
* @packet 0x3010 [in] <account_id>.L <storage_id>.W <storage_size>.W
* @param fd [in] file/socket descriptor
* @return 1 on success, 0 on failure.
*/
static int mapif_parse_AccountStorageLoad(int fd)
{
int account_id = RFIFOL(fd, 2);
int account_id = RFIFOL(fd, 2), storage_id = RFIFOW(fd, 6);
int storage_size = RFIFOW(fd, 8);

Assert_ret(fd > 0);
Assert_ret(account_id > 0);
Assert_ret(storage_id >= 0);
Assert_ret(storage_size > 0);

mapif->account_storage_load(fd, account_id);
mapif->account_storage_load(fd, account_id, storage_id, storage_size);

return 1;
}

/**
* Parses an account storage save request from the map server.
* @packet 0x3011 [in] <packet_len>.W <account_id>.L <struct item[]>.P
* @packet 0x3011 [in] <packet_len>.W <account_id>.L <storage_id>.L <struct item[]>.P
* @param fd [in] file/socket descriptor.
* @return 1 on success, 0 on failure.
*/
static int mapif_parse_AccountStorageSave(int fd)
{
int payload_size = RFIFOW(fd, 2) - 8, account_id = RFIFOL(fd, 4);
int payload_size = RFIFOW(fd, 2) - 10, account_id = RFIFOL(fd, 4);
short storage_id = RFIFOW(fd, 8);

int i = 0, count = 0;
struct storage_data p_stor = { 0 };

Expand All @@ -1887,38 +1893,39 @@ static int mapif_parse_AccountStorageSave(int fd)
VECTOR_ENSURE(p_stor.item, count, 1);

for (i = 0; i < count; i++) {
const struct item *it = RFIFOP(fd, 8 + i * sizeof(struct item));
const struct item *it = RFIFOP(fd, 10 + i * sizeof(struct item));

VECTOR_PUSH(p_stor.item, *it);
}

p_stor.aggregate = count;
}

inter_storage->tosql(account_id, &p_stor);
inter_storage->tosql(account_id, storage_id, &p_stor);

VECTOR_CLEAR(p_stor.item);

mapif->sAccountStorageSaveAck(fd, account_id, true);
mapif->sAccountStorageSaveAck(fd, account_id, storage_id, true);

return 1;
}

/**
* Sends an acknowledgement for the save
* status of the account storage.
* @packet 0x3808 [out] <account_id>.L <save_flag>.B
* @packet 0x3808 [out] <account_id>.L <storage_id>.W <save_flag>.B
* @param fd [in] File/Socket Descriptor.
* @param account_id [in] Account ID of the storage in question.
* @param flag [in] Save flag, true for success and false for failure.
*/
static void mapif_send_AccountStorageSaveAck(int fd, int account_id, bool flag)
static void mapif_send_AccountStorageSaveAck(int fd, int account_id, int storage_id, bool flag)
{
WFIFOHEAD(fd, 7);
WFIFOHEAD(fd, 9);
WFIFOW(fd, 0) = 0x3808;
WFIFOL(fd, 2) = account_id;
WFIFOB(fd, 6) = flag ? 1 : 0;
WFIFOSET(fd, 7);
WFIFOW(fd, 6) = storage_id;
WFIFOB(fd, 8) = flag ? 1 : 0;
WFIFOSET(fd, 9);
}

static int mapif_parse_LoadGuildStorage(int fd)
Expand Down
2 changes: 1 addition & 1 deletion src/map/intif.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ static void intif_send_account_storage(struct map_session_data *sd, int storage_

WFIFOSET(inter_fd, len);

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

/**
Expand Down
1 change: 0 additions & 1 deletion src/map/pc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,6 @@ static bool pc_authok(struct map_session_data *sd, int login_id2, time_t expirat
VECTOR_INIT(sd->channels);
VECTOR_INIT(sd->script_queues);
VECTOR_INIT(sd->achievement); // Achievements [Smokexyz/Hercules]
VECTOR_INIT(sd->storage.item); // initialize storage item vector.
VECTOR_INIT(sd->hatEffectId);

// Storage
Expand Down
2 changes: 1 addition & 1 deletion src/map/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ static int storage_storageopen(struct map_session_data *sd, struct storage_data
/* Send item list to client if available. */
if (stor->aggregate > 0) {
storage->sortitem(VECTOR_DATA(stor->item), VECTOR_LENGTH(stor->item));
clif->storagelist(sd, VECTOR_DATA(stor->item), VECTOR_LENGTH(stor->item));
}
clif->storageList(sd, VECTOR_DATA(stor->item), VECTOR_LENGTH(stor->item));

/* Send storage total items and max amount update. */
clif->updatestorageamount(sd, stor->aggregate, stst->capacity);
Expand Down

0 comments on commit c2fea08

Please sign in to comment.