summaryrefslogtreecommitdiff
path: root/src/char/int_pet.c
diff options
context:
space:
mode:
authorHaruna <haru@dotalux.com>2014-11-15 17:04:09 +0100
committerHaruna <haru@dotalux.com>2014-11-15 17:04:09 +0100
commita6f077063eeff08ee27ae5170de1bb5cf4b2defb (patch)
tree9bb5ab158230301e604918883ce6d06c31890341 /src/char/int_pet.c
parent77b88fe80b907122b24d698938538c22e029d25f (diff)
parent7f9fa7f59a82682fb139be4301e9a12a99644a19 (diff)
downloadhercules-a6f077063eeff08ee27ae5170de1bb5cf4b2defb.tar.gz
hercules-a6f077063eeff08ee27ae5170de1bb5cf4b2defb.tar.bz2
hercules-a6f077063eeff08ee27ae5170de1bb5cf4b2defb.tar.xz
hercules-a6f077063eeff08ee27ae5170de1bb5cf4b2defb.zip
Merge pull request #388 from 4144/charplugins
char server plugins
Diffstat (limited to 'src/char/int_pet.c')
-rw-r--r--src/char/int_pet.c207
1 files changed, 117 insertions, 90 deletions
diff --git a/src/char/int_pet.c b/src/char/int_pet.c
index bf7961462..c68fe6476 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,7 +21,7 @@
#include "../common/strlib.h"
#include "../common/utils.h"
-struct s_pet *pet_pt;
+struct inter_pet_interface inter_pet_s;
//---------------------------------------------------------
int inter_pet_tosql(int pet_id, struct s_pet* p)
@@ -28,30 +29,30 @@ int inter_pet_tosql(int pet_id, struct s_pet* p)
//`pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate`)
char esc_name[NAME_LENGTH*2+1];// escaped pet name
- SQL->EscapeStringLen(sql_handle, esc_name, p->name, strnlen(p->name, NAME_LENGTH));
+ SQL->EscapeStringLen(inter->sql_handle, esc_name, p->name, strnlen(p->name, NAME_LENGTH));
p->hungry = cap_value(p->hungry, 0, 100);
p->intimate = cap_value(p->intimate, 0, 1000);
if( pet_id == -1 )
{// New pet.
- if( SQL_ERROR == SQL->Query(sql_handle, "INSERT INTO `%s` "
+ if( SQL_ERROR == SQL->Query(inter->sql_handle, "INSERT INTO `%s` "
"(`class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate`) "
"VALUES ('%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')",
pet_db, p->class_, esc_name, p->account_id, p->char_id, p->level, p->egg_id,
p->equip, p->intimate, p->hungry, p->rename_flag, p->incubate) )
{
- Sql_ShowDebug(sql_handle);
+ Sql_ShowDebug(inter->sql_handle);
return 0;
}
- p->pet_id = (int)SQL->LastInsertId(sql_handle);
+ p->pet_id = (int)SQL->LastInsertId(inter->sql_handle);
}
else
{// Update pet.
- if( SQL_ERROR == SQL->Query(sql_handle, "UPDATE `%s` SET `class`='%d',`name`='%s',`account_id`='%d',`char_id`='%d',`level`='%d',`egg_id`='%d',`equip`='%d',`intimate`='%d',`hungry`='%d',`rename_flag`='%d',`incubate`='%d' WHERE `pet_id`='%d'",
+ if( SQL_ERROR == SQL->Query(inter->sql_handle, "UPDATE `%s` SET `class`='%d',`name`='%s',`account_id`='%d',`char_id`='%d',`level`='%d',`egg_id`='%d',`equip`='%d',`intimate`='%d',`hungry`='%d',`rename_flag`='%d',`incubate`='%d' WHERE `pet_id`='%d'",
pet_db, p->class_, esc_name, p->account_id, p->char_id, p->level, p->egg_id,
p->equip, p->intimate, p->hungry, p->rename_flag, p->incubate, p->pet_id) )
{
- Sql_ShowDebug(sql_handle);
+ Sql_ShowDebug(inter->sql_handle);
return 0;
}
}
@@ -73,28 +74,28 @@ int inter_pet_fromsql(int pet_id, struct s_pet* p)
//`pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate`)
- if( SQL_ERROR == SQL->Query(sql_handle, "SELECT `pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate` FROM `%s` WHERE `pet_id`='%d'", pet_db, pet_id) )
+ if( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incubate` FROM `%s` WHERE `pet_id`='%d'", pet_db, pet_id) )
{
- Sql_ShowDebug(sql_handle);
+ Sql_ShowDebug(inter->sql_handle);
return 0;
}
- if( SQL_SUCCESS == SQL->NextRow(sql_handle) )
+ if( SQL_SUCCESS == SQL->NextRow(inter->sql_handle) )
{
p->pet_id = pet_id;
- SQL->GetData(sql_handle, 1, &data, NULL); p->class_ = atoi(data);
- SQL->GetData(sql_handle, 2, &data, &len); memcpy(p->name, data, min(len, NAME_LENGTH));
- SQL->GetData(sql_handle, 3, &data, NULL); p->account_id = atoi(data);
- SQL->GetData(sql_handle, 4, &data, NULL); p->char_id = atoi(data);
- SQL->GetData(sql_handle, 5, &data, NULL); p->level = atoi(data);
- SQL->GetData(sql_handle, 6, &data, NULL); p->egg_id = atoi(data);
- SQL->GetData(sql_handle, 7, &data, NULL); p->equip = atoi(data);
- SQL->GetData(sql_handle, 8, &data, NULL); p->intimate = atoi(data);
- SQL->GetData(sql_handle, 9, &data, NULL); p->hungry = atoi(data);
- SQL->GetData(sql_handle, 10, &data, NULL); p->rename_flag = atoi(data);
- SQL->GetData(sql_handle, 11, &data, NULL); p->incubate = atoi(data);
-
- SQL->FreeResult(sql_handle);
+ SQL->GetData(inter->sql_handle, 1, &data, NULL); p->class_ = atoi(data);
+ SQL->GetData(inter->sql_handle, 2, &data, &len); memcpy(p->name, data, min(len, NAME_LENGTH));
+ SQL->GetData(inter->sql_handle, 3, &data, NULL); p->account_id = atoi(data);
+ SQL->GetData(inter->sql_handle, 4, &data, NULL); p->char_id = atoi(data);
+ SQL->GetData(inter->sql_handle, 5, &data, NULL); p->level = atoi(data);
+ SQL->GetData(inter->sql_handle, 6, &data, NULL); p->egg_id = atoi(data);
+ SQL->GetData(inter->sql_handle, 7, &data, NULL); p->equip = atoi(data);
+ SQL->GetData(inter->sql_handle, 8, &data, NULL); p->intimate = atoi(data);
+ SQL->GetData(inter->sql_handle, 9, &data, NULL); p->hungry = atoi(data);
+ SQL->GetData(inter->sql_handle, 10, &data, NULL); p->rename_flag = atoi(data);
+ SQL->GetData(inter->sql_handle, 11, &data, NULL); p->incubate = atoi(data);
+
+ SQL->FreeResult(inter->sql_handle);
p->hungry = cap_value(p->hungry, 0, 100);
p->intimate = cap_value(p->intimate, 0, 1000);
@@ -106,21 +107,21 @@ 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);
+ inter_pet->pt = (struct s_pet*)aCalloc(sizeof(struct s_pet), 1);
return 0;
}
-void inter_pet_sql_final(void){
- if (pet_pt) aFree(pet_pt);
+void inter_pet_sql_final(void) {
+ if (inter_pet->pt) aFree(inter_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) )
- Sql_ShowDebug(sql_handle);
+ if( SQL_ERROR == SQL->Query(inter->sql_handle, "DELETE FROM `%s` WHERE `pet_id`='%d'", pet_db, pet_id) )
+ Sql_ShowDebug(inter->sql_handle);
return 0;
}
//------------------------------------------------------
@@ -142,7 +143,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 +156,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 +169,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 +180,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;
@@ -188,63 +193,65 @@ 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)
{
- memset(pet_pt, 0, sizeof(struct s_pet));
- safestrncpy(pet_pt->name, pet_name, NAME_LENGTH);
+ memset(inter_pet->pt, 0, sizeof(struct s_pet));
+ safestrncpy(inter_pet->pt->name, pet_name, NAME_LENGTH);
if(incubate == 1)
- pet_pt->account_id = pet_pt->char_id = 0;
+ inter_pet->pt->account_id = inter_pet->pt->char_id = 0;
else {
- pet_pt->account_id = account_id;
- pet_pt->char_id = char_id;
+ inter_pet->pt->account_id = account_id;
+ inter_pet->pt->char_id = char_id;
}
- pet_pt->class_ = pet_class;
- pet_pt->level = pet_lv;
- pet_pt->egg_id = pet_egg_id;
- pet_pt->equip = pet_equip;
- pet_pt->intimate = intimate;
- pet_pt->hungry = hungry;
- pet_pt->rename_flag = rename_flag;
- pet_pt->incubate = incubate;
-
- if(pet_pt->hungry < 0)
- pet_pt->hungry = 0;
- else if(pet_pt->hungry > 100)
- pet_pt->hungry = 100;
- if(pet_pt->intimate < 0)
- pet_pt->intimate = 0;
- else if(pet_pt->intimate > 1000)
- 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);
+ inter_pet->pt->class_ = pet_class;
+ inter_pet->pt->level = pet_lv;
+ inter_pet->pt->egg_id = pet_egg_id;
+ inter_pet->pt->equip = pet_equip;
+ inter_pet->pt->intimate = intimate;
+ inter_pet->pt->hungry = hungry;
+ inter_pet->pt->rename_flag = rename_flag;
+ inter_pet->pt->incubate = incubate;
+
+ if(inter_pet->pt->hungry < 0)
+ inter_pet->pt->hungry = 0;
+ else if(inter_pet->pt->hungry > 100)
+ inter_pet->pt->hungry = 100;
+ if(inter_pet->pt->intimate < 0)
+ inter_pet->pt->intimate = 0;
+ else if(inter_pet->pt->intimate > 1000)
+ inter_pet->pt->intimate = 1000;
+
+ inter_pet->pt->pet_id = -1; //Signal NEW pet.
+ if (inter_pet->tosql(inter_pet->pt->pet_id,inter_pet->pt))
+ mapif->pet_created(fd, account_id, inter_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){
- memset(pet_pt, 0, sizeof(struct s_pet));
+int mapif_load_pet(int fd, int account_id, int char_id, int pet_id)
+{
+ memset(inter_pet->pt, 0, sizeof(struct s_pet));
- inter_pet_fromsql(pet_id, pet_pt);
+ inter_pet->fromsql(pet_id, inter_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);
+ if(inter_pet->pt!=NULL) {
+ if(inter_pet->pt->incubate == 1) {
+ inter_pet->pt->account_id = inter_pet->pt->char_id = 0;
+ mapif->pet_info(fd, account_id, inter_pet->pt);
}
- else if(account_id == pet_pt->account_id && char_id == pet_pt->char_id)
- mapif_pet_info(fd, account_id, pet_pt);
+ else if(account_id == inter_pet->pt->account_id && char_id == inter_pet->pt->char_id)
+ mapif->pet_info(fd, account_id, inter_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 +269,72 @@ 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->pt = NULL;
+
+ 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;
+ inter_pet->parse_frommap = inter_pet_parse_frommap;
+}