diff options
-rw-r--r-- | src/char/char.c | 2 | ||||
-rw-r--r-- | src/char/int_pet.c | 94 | ||||
-rw-r--r-- | src/char/int_pet.h | 19 | ||||
-rw-r--r-- | src/char/inter.c | 6 | ||||
-rw-r--r-- | src/char/mapif.c | 27 | ||||
-rw-r--r-- | src/char/mapif.h | 15 |
6 files changed, 117 insertions, 46 deletions
diff --git a/src/char/char.c b/src/char/char.c index 7d1060128..094003ec2 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -23,6 +23,7 @@ #include "int_mail.h" #include "int_mercenary.h" #include "int_party.h" +#include "int_pet.h" #include "int_storage.h" #include "inter.h" #include "loginif.h" @@ -6013,6 +6014,7 @@ void char_load_defaults(void) inter_mail_defaults(); inter_mercenary_defaults(); inter_party_defaults(); + inter_pet_defaults(); } void char_defaults(void) diff --git a/src/char/int_pet.c b/src/char/int_pet.c index bf7961462..792f6678c 100644 --- a/src/char/int_pet.c +++ b/src/char/int_pet.c @@ -12,6 +12,7 @@ #include "char.h" #include "inter.h" +#include "mapif.h" #include "../common/malloc.h" #include "../common/mmo.h" #include "../common/showmsg.h" @@ -20,6 +21,8 @@ #include "../common/strlib.h" #include "../common/utils.h" +struct inter_pet_interface inter_pet_s; + struct s_pet *pet_pt; //--------------------------------------------------------- @@ -106,17 +109,17 @@ int inter_pet_fromsql(int pet_id, struct s_pet* p) } //---------------------------------------------- -int inter_pet_sql_init(void){ +int inter_pet_sql_init(void) { //memory alloc pet_pt = (struct s_pet*)aCalloc(sizeof(struct s_pet), 1); return 0; } -void inter_pet_sql_final(void){ +void inter_pet_sql_final(void) { if (pet_pt) aFree(pet_pt); return; } //---------------------------------- -int inter_pet_delete(int pet_id){ +int inter_pet_delete(int pet_id) { ShowInfo("delete pet request: %d...\n",pet_id); if( SQL_ERROR == SQL->Query(sql_handle, "DELETE FROM `%s` WHERE `pet_id`='%d'", pet_db, pet_id) ) @@ -142,7 +145,8 @@ int mapif_pet_created(int fd, int account_id, struct s_pet *p) return 0; } -int mapif_pet_info(int fd, int account_id, struct s_pet *p){ +int mapif_pet_info(int fd, int account_id, struct s_pet *p) +{ WFIFOHEAD(fd, sizeof(struct s_pet) + 9); WFIFOW(fd, 0) =0x3881; WFIFOW(fd, 2) =sizeof(struct s_pet) + 9; @@ -154,7 +158,8 @@ int mapif_pet_info(int fd, int account_id, struct s_pet *p){ return 0; } -int mapif_pet_noinfo(int fd, int account_id){ +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; @@ -166,7 +171,8 @@ int mapif_pet_noinfo(int fd, int account_id){ return 0; } -int mapif_save_pet_ack(int fd, int account_id, int flag){ +int mapif_save_pet_ack(int fd, int account_id, int flag) +{ WFIFOHEAD(fd, 7); WFIFOW(fd, 0) =0x3882; WFIFOL(fd, 2) =account_id; @@ -176,7 +182,8 @@ int mapif_save_pet_ack(int fd, int account_id, int flag){ return 0; } -int mapif_delete_pet_ack(int fd, int flag){ +int mapif_delete_pet_ack(int fd, int flag) +{ WFIFOHEAD(fd, 3); WFIFOW(fd, 0) =0x3883; WFIFOB(fd, 2) =flag; @@ -215,36 +222,38 @@ int mapif_create_pet(int fd, int account_id, int char_id, short pet_class, short pet_pt->intimate = 1000; pet_pt->pet_id = -1; //Signal NEW pet. - if (inter_pet_tosql(pet_pt->pet_id,pet_pt)) - mapif_pet_created(fd, account_id, pet_pt); + if (inter_pet->tosql(pet_pt->pet_id,pet_pt)) + mapif->pet_created(fd, account_id, pet_pt); else //Failed... - mapif_pet_created(fd, account_id, NULL); + mapif->pet_created(fd, account_id, NULL); return 0; } -int mapif_load_pet(int fd, int account_id, int char_id, int pet_id){ +int mapif_load_pet(int fd, int account_id, int char_id, int pet_id) +{ memset(pet_pt, 0, sizeof(struct s_pet)); - inter_pet_fromsql(pet_id, pet_pt); + inter_pet->fromsql(pet_id, pet_pt); if(pet_pt!=NULL) { if(pet_pt->incubate == 1) { pet_pt->account_id = pet_pt->char_id = 0; - mapif_pet_info(fd, account_id, pet_pt); + mapif->pet_info(fd, account_id, pet_pt); } else if(account_id == pet_pt->account_id && char_id == pet_pt->char_id) - mapif_pet_info(fd, account_id, pet_pt); + mapif->pet_info(fd, account_id, pet_pt); else - mapif_pet_noinfo(fd, account_id); + mapif->pet_noinfo(fd, account_id); } else - mapif_pet_noinfo(fd, account_id); + mapif->pet_noinfo(fd, account_id); return 0; } -int mapif_save_pet(int fd, int account_id, struct s_pet *data) { +int mapif_save_pet(int fd, int account_id, struct s_pet *data) +{ //here process pet save request. int len; RFIFOHEAD(fd); @@ -262,52 +271,69 @@ int mapif_save_pet(int fd, int account_id, struct s_pet *data) { data->intimate = 0; else if (data->intimate > 1000) data->intimate = 1000; - inter_pet_tosql(data->pet_id,data); - mapif_save_pet_ack(fd, account_id, 0); + inter_pet->tosql(data->pet_id,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)); +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 mapif_parse_CreatePet(int fd) +{ RFIFOHEAD(fd); - mapif_create_pet(fd, RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOW(fd, 10), RFIFOW(fd, 12), RFIFOW(fd, 14), RFIFOW(fd, 16), RFIFOW(fd, 18), + mapif->create_pet(fd, RFIFOL(fd, 2), 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), (char*)RFIFOP(fd, 24)); return 0; } -int mapif_parse_LoadPet(int fd){ +int mapif_parse_LoadPet(int fd) +{ RFIFOHEAD(fd); - mapif_load_pet(fd, RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOL(fd, 10)); + mapif->load_pet(fd, RFIFOL(fd, 2), RFIFOL(fd, 6), RFIFOL(fd, 10)); return 0; } -int mapif_parse_SavePet(int fd){ +int mapif_parse_SavePet(int fd) +{ RFIFOHEAD(fd); - mapif_save_pet(fd, RFIFOL(fd, 4), (struct s_pet *) RFIFOP(fd, 8)); + mapif->save_pet(fd, RFIFOL(fd, 4), (struct s_pet *) RFIFOP(fd, 8)); return 0; } -int mapif_parse_DeletePet(int fd){ +int mapif_parse_DeletePet(int fd) +{ RFIFOHEAD(fd); - mapif_delete_pet(fd, RFIFOL(fd, 2)); + mapif->delete_pet(fd, RFIFOL(fd, 2)); return 0; } -int inter_pet_parse_frommap(int fd){ +int inter_pet_parse_frommap(int fd) +{ RFIFOHEAD(fd); switch(RFIFOW(fd, 0)){ - case 0x3080: mapif_parse_CreatePet(fd); break; - case 0x3081: mapif_parse_LoadPet(fd); break; - case 0x3082: mapif_parse_SavePet(fd); break; - case 0x3083: mapif_parse_DeletePet(fd); break; + case 0x3080: mapif->parse_CreatePet(fd); break; + case 0x3081: mapif->parse_LoadPet(fd); break; + case 0x3082: mapif->parse_SavePet(fd); break; + case 0x3083: mapif->parse_DeletePet(fd); break; default: return 0; } return 1; } + +void inter_pet_defaults(void) +{ + inter_pet = &inter_pet_s; + + inter_pet->tosql = inter_pet_tosql; + inter_pet->fromsql = inter_pet_fromsql; + inter_pet->sql_init = inter_pet_sql_init; + inter_pet->sql_final = inter_pet_sql_final; + inter_pet->delete_ = inter_pet_delete; +} diff --git a/src/char/int_pet.h b/src/char/int_pet.h index 52642fc54..44f3eb389 100644 --- a/src/char/int_pet.h +++ b/src/char/int_pet.h @@ -6,16 +6,17 @@ struct s_pet; -int inter_pet_init(void); -void inter_pet_sql_final(void); -int inter_pet_save(void); -int inter_pet_delete(int pet_id); +void inter_pet_defaults(void); -int inter_pet_parse_frommap(int fd); -int inter_pet_sql_init(void); -//extern char pet_txt[256]; +struct inter_pet_interface { + int (*tosql) (int pet_id, struct s_pet* p); + int (*fromsql) (int pet_id, struct s_pet* p); + int (*sql_init) (void); + void (*sql_final) (void); + int (*delete_) (int pet_id); + int (*parse_frommap) (int fd); +}; -//Exported for use in the TXT-SQL converter. -int inter_pet_tosql(int pet_id, struct s_pet *p); +struct inter_pet_interface *inter_pet; #endif /* CHAR_INT_PET_H */ diff --git a/src/char/inter.c b/src/char/inter.c index 37369364f..60c375bc1 100644 --- a/src/char/inter.c +++ b/src/char/inter.c @@ -1029,7 +1029,7 @@ int inter_init_sql(const char *file) inter_guild->sql_init(); inter_storage_sql_init(); inter_party->sql_init(); - inter_pet_sql_init(); + inter_pet->sql_init(); inter_homunculus->sql_init(); inter_mercenary->sql_init(); inter_elemental->sql_init(); @@ -1049,7 +1049,7 @@ void inter_final(void) inter_guild->sql_final(); inter_storage_sql_final(); inter_party->sql_final(); - inter_pet_sql_final(); + inter_pet->sql_final(); inter_homunculus->sql_final(); inter_mercenary->sql_final(); inter_elemental->sql_final(); @@ -1456,7 +1456,7 @@ int inter_parse_frommap(int fd) if( inter_party->parse_frommap(fd) || inter_guild->parse_frommap(fd) || inter_storage_parse_frommap(fd) - || inter_pet_parse_frommap(fd) + || inter_pet->parse_frommap(fd) || inter_homunculus->parse_frommap(fd) || inter_mercenary->parse_frommap(fd) || inter_elemental->parse_frommap(fd) diff --git a/src/char/mapif.c b/src/char/mapif.c index ac199b6e1..0a4d5a633 100644 --- a/src/char/mapif.c +++ b/src/char/mapif.c @@ -141,6 +141,20 @@ int mapif_parse_PartyChangeMap(int fd, int party_id, int account_id, int char_id int mapif_parse_BreakParty(int fd, int party_id); int mapif_parse_PartyMessage(int fd, int party_id, int account_id, char *mes, int len); int mapif_parse_PartyLeaderChange(int fd, int party_id, int account_id, int char_id); +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_create_pet(int fd, int account_id, int char_id, short pet_class, short pet_lv, short pet_egg_id, + short pet_equip, short intimate, short hungry, char rename_flag, char incubate, char *pet_name); +int mapif_load_pet(int fd, int account_id, int char_id, int pet_id); +int mapif_save_pet(int fd, int account_id, 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); void mapif_defaults(void) { mapif = &mapif_s; @@ -267,4 +281,17 @@ void mapif_defaults(void) { mapif->parse_BreakParty = mapif_parse_BreakParty; mapif->parse_PartyMessage = mapif_parse_PartyMessage; mapif->parse_PartyLeaderChange = mapif_parse_PartyLeaderChange; + mapif->pet_created = mapif_pet_created; + mapif->pet_info = mapif_pet_info; + mapif->pet_noinfo = mapif_pet_noinfo; + mapif->save_pet_ack = mapif_save_pet_ack; + mapif->delete_pet_ack = mapif_delete_pet_ack; + mapif->create_pet = mapif_create_pet; + mapif->load_pet = mapif_load_pet; + mapif->save_pet = mapif_save_pet; + mapif->delete_pet = mapif_delete_pet; + mapif->parse_CreatePet = mapif_parse_CreatePet; + mapif->parse_LoadPet = mapif_parse_LoadPet; + mapif->parse_SavePet = mapif_parse_SavePet; + mapif->parse_DeletePet = mapif_parse_DeletePet; } diff --git a/src/char/mapif.h b/src/char/mapif.h index efd2a1585..8c4c8922e 100644 --- a/src/char/mapif.h +++ b/src/char/mapif.h @@ -10,6 +10,7 @@ struct s_elemental; struct s_homunculus; struct s_mercenary; +struct s_pet; struct mail_message; /* mapif interface */ @@ -136,6 +137,20 @@ struct mapif_interface { int (*parse_BreakParty) (int fd, int party_id); int (*parse_PartyMessage) (int fd, int party_id, int account_id, char *mes, int len); int (*parse_PartyLeaderChange) (int fd, int party_id, int account_id, int char_id); + int (*pet_created) (int fd, int account_id, struct s_pet *p); + int (*pet_info) (int fd, int account_id, struct s_pet *p); + int (*pet_noinfo) (int fd, int account_id); + int (*save_pet_ack) (int fd, int account_id, int flag); + int (*delete_pet_ack) (int fd, int flag); + int (*create_pet) (int fd, int account_id, int char_id, short pet_class, short pet_lv, short pet_egg_id, + short pet_equip, short intimate, short hungry, char rename_flag, char incubate, char *pet_name); + int (*load_pet) (int fd, int account_id, int char_id, int pet_id); + int (*save_pet) (int fd, int account_id, struct s_pet *data); + int (*delete_pet) (int fd, int pet_id); + int (*parse_CreatePet) (int fd); + int (*parse_LoadPet) (int fd); + int (*parse_SavePet) (int fd); + int (*parse_DeletePet) (int fd); } mapif_s; struct mapif_interface *mapif; |