From 7b2f7c0503cb5be8bc45f57353d838a4dbf84d7b Mon Sep 17 00:00:00 2001 From: DracoRPG Date: Mon, 17 Jul 2006 00:15:33 +0000 Subject: Orn's and Albator's Homunculus system, finally, YAY!! git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@7706 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/char_sql/Makefile | 7 +- src/char_sql/char.c | 9 +- src/char_sql/int_homun.c | 300 +++++++++++++++++++++++++++++++++++++++++++++++ src/char_sql/int_homun.h | 14 +++ src/char_sql/inter.c | 11 +- 5 files changed, 333 insertions(+), 8 deletions(-) create mode 100644 src/char_sql/int_homun.c create mode 100644 src/char_sql/int_homun.h (limited to 'src/char_sql') diff --git a/src/char_sql/Makefile b/src/char_sql/Makefile index f67a95315..544ba82c0 100644 --- a/src/char_sql/Makefile +++ b/src/char_sql/Makefile @@ -10,7 +10,7 @@ COMMON_H = ../common/core.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/malloc.h ../common/showmsg.h ../common/utils.h ../common/strlib.h \ ../common/graph.h ../common/grfio.h ../common/mapindex.h -char-server_sql: char.o inter.o int_party.o int_guild.o int_storage.o int_pet.o itemdb.o $(COMMON_OBJ) +char-server_sql: char.o inter.o int_party.o int_guild.o int_storage.o int_pet.o int_homun.o itemdb.o $(COMMON_OBJ) $(CC) -o ../../$@ $^ $(LIB_S) clean: @@ -19,9 +19,10 @@ clean: # DO NOT DELETE char.o: char.c char.h ../common/strlib.h itemdb.h ../common/showmsg.h -inter.o: inter.c inter.h int_party.h int_guild.h int_storage.h int_pet.h ../common/mmo.h char.h ../common/socket.h ../common/showmsg.h +inter.o: inter.c inter.h int_party.h int_guild.h int_storage.h int_pet.h int_homun.h ../common/mmo.h char.h ../common/socket.h ../common/showmsg.h int_party.o: int_party.c int_party.h inter.h ../common/mmo.h char.h ../common/socket.h ../common/timer.h ../common/db.h ../common/showmsg.h int_guild.o: int_guild.c int_guild.h inter.h ../common/mmo.h char.h ../common/socket.h ../common/db.h ../common/showmsg.h int_storage.o: int_storage.c int_storage.h char.h itemdb.h ../common/showmsg.h int_pet.o: int_pet.c int_pet.h inter.h char.h ../common/mmo.h ../common/socket.h ../common/db.h ../common/showmsg.h -itemdb.o: itemdb.c itemdb.h ../common/db.h ../common/mmo.h ../common/showmsg.h +int_homun.o: int_homun.c int_homun.h inter.h char.h ../common/mmo.h ../common/socket.h ../common/db.h ../common/showmsg.h +itemdb.o: itemdb.c itemdb.h ../common/db.h ../common/mmo.h ../common/showmsg.h \ No newline at end of file diff --git a/src/char_sql/char.c b/src/char_sql/char.c index 15da747e5..682a2c7d0 100644 --- a/src/char_sql/char.c +++ b/src/char_sql/char.c @@ -491,7 +491,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){ "`base_exp`='%u', `job_exp`='%u', `zeny`='%d'," "`max_hp`='%d',`hp`='%d',`max_sp`='%d',`sp`='%d',`status_point`='%d',`skill_point`='%d'," "`str`='%d',`agi`='%d',`vit`='%d',`int`='%d',`dex`='%d',`luk`='%d'," - "`option`='%d',`party_id`='%d',`guild_id`='%d',`pet_id`='%d'," + "`option`='%d',`party_id`='%d',`guild_id`='%d',`pet_id`='%d',`homun_id`='%d'," //[orn] add homun_id (homunculus id) "`weapon`='%d',`shield`='%d',`head_top`='%d',`head_mid`='%d',`head_bottom`='%d'," "`last_map`='%s',`last_x`='%d',`last_y`='%d',`save_map`='%s',`save_x`='%d',`save_y`='%d'" " WHERE `account_id`='%d' AND `char_id` = '%d'", @@ -499,7 +499,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){ p->base_exp, p->job_exp, p->zeny, p->max_hp, p->hp, p->max_sp, p->sp, p->status_point, p->skill_point, p->str, p->agi, p->vit, p->int_, p->dex, p->luk, - p->option, p->party_id, p->guild_id, p->pet_id, + p->option, p->party_id, p->guild_id, p->pet_id, p->hom_id, //[orn] add homun_id (homunculus id) p->weapon, p->shield, p->head_top, p->head_mid, p->head_bottom, mapindex_id2name(p->last_point.map), p->last_point.x, p->last_point.y, mapindex_id2name(p->save_point.map), p->save_point.x, p->save_point.y, @@ -956,7 +956,7 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus *p){ sprintf(tmp_sql, "SELECT `option`,`karma`,`manner`,`party_id`,`guild_id`,`pet_id`,`hair`,`hair_color`," "`clothes_color`,`weapon`,`shield`,`head_top`,`head_mid`,`head_bottom`," - "`last_map`,`last_x`,`last_y`,`save_map`,`save_x`,`save_y`, `partner_id`, `father`, `mother`, `child`, `fame`" + "`last_map`,`last_x`,`last_y`,`save_map`,`save_x`,`save_y`, `partner_id`, `father`, `mother`, `child`, `fame`, `homun_id`" //[orn] homun_id "FROM `%s` WHERE `char_id` = '%d'",char_db, char_id); // TBR if (mysql_query(&mysql_handle, tmp_sql)) { ShowSQL("DB error - %s\n",mysql_error(&mysql_handle)); @@ -977,6 +977,7 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus *p){ p->save_point.map = mapindex_name2id(sql_row[17]); p->save_point.x = atoi(sql_row[18]); p->save_point.y = atoi(sql_row[19]); p->partner_id = atoi(sql_row[20]); p->father = atoi(sql_row[21]); p->mother = atoi(sql_row[22]); p->child = atoi(sql_row[23]); p->fame = atoi(sql_row[24]); + p->hom_id = atoi(sql_row[25]); //[orn] homunculus id strcat (t_msg, " status2"); } else @@ -3036,7 +3037,7 @@ int parse_frommap(int fd) { } // no inter server packet. no char server packet -> disconnect - ShowError("Unknown packet 0x%04x from map server, disconnecting.\n", RFIFOW(fd,0)); + ShowError("Unknown packet 0x%04x ( %s ) from map server, disconnecting.\n", RFIFOW(fd,0), (char*)RFIFOP(fd,0)); session[fd]->eof = 1; return 0; } diff --git a/src/char_sql/int_homun.c b/src/char_sql/int_homun.c new file mode 100644 index 000000000..cafa67806 --- /dev/null +++ b/src/char_sql/int_homun.c @@ -0,0 +1,300 @@ +// Homunculus saving by Albator and Orn for eAthena. +// GNU/GPL rulez ! + +#include +#include +#include + +#include "char.h" +#include "../common/strlib.h" +#include "../common/showmsg.h" + +struct s_homunculus *homun_pt; + +#ifndef SQL_DEBUG + +#define mysql_query(_x, _y) mysql_real_query(_x, _y, strlen(_y)) //supports ' in names and runs faster [Kevin] + +#else + +#define mysql_query(_x, _y) debug_mysql_query(__FILE__, __LINE__, _x, _y) + +#endif + + +int inter_homunculus_sql_init(void){ + //memory alloc + homun_pt = (struct s_homunculus*)aCalloc(sizeof(struct s_homunculus), 1); + return 0; +} +void inter_homunculus_sql_final(void){ + if (homun_pt) aFree(homun_pt); + return; +} + +int mapif_saved_homunculus(int fd, short flag) +{ + WFIFOW(fd,0) = 0x3892; + if(flag==1) + WFIFOB(fd,2) = 1; + else + WFIFOB(fd,2) = 0; + WFIFOSET(fd, 3); + return 0; +} +int mapif_info_homunculus(int fd, int account_id, struct s_homunculus *hd) +{ + WFIFOW(fd,0) = 0x3891; + WFIFOW(fd,2) = sizeof(struct s_homunculus)+9; + WFIFOL(fd,4) = account_id; + WFIFOB(fd,8) = 1; // account loaded with success + + memcpy(WFIFOP(fd,9), hd, sizeof(struct s_homunculus)); + WFIFOSET(fd, sizeof(struct s_homunculus)+9); + return 0; +} + +int mapif_homunculus_deleted(int fd, int flag) +{ + WFIFOW(fd, 0) = 0x3893; + if(flag == 1) + WFIFOB(fd,2) = 1; // Homunculus deleted + else + WFIFOB(fd,2) = 0; /* Fail /!\ */ + + WFIFOSET(fd, 3); + + return 0; + +} +int mapif_homunculus_created(int fd, int account_id, struct s_homunculus *sh, short flag) +{ + WFIFOW(fd, 0) =0x3890; + WFIFOL(fd,2) = account_id; + WFIFOL(fd,6) = sh->char_id; + if(flag==1){ + WFIFOW(fd, 10)=1; + WFIFOL(fd,12) = sh->hom_id; + } + else{ + WFIFOW(fd, 10)=0; + WFIFOL(fd,12) = 0; + } + WFIFOSET(fd, 16); + + return 0; +} +void init_homun_skills(struct s_homunculus *hd) +{ + int i; + for(i=0;ihskill[i].id = hd->hskill[i].lv = hd->hskill[i].flag = 0; +} + +// Save/Update Homunculus Skills +int mapif_save_homunculus_skills(struct s_homunculus *hd) +{ + int i; + + for(i=0; ihskill[i].id != 0 && hd->hskill[i].lv != 0 ) + { + sprintf(tmp_sql,"REPLACE INTO `skill_homunculus` (`homun_id`, `id`, `lv`) VALUES (%d, %d, %d)", + hd->hom_id, hd->hskill[i].id, hd->hskill[i].lv); + + if(mysql_query(&mysql_handle, tmp_sql)){ + ShowSQL("DB error - %s\n",mysql_error(&mysql_handle)); + ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); + return 0; + } + } + } + + return 1; +} + +int mapif_save_homunculus(int fd, int account_id, struct s_homunculus *hd) +{ + int flag =1; + + if(hd->hom_id==0) // new homunculus + { + ShowInfo("New homunculus name : %s\n",hd->name); + + sprintf(tmp_sql, "INSERT INTO `homunculus` " + "(`char_id`, `class`,`name`,`level`,`exp`,`intimacy`,`hunger`, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hp`,`max_hp`,`sp`,`max_sp`,`skill_point`, `alive`, `rename_flag`, `vaporize`) " + "VALUES ('%d', '%d', '%s', '%d', '%lu', '%lu', '%d', '%d', %d, '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", + hd->char_id, hd->class_,hd->name,hd->level,hd->exp,hd->intimacy,hd->hunger, hd->str, hd->agi, hd->vit, hd->int_, hd->dex, hd->luk, + hd->hp,hd->max_hp,hd->sp,hd->max_sp, hd->skillpts, hd->alive, hd->rename_flag, hd->vaporize); + + } + else + { + sprintf(tmp_sql, "UPDATE `homunculus` SET `char_id`='%d', `class`='%d',`name`='%s',`level`='%d',`exp`='%lu',`intimacy`='%lu',`hunger`='%d', `agi`='%d', `vit`='%d', `int`='%d', `dex`='%d', `luk`='%d', `hp`='%d',`max_hp`='%d',`sp`='%d',`max_sp`='%d',`skill_point`='%d', `alive`='%d', `rename_flag`='%d', `vaporize`='%d', `str`='%d' WHERE `homun_id`='%d'", + hd->char_id, hd->class_,hd->name,hd->level,hd->exp,hd->intimacy,hd->hunger, hd->str, hd->agi, hd->vit, hd->int_, hd->dex, hd->luk, + hd->hp,hd->max_hp,hd->sp,hd->max_sp, hd->skillpts, hd->alive, hd->rename_flag, hd->vaporize); + } + + if(mysql_query(&mysql_handle, tmp_sql)){ + ShowSQL("DB error - %s\n",mysql_error(&mysql_handle)); + ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); + flag = 0; + } + + if(hd->hom_id==0 && flag!=0) + hd->hom_id = (int)mysql_insert_id(&mysql_handle); // new homunculus + else + { + flag = mapif_save_homunculus_skills(hd); + mapif_saved_homunculus(fd, flag); + } + return flag; +} + + + +// Load an homunculus +int mapif_load_homunculus(int fd){ + int i; + memset(homun_pt, 0, sizeof(struct s_homunculus)); + + sprintf(tmp_sql,"SELECT `homun_id`,`char_id`,`class`,`name`,`level`,`exp`,`intimacy`,`hunger`,, `str`, `agi`, `vit`, `int`, `dex`, `luk`, `hp`,`max_hp`,`sp`,`max_sp`,`skill_point`,`alive`,`rename_flag`, `vaporize` FROM `homunculus` WHERE `homun_id`='%lu'", RFIFOL(fd,6)); + if(mysql_query(&mysql_handle, tmp_sql) ) { + ShowSQL("DB error - %s\n",mysql_error(&mysql_handle)); + ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); + + return 0; + } + sql_res = mysql_store_result(&mysql_handle) ; + if (sql_res!=NULL && mysql_num_rows(sql_res)>0) { + sql_row = mysql_fetch_row(sql_res); + + homun_pt->hom_id = RFIFOL(fd,6) ; //RFIFOL(fd,2); + homun_pt->class_ = atoi(sql_row[2]); + memcpy(homun_pt->name, sql_row[3],NAME_LENGTH-1); + homun_pt->char_id = atoi(sql_row[1]); + homun_pt->level = atoi(sql_row[4]); + homun_pt->exp = atoi(sql_row[5]); + homun_pt->intimacy = atoi(sql_row[6]); + homun_pt->hunger = atoi(sql_row[7]); + homun_pt->str = atoi(sql_row[8]); + homun_pt->agi = atoi(sql_row[9]); + homun_pt->vit = atoi(sql_row[10]); + homun_pt->int_ = atoi(sql_row[11]); + homun_pt->dex = atoi(sql_row[12]); + homun_pt->luk = atoi(sql_row[13]); + homun_pt->hp = atoi(sql_row[14]); + homun_pt->max_hp = atoi(sql_row[15]); + homun_pt->sp = atoi(sql_row[16]); + homun_pt->max_sp = atoi(sql_row[17]); + homun_pt->skillpts = atoi(sql_row[18]); + homun_pt->alive = atoi(sql_row[19]); + homun_pt->rename_flag = atoi(sql_row[20]); + homun_pt->vaporize = atoi(sql_row[21]); + } + if(homun_pt->hunger < 0) + homun_pt->hunger = 0; + else if(homun_pt->hunger > 100) + homun_pt->hunger = 100; + if(homun_pt->intimacy < 0) + homun_pt->intimacy = 0; + else if(homun_pt->intimacy > 100000) + homun_pt->intimacy = 100000; + + mysql_free_result(sql_res); + + // Load Homunculus Skill + init_homun_skills(homun_pt); //bousille homun_pt !!! + + sprintf(tmp_sql,"SELECT `id`,`lv` FROM `skill_homunculus` WHERE `homun_id`=%d",homun_pt->hom_id); + if(mysql_query(&mysql_handle, tmp_sql) ) { + ShowSQL("DB error - %s\n",mysql_error(&mysql_handle)); + ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); + return 0; + } + sql_res = mysql_store_result(&mysql_handle); + if(sql_res){ + while((sql_row = mysql_fetch_row(sql_res))){ + i = (atoi(sql_row[0])-HM_SKILLBASE-1); + homun_pt->hskill[i].id = atoi(sql_row[0]); + homun_pt->hskill[i].lv = atoi(sql_row[1]); + } + } + + mysql_free_result(sql_res); + + ShowInfo("Homunculus loaded (%d - %s).\n", homun_pt->hom_id, homun_pt->name); + return mapif_info_homunculus(fd, RFIFOL(fd,2), homun_pt); +} + + + +int mapif_delete_homunculus(int fd) +{ + sprintf(tmp_sql, "DELETE FROM `homunculus` WHERE `homun_id` = '%lu'", RFIFOL(fd,2)); + if(mysql_query(&mysql_handle, tmp_sql)){ + ShowSQL("DB error - %s\n",mysql_error(&mysql_handle)); + ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); + return mapif_homunculus_deleted(fd, 0); + } + + return mapif_homunculus_deleted(fd, 1); +} + + + +int mapif_parse_CreateHomunculus(int fd) +{ + memset(homun_pt, 0, sizeof(struct s_homunculus)); + + /* Data from packet */ + homun_pt->char_id = RFIFOL(fd,6); + homun_pt->class_ = RFIFOW(fd,10); + homun_pt->max_hp = RFIFOL(fd,12); + homun_pt->max_sp = RFIFOL(fd,16); + memcpy(homun_pt->name, (char*)RFIFOP(fd, 20), NAME_LENGTH-1); + homun_pt->str = RFIFOL(fd,44); + homun_pt->agi = RFIFOL(fd,48); + homun_pt->vit = RFIFOL(fd,52); + homun_pt->int_ = RFIFOL(fd,56); + homun_pt->dex = RFIFOL(fd,60); + homun_pt->luk = RFIFOL(fd,64); + + /* Const data for each creation*/ + homun_pt->hom_id = 0; + homun_pt->exp =0; + homun_pt->hp = 10 ; + homun_pt->sp = 0 ; + homun_pt->rename_flag = 0; + homun_pt->skillpts =0; + homun_pt->hunger = 32; + homun_pt->level=1; + homun_pt->intimacy = 21; + + // Save in sql db + if(mapif_save_homunculus(fd,RFIFOL(fd,2), homun_pt)) + return mapif_homunculus_created(fd, RFIFOL(fd,2), homun_pt, 1); // send homun_id + else + return mapif_homunculus_created(fd, RFIFOL(fd,2), homun_pt, 0); // fail + + +} + + + + +int inter_homunculus_parse_frommap(int fd){ + switch(RFIFOW(fd, 0)){ + case 0x3090: mapif_parse_CreateHomunculus(fd); break; + case 0x3091: mapif_load_homunculus(fd); break; + case 0x3092: mapif_save_homunculus(fd, RFIFOL(fd,6), (struct s_homunculus*) RFIFOP(fd, 10)); break; + case 0x3093: mapif_delete_homunculus(fd); break; // doesn't need to be parse, very simple packet... + // rename homunculus is just like save... Map server check the rename flag before, send the save packet + // case 0x3094: mapif_parse_rename_homunculus(fd); break; + + default: + return 0; + } + return 1; +} diff --git a/src/char_sql/int_homun.h b/src/char_sql/int_homun.h new file mode 100644 index 000000000..e274c9ee1 --- /dev/null +++ b/src/char_sql/int_homun.h @@ -0,0 +1,14 @@ +// Homunculus saving by Albator and Orn for eAthena. +// GNU/GPL rulez ! + +#ifndef _INT_HOMUN_H_ +#define _INT_HOMUN_H_ + +int inter_homunculus_sql_init(void); +void inter_homunculus_sql_final(void); +int mapif_save_homunculus(struct s_homunculus *hd); +int mapif_load_homunculus(int fd); +int mapif_delete_homunculus(int fd); +int inter_homunculus_parse_frommap(int fd); + +#endif diff --git a/src/char_sql/inter.c b/src/char_sql/inter.c index 37c331141..73b049044 100644 --- a/src/char_sql/inter.c +++ b/src/char_sql/inter.c @@ -15,6 +15,7 @@ #include "int_guild.h" #include "int_storage.h" #include "int_pet.h" +#include "int_homun.h" //albator #define WISDATA_TTL (60*1000) // Wisデータの生存時間(60秒) #define WISDELLIST_MAX 256 // Wisデータ削除リストの要素数 @@ -79,6 +80,10 @@ int inter_recv_packet_length[]={ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48,14,-1, 6, 35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3080-0x308f +// 44,10,-1, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x3090 - 0x309f Homunculus packets [albator] + 68,10,-1, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x3090 - 0x309f Homunculus packets [albator] + + }; struct WisData { @@ -362,6 +367,7 @@ int inter_init(const char *file) inter_party_sql_init(); inter_pet_sql_init(); + inter_homunculus_sql_init(); // albator inter_accreg_sql_init(); //printf ("interserver timer initializing : %d sec...\n",autosave_interval); @@ -419,6 +425,7 @@ void inter_final(void) { inter_storage_sql_final(); inter_party_sql_final(); inter_pet_sql_final(); + inter_homunculus_sql_final(); //[orn] if (accreg_pt) aFree(accreg_pt); return; @@ -753,7 +760,7 @@ int inter_parse_frommap(int fd) int cmd=RFIFOW(fd,0); int len=0; - // inter鯖管轄かを調べる + // inter鯖管轄かを調べ if(cmd < 0x3000 || cmd >= 0x3000 + (sizeof(inter_recv_packet_length)/ sizeof(inter_recv_packet_length[0]) ) ) return 0; @@ -781,6 +788,8 @@ int inter_parse_frommap(int fd) break; if(inter_pet_parse_frommap(fd)) break; + if(inter_homunculus_parse_frommap(fd)) //albator + break; return 0; } -- cgit v1.2.3-70-g09d2