diff options
author | Haru <haru@dotalux.com> | 2018-06-25 00:40:33 +0200 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2018-06-30 01:51:12 +0200 |
commit | 401b579bb064c180a5e17196fcd5b420bc3d49ee (patch) | |
tree | 6e52013d77377d5053567d5edbbf6a5232560808 /src/char/mapif.c | |
parent | 4bcd46503481e616214fd40424ea63adf9352db8 (diff) | |
download | hercules-401b579bb064c180a5e17196fcd5b420bc3d49ee.tar.gz hercules-401b579bb064c180a5e17196fcd5b420bc3d49ee.tar.bz2 hercules-401b579bb064c180a5e17196fcd5b420bc3d49ee.tar.xz hercules-401b579bb064c180a5e17196fcd5b420bc3d49ee.zip |
Move mapif functions from int_pet.c to mapif.c
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/char/mapif.c')
-rw-r--r-- | src/char/mapif.c | 151 |
1 files changed, 140 insertions, 11 deletions
diff --git a/src/char/mapif.c b/src/char/mapif.c index e2956af01..cba79de22 100644 --- a/src/char/mapif.c +++ b/src/char/mapif.c @@ -31,6 +31,7 @@ #include "char/int_mail.h" #include "char/int_mercenary.h" #include "char/int_party.h" +#include "char/int_pet.h" #include "char/int_rodex.h" #include "char/inter.h" #include "common/cbasetypes.h" @@ -1416,17 +1417,145 @@ int mapif_parse_PartyLeaderChange(int fd, int party_id, int account_id, int char return 1; } -int mapif_pet_created(int fd, int account_id, struct s_pet *p); -int mapif_pet_info(int fd, int account_id, struct s_pet *p); -int mapif_pet_noinfo(int fd, int account_id); -int mapif_save_pet_ack(int fd, int account_id, int flag); -int mapif_delete_pet_ack(int fd, int flag); -int mapif_save_pet(int fd, int account_id, const struct s_pet *data); -int mapif_delete_pet(int fd, int pet_id); -int mapif_parse_CreatePet(int fd); -int mapif_parse_LoadPet(int fd); -int mapif_parse_SavePet(int fd); -int mapif_parse_DeletePet(int fd); +int mapif_pet_created(int fd, int account_id, struct s_pet *p) +{ + WFIFOHEAD(fd, 12); + WFIFOW(fd, 0) = 0x3880; + WFIFOL(fd, 2) = account_id; + if (p != NULL){ + WFIFOW(fd, 6) = p->class_; + WFIFOL(fd, 8) = p->pet_id; + ShowInfo("int_pet: created pet %d - %s\n", p->pet_id, p->name); + } else { + WFIFOB(fd, 6) = 0; + WFIFOL(fd, 8) = 0; + } + WFIFOSET(fd, 12); + + return 0; +} + +int mapif_pet_info(int fd, int account_id, struct s_pet *p) +{ + nullpo_ret(p); + WFIFOHEAD(fd, sizeof(struct s_pet) + 9); + WFIFOW(fd, 0) = 0x3881; + WFIFOW(fd, 2) = sizeof(struct s_pet) + 9; + WFIFOL(fd, 4) = account_id; + WFIFOB(fd, 8) = 0; + memcpy(WFIFOP(fd, 9), p, sizeof(struct s_pet)); + WFIFOSET(fd, WFIFOW(fd, 2)); + + return 0; +} + +int mapif_pet_noinfo(int fd, int account_id) +{ + WFIFOHEAD(fd, sizeof(struct s_pet) + 9); + WFIFOW(fd, 0) = 0x3881; + WFIFOW(fd, 2) = sizeof(struct s_pet) + 9; + WFIFOL(fd, 4) = account_id; + WFIFOB(fd, 8) = 1; + memset(WFIFOP(fd, 9), 0, sizeof(struct s_pet)); + WFIFOSET(fd, WFIFOW(fd, 2)); + + return 0; +} + +int mapif_save_pet_ack(int fd, int account_id, int flag) +{ + WFIFOHEAD(fd, 7); + WFIFOW(fd, 0) = 0x3882; + WFIFOL(fd, 2) = account_id; + WFIFOB(fd, 6) = flag; + WFIFOSET(fd, 7); + + return 0; +} + +int mapif_delete_pet_ack(int fd, int flag) +{ + WFIFOHEAD(fd, 3); + WFIFOW(fd, 0) = 0x3883; + WFIFOB(fd, 2) = flag; + WFIFOSET(fd, 3); + + return 0; +} + +int mapif_save_pet(int fd, int account_id, const struct s_pet *data) +{ + //here process pet save request. + int len; + nullpo_ret(data); + RFIFOHEAD(fd); + len = RFIFOW(fd, 2); + if (sizeof(struct s_pet) != len-8) { + ShowError("inter pet: data size mismatch: %d != %"PRIuS"\n", len-8, sizeof(struct s_pet)); + return 0; + } + + inter_pet->tosql(data); + mapif->save_pet_ack(fd, account_id, 0); + + return 0; +} + +int mapif_delete_pet(int fd, int pet_id) +{ + mapif->delete_pet_ack(fd, inter_pet->delete_(pet_id)); + + return 0; +} + +int mapif_parse_CreatePet(int fd) +{ + int account_id; + struct s_pet *pet; + + RFIFOHEAD(fd); + account_id = RFIFOL(fd, 2); + pet = inter_pet->create(account_id, RFIFOL(fd, 6), RFIFOW(fd, 10), RFIFOW(fd, 12), RFIFOW(fd, 14), + RFIFOW(fd, 16), RFIFOW(fd, 18), RFIFOW(fd, 20), RFIFOB(fd, 22), RFIFOB(fd, 23), RFIFOP(fd, 24)); + + if (pet != NULL) + mapif->pet_created(fd, account_id, pet); + else + mapif->pet_created(fd, account_id, NULL); + + return 0; +} + +int mapif_parse_LoadPet(int fd) +{ + int account_id; + struct s_pet *pet; + + RFIFOHEAD(fd); + account_id = RFIFOL(fd, 2); + pet = inter_pet->load(account_id, RFIFOL(fd, 6), RFIFOL(fd, 10)); + + if (pet != NULL) + mapif->pet_info(fd, account_id, pet); + else + mapif->pet_noinfo(fd, account_id); + return 0; +} + +int mapif_parse_SavePet(int fd) +{ + RFIFOHEAD(fd); + mapif->save_pet(fd, RFIFOL(fd, 4), RFIFOP(fd, 8)); + return 0; +} + +int mapif_parse_DeletePet(int fd) +{ + RFIFOHEAD(fd); + mapif->delete_pet(fd, RFIFOL(fd, 2)); + return 0; +} + struct quest *mapif_quests_fromsql(int char_id, int *count); bool mapif_quest_delete(int char_id, int quest_id); bool mapif_quest_add(int char_id, struct quest qd); |