diff options
author | Haru <haru@dotalux.com> | 2018-06-25 04:34:23 +0200 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2018-06-30 01:51:13 +0200 |
commit | 031f6ee5a7c8bb2f33929d5e17cd264b21d08b9f (patch) | |
tree | 4896d2f1ce66613107fa29df060975a476180a91 | |
parent | 256758edbb6b61630b1f072762b07226f053d2e6 (diff) | |
download | hercules-031f6ee5a7c8bb2f33929d5e17cd264b21d08b9f.tar.gz hercules-031f6ee5a7c8bb2f33929d5e17cd264b21d08b9f.tar.bz2 hercules-031f6ee5a7c8bb2f33929d5e17cd264b21d08b9f.tar.xz hercules-031f6ee5a7c8bb2f33929d5e17cd264b21d08b9f.zip |
Move mapif functions from int_storage.c to mapif.c
Signed-off-by: Haru <haru@dotalux.com>
-rw-r--r-- | src/char/int_storage.c | 214 | ||||
-rw-r--r-- | src/char/mapif.c | 218 |
2 files changed, 208 insertions, 224 deletions
diff --git a/src/char/int_storage.c b/src/char/int_storage.c index 4c1e6cb85..3deb8d58b 100644 --- a/src/char/int_storage.c +++ b/src/char/int_storage.c @@ -339,200 +339,6 @@ int inter_storage_guild_storage_delete(int guild_id) return 0; } -//--------------------------------------------------------- -// packet from map server - -int mapif_load_guild_storage(int fd, int account_id, int guild_id, char flag) -{ - if( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `guild_id` FROM `%s` WHERE `guild_id`='%d'", guild_db, guild_id) ) - Sql_ShowDebug(inter->sql_handle); - else if( SQL->NumRows(inter->sql_handle) > 0 ) - {// guild exists - WFIFOHEAD(fd, sizeof(struct guild_storage)+13); - WFIFOW(fd,0) = 0x3818; - WFIFOW(fd,2) = sizeof(struct guild_storage)+13; - WFIFOL(fd,4) = account_id; - WFIFOL(fd,8) = guild_id; - WFIFOB(fd,12) = flag; //1 open storage, 0 don't open - inter_storage->guild_storage_fromsql(guild_id, WFIFOP(fd,13)); - WFIFOSET(fd, WFIFOW(fd,2)); - return 0; - } - // guild does not exist - SQL->FreeResult(inter->sql_handle); - WFIFOHEAD(fd, 12); - WFIFOW(fd,0) = 0x3818; - WFIFOW(fd,2) = 12; - WFIFOL(fd,4) = account_id; - WFIFOL(fd,8) = 0; - WFIFOSET(fd, 12); - return 0; -} -int mapif_save_guild_storage_ack(int fd, int account_id, int guild_id, int fail) -{ - WFIFOHEAD(fd,11); - WFIFOW(fd,0)=0x3819; - WFIFOL(fd,2)=account_id; - WFIFOL(fd,6)=guild_id; - WFIFOB(fd,10)=fail; - WFIFOSET(fd,11); - return 0; -} - -//========================================================= -// Account Storage -//--------------------------------------------------------- -/** - * Parses account storage load request from map server. - * @packet 0x3010 [in] <account_id>.L - * @param fd [in] file/socket descriptor - * @return 1 on success, 0 on failure. - */ -int mapif_parse_AccountStorageLoad(int fd) -{ - int account_id = RFIFOL(fd, 2); - - Assert_ret(fd > 0); - Assert_ret(account_id > 0); - - mapif->account_storage_load(fd, account_id); - - return 1; -} - -/** - * Loads the account storage and send to the map server. - * @packet 0x3805 [out] <account_id>.L <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. - */ -int mapif_account_storage_load(int fd, int account_id) -{ - 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); - - len = 8 + count * sizeof(struct item); - - WFIFOHEAD(fd, len); - WFIFOW(fd, 0) = 0x3805; - WFIFOW(fd, 2) = (uint16) len; - WFIFOL(fd, 4) = account_id; - for (i = 0; i < count; i++) - memcpy(WFIFOP(fd, 8 + i * sizeof(struct item)), &VECTOR_INDEX(stor.item, i), sizeof(struct item)); - WFIFOSET(fd, len); - - VECTOR_CLEAR(stor.item); - - return 1; -} - -/** - * Parses an account storage save request from the map server. - * @packet 0x3011 [in] <packet_len>.W <account_id>.L <struct item[]>.P - * @param fd [in] file/socket descriptor. - * @return 1 on success, 0 on failure. - */ -int mapif_parse_AccountStorageSave(int fd) -{ - int payload_size = RFIFOW(fd, 2) - 8, account_id = RFIFOL(fd, 4); - int i = 0, count = 0; - struct storage_data p_stor = { 0 }; - - Assert_ret(fd > 0); - Assert_ret(account_id > 0); - - count = payload_size/sizeof(struct item); - - VECTOR_INIT(p_stor.item); - - if (count > 0) { - VECTOR_ENSURE(p_stor.item, count, 1); - - for (i = 0; i < count; i++) { - const struct item *it = RFIFOP(fd, 8 + i * sizeof(struct item)); - - VECTOR_PUSH(p_stor.item, *it); - } - - p_stor.aggregate = count; - } - - inter_storage->tosql(account_id, &p_stor); - - VECTOR_CLEAR(p_stor.item); - - mapif->sAccountStorageSaveAck(fd, account_id, true); - - return 1; -} - -/** - * Sends an acknowledgement for the save - * status of the account storage. - * @packet 0x3808 [out] <account_id>.L <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. - */ -void mapif_send_AccountStorageSaveAck(int fd, int account_id, bool flag) -{ - WFIFOHEAD(fd, 7); - WFIFOW(fd, 0) = 0x3808; - WFIFOL(fd, 2) = account_id; - WFIFOB(fd, 6) = flag ? 1 : 0; - WFIFOSET(fd, 7); -} - -//========================================================= -// Guild Storage -//--------------------------------------------------------- -int mapif_parse_LoadGuildStorage(int fd) -{ - RFIFOHEAD(fd); - - mapif->load_guild_storage(fd,RFIFOL(fd,2),RFIFOL(fd,6),1); - - return 0; -} - -int mapif_parse_SaveGuildStorage(int fd) -{ - int guild_id; - int len; - - RFIFOHEAD(fd); - guild_id = RFIFOL(fd,8); - len = RFIFOW(fd,2); - - if (sizeof(struct guild_storage) != len - 12) { - ShowError("inter storage: data size mismatch: %d != %"PRIuS"\n", len - 12, sizeof(struct guild_storage)); - } else if (inter_storage->guild_storage_tosql(guild_id, RFIFOP(fd,12))) { - mapif->save_guild_storage_ack(fd, RFIFOL(fd,4), guild_id, 0); - return 0; - } - mapif->save_guild_storage_ack(fd, RFIFOL(fd,4), guild_id, 1); - - return 0; -} - -int mapif_itembound_ack(int fd, int aid, int guild_id) -{ -#ifdef GP_BOUND_ITEMS - WFIFOHEAD(fd,8); - WFIFOW(fd,0) = 0x3856; - WFIFOL(fd,2) = aid;/* the value is not being used, drop? */ - WFIFOW(fd,6) = guild_id; - WFIFOSET(fd,8); -#endif - return 0; -} - //------------------------------------------------ //Guild bound items pull for offline characters [Akinari] //Revised by [Mhalicot] @@ -711,26 +517,6 @@ bool inter_storage_retrieve_bound_items(int char_id, int account_id, int guild_i return true; } -void mapif_parse_ItemBoundRetrieve(int fd) -{ -#ifdef GP_BOUND_ITEMS - int char_id = RFIFOL(fd, 2); - int account_id = RFIFOL(fd, 6); - int guild_id = RFIFOW(fd, 10); - - inter_storage->retrieve_bound_items(char_id, account_id, guild_id); - - //Finally reload storage and tell map we're done - mapif->load_guild_storage(fd, account_id, guild_id, 0); - - // If character is logged in char, disconnect - chr->disconnect_player(account_id); -#endif // GP_BOUND_ITEMS - - /* tell map server the operation is over and it can unlock the storage */ - mapif->itembound_ack(fd,RFIFOL(fd,6),RFIFOW(fd,10)); -} - int inter_storage_parse_frommap(int fd) { RFIFOHEAD(fd); diff --git a/src/char/mapif.c b/src/char/mapif.c index 3ccfd5582..1dfa08b82 100644 --- a/src/char/mapif.c +++ b/src/char/mapif.c @@ -20,6 +20,7 @@ */ #define HERCULES_CORE +#include "config/core.h" // GP_BOUND_ITEMS #include "mapif.h" #include "char/char.h" @@ -34,6 +35,7 @@ #include "char/int_pet.h" #include "char/int_quest.h" #include "char/int_rodex.h" +#include "char/int_storage.h" #include "char/inter.h" #include "common/cbasetypes.h" #include "common/memmgr.h" @@ -1804,16 +1806,212 @@ void mapif_rodex_checkname(int fd, int reqchar_id, int target_char_id, short tar WFIFOSET(fd, 16 + NAME_LENGTH); } -int mapif_load_guild_storage(int fd,int account_id,int guild_id, char flag); -int mapif_save_guild_storage_ack(int fd, int account_id, int guild_id, int fail); -int mapif_parse_LoadGuildStorage(int fd); -int mapif_parse_SaveGuildStorage(int fd); -int mapif_account_storage_load(int fd, int account_id); -int mapif_parse_AccountStorageLoad(int fd); -int mapif_parse_AccountStorageSave(int fd); -void mapif_send_AccountStorageSaveAck(int fd, int account_id, bool save); -int mapif_itembound_ack(int fd, int aid, int guild_id); -void mapif_parse_ItemBoundRetrieve(int fd); +int mapif_load_guild_storage(int fd, int account_id, int guild_id, char flag) +{ + if (SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `guild_id` FROM `%s` WHERE `guild_id`='%d'", guild_db, guild_id)) { + Sql_ShowDebug(inter->sql_handle); + } else if (SQL->NumRows(inter->sql_handle) > 0) { + // guild exists + WFIFOHEAD(fd, sizeof(struct guild_storage) + 13); + WFIFOW(fd, 0) = 0x3818; + WFIFOW(fd, 2) = sizeof(struct guild_storage)+13; + WFIFOL(fd, 4) = account_id; + WFIFOL(fd, 8) = guild_id; + WFIFOB(fd, 12) = flag; //1 open storage, 0 don't open + inter_storage->guild_storage_fromsql(guild_id, WFIFOP(fd, 13)); + WFIFOSET(fd, WFIFOW(fd, 2)); + return 0; + } + // guild does not exist + SQL->FreeResult(inter->sql_handle); + WFIFOHEAD(fd, 12); + WFIFOW(fd, 0) = 0x3818; + WFIFOW(fd, 2) = 12; + WFIFOL(fd, 4) = account_id; + WFIFOL(fd, 8) = 0; + WFIFOSET(fd, 12); + return 0; +} + +int mapif_save_guild_storage_ack(int fd, int account_id, int guild_id, int fail) +{ + WFIFOHEAD(fd, 11); + WFIFOW(fd, 0) = 0x3819; + WFIFOL(fd, 2) = account_id; + WFIFOL(fd, 6) = guild_id; + WFIFOB(fd, 10) = fail; + WFIFOSET(fd, 11); + return 0; +} + +/** + * Loads the account storage and send to the map server. + * @packet 0x3805 [out] <account_id>.L <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. + */ +int mapif_account_storage_load(int fd, int account_id) +{ + 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); + + len = 8 + count * sizeof(struct item); + + WFIFOHEAD(fd, len); + WFIFOW(fd, 0) = 0x3805; + WFIFOW(fd, 2) = (uint16) len; + WFIFOL(fd, 4) = account_id; + for (i = 0; i < count; i++) + memcpy(WFIFOP(fd, 8 + i * sizeof(struct item)), &VECTOR_INDEX(stor.item, i), sizeof(struct item)); + WFIFOSET(fd, len); + + VECTOR_CLEAR(stor.item); + + return 1; +} + +/** + * Parses account storage load request from map server. + * @packet 0x3010 [in] <account_id>.L + * @param fd [in] file/socket descriptor + * @return 1 on success, 0 on failure. + */ +int mapif_parse_AccountStorageLoad(int fd) +{ + int account_id = RFIFOL(fd, 2); + + Assert_ret(fd > 0); + Assert_ret(account_id > 0); + + mapif->account_storage_load(fd, account_id); + + return 1; +} + +/** + * Parses an account storage save request from the map server. + * @packet 0x3011 [in] <packet_len>.W <account_id>.L <struct item[]>.P + * @param fd [in] file/socket descriptor. + * @return 1 on success, 0 on failure. + */ +int mapif_parse_AccountStorageSave(int fd) +{ + int payload_size = RFIFOW(fd, 2) - 8, account_id = RFIFOL(fd, 4); + int i = 0, count = 0; + struct storage_data p_stor = { 0 }; + + Assert_ret(fd > 0); + Assert_ret(account_id > 0); + + count = payload_size/sizeof(struct item); + + VECTOR_INIT(p_stor.item); + + if (count > 0) { + VECTOR_ENSURE(p_stor.item, count, 1); + + for (i = 0; i < count; i++) { + const struct item *it = RFIFOP(fd, 8 + i * sizeof(struct item)); + + VECTOR_PUSH(p_stor.item, *it); + } + + p_stor.aggregate = count; + } + + inter_storage->tosql(account_id, &p_stor); + + VECTOR_CLEAR(p_stor.item); + + mapif->sAccountStorageSaveAck(fd, account_id, true); + + return 1; +} + +/** + * Sends an acknowledgement for the save + * status of the account storage. + * @packet 0x3808 [out] <account_id>.L <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. + */ +void mapif_send_AccountStorageSaveAck(int fd, int account_id, bool flag) +{ + WFIFOHEAD(fd, 7); + WFIFOW(fd, 0) = 0x3808; + WFIFOL(fd, 2) = account_id; + WFIFOB(fd, 6) = flag ? 1 : 0; + WFIFOSET(fd, 7); +} + +int mapif_parse_LoadGuildStorage(int fd) +{ + RFIFOHEAD(fd); + + mapif->load_guild_storage(fd, RFIFOL(fd, 2), RFIFOL(fd, 6), 1); + + return 0; +} + +int mapif_parse_SaveGuildStorage(int fd) +{ + int guild_id; + int len; + + RFIFOHEAD(fd); + guild_id = RFIFOL(fd, 8); + len = RFIFOW(fd, 2); + + if (sizeof(struct guild_storage) != len - 12) { + ShowError("inter storage: data size mismatch: %d != %"PRIuS"\n", len - 12, sizeof(struct guild_storage)); + } else if (inter_storage->guild_storage_tosql(guild_id, RFIFOP(fd, 12))) { + mapif->save_guild_storage_ack(fd, RFIFOL(fd, 4), guild_id, 0); + return 0; + } + mapif->save_guild_storage_ack(fd, RFIFOL(fd, 4), guild_id, 1); + + return 0; +} + +int mapif_itembound_ack(int fd, int aid, int guild_id) +{ +#ifdef GP_BOUND_ITEMS + WFIFOHEAD(fd, 8); + WFIFOW(fd, 0) = 0x3856; + WFIFOL(fd, 2) = aid;/* the value is not being used, drop? */ + WFIFOW(fd, 6) = guild_id; + WFIFOSET(fd, 8); +#endif + return 0; +} + +void mapif_parse_ItemBoundRetrieve(int fd) +{ +#ifdef GP_BOUND_ITEMS + int char_id = RFIFOL(fd, 2); + int account_id = RFIFOL(fd, 6); + int guild_id = RFIFOW(fd, 10); + + inter_storage->retrieve_bound_items(char_id, account_id, guild_id); + + //Finally reload storage and tell map we're done + mapif->load_guild_storage(fd, account_id, guild_id, 0); + + // If character is logged in char, disconnect + chr->disconnect_player(account_id); +#endif // GP_BOUND_ITEMS + + /* tell map server the operation is over and it can unlock the storage */ + mapif->itembound_ack(fd, RFIFOL(fd, 6), RFIFOW(fd, 10)); +} + void mapif_parse_accinfo(int fd); void mapif_parse_accinfo2(bool success, int map_fd, int u_fd, int u_aid, int account_id, const char *userid, const char *user_pass, const char *email, const char *last_ip, const char *lastlogin, const char *pin_code, const char *birthdate, int group_id, int logincount, int state); |