diff options
author | amber <amber@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2004-12-20 01:51:58 +0000 |
---|---|---|
committer | amber <amber@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2004-12-20 01:51:58 +0000 |
commit | b1f3d9f5d13fd499dac9180c2152ded91712dd6b (patch) | |
tree | 8870758c3e43263cd94687cec538e6a894fa4e30 /src | |
parent | f86e02de09df6a70a01061ae4e2fec0e660d748f (diff) | |
download | hercules-b1f3d9f5d13fd499dac9180c2152ded91712dd6b.tar.gz hercules-b1f3d9f5d13fd499dac9180c2152ded91712dd6b.tar.bz2 hercules-b1f3d9f5d13fd499dac9180c2152ded91712dd6b.tar.xz hercules-b1f3d9f5d13fd499dac9180c2152ded91712dd6b.zip |
DFASTCHAR
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/branches/stable@649 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src')
-rw-r--r-- | src/char_sql/char.c | 200 | ||||
-rw-r--r-- | src/char_sql/char.h | 4 | ||||
-rw-r--r-- | src/char_sql/int_guild.c | 98 | ||||
-rw-r--r-- | src/char_sql/int_party.c | 4 | ||||
-rw-r--r-- | src/char_sql/int_pet.c | 5 | ||||
-rw-r--r-- | src/char_sql/int_storage.c | 3 |
6 files changed, 313 insertions, 1 deletions
diff --git a/src/char_sql/char.c b/src/char_sql/char.c index 41d2341f0..e26d92af7 100644 --- a/src/char_sql/char.c +++ b/src/char_sql/char.c @@ -37,11 +37,18 @@ #include "strlib.h" #include "itemdb.h" #include "inter.h" +#ifdef FASTCHAR +#include "db.h" +#endif /* FASTCHAR */ #ifdef MEMWATCH #include "memwatch.h" #endif +#ifdef FASTCHAR +static struct dbt *char_db_; + +#endif /* FASTCHAR */ char char_db[256] = "char"; char cart_db[256] = "cart_inventory"; char inventory_db[256] = "inventory"; @@ -150,6 +157,11 @@ int GM_num = 0; int console = 0; +#ifdef FASTCHAR +#define mysql_query(_x, _y) debug_mysql_query(__FILE__, __LINE__, _x, _y) + + +#endif /* FASTCHAR */ //------------------------------------------------- // Set Character online/offline [Wizputer] //------------------------------------------------- @@ -285,22 +297,55 @@ void insert_friends(int char_id_count){ } } +#ifdef FASTCHAR +int compare_item(struct item *a, struct item *b) { + return ( + (a->id == b->id) && + (a->nameid == b->nameid) && + (a->amount == b->amount) && + (a->equip == b->equip) && + (a->identify == b->identify) && + (a->refine == b->refine) && + (a->attribute == b->attribute) && + (a->card[0] == b->card[0]) && + (a->card[1] == b->card[1]) && + (a->card[2] == b->card[2]) && + (a->card[3] == b->card[3])); +} + +#endif /* FASTCHAR */ //===================================================================================================== int mmo_char_tosql(int char_id, struct mmo_charstatus *p){ int i=0,party_exist,guild_exist; int eqcount=1; int noteqcount=1; +#ifdef FASTCHAR + int diff = 0; +#endif /* FASTCHAR */ char temp_str[1024]; char *tmp_p = tmp_sql; +#ifndef FASTCHAR +#else /* FASTCHAR */ + struct mmo_charstatus *cp; +#endif /* FASTCHAR */ struct itemtemp mapitem; +#ifdef FASTCHAR + +#endif /* FASTCHAR */ if (char_id!=p->char_id) return 0; +#ifdef FASTCHAR + cp = numdb_search(char_db_,char_id); + +#endif /* FASTCHAR */ save_flag = p->char_id; printf("(\033[1;32m%d\033[0m) %s \trequest save char data - ",char_id,char_dat[0].name); +#ifndef FASTCHAR +#endif /* not FASTCHAR */ //for(testcount=1;testcount<50;testcount++){//---------------------------test count-------------------- // printf("test count : %d\n", testcount); // eqcount=1; @@ -310,8 +355,16 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){ //----------------------------------------------------------------------------------------------------- //=========================================map inventory data > memory =============================== +#ifdef FASTCHAR + diff = 0; + +#endif /* FASTCHAR */ //map inventory data for(i=0;i<MAX_INVENTORY;i++){ +#ifdef FASTCHAR + if (!compare_item(&p->inventory[i], &cp->inventory[i])) + diff = 1; +#endif /* FASTCHAR */ if(p->inventory[i].nameid>0){ if(itemdb_isequip(p->inventory[i].nameid)==1){ mapitem.equip[eqcount].flag=0; @@ -345,15 +398,30 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){ } } } +#ifdef FASTCHAR + +#endif /* FASTCHAR */ //printf("- Save item data to MySQL!\n"); +#ifndef FASTCHAR memitemdata_to_sql(mapitem, eqcount, noteqcount, p->char_id,TABLE_INVENTORY); +#else /* FASTCHAR */ + if (diff) + memitemdata_to_sql(mapitem, eqcount, noteqcount, p->char_id,TABLE_INVENTORY); +#endif /* FASTCHAR */ //=========================================map cart data > memory ==================================== eqcount=1; noteqcount=1; +#ifdef FASTCHAR + diff = 0; +#endif /* FASTCHAR */ //map cart data for(i=0;i<MAX_CART;i++){ +#ifdef FASTCHAR + if (!compare_item(&p->cart[i], &cp->cart[i])) + diff = 1; +#endif /* FASTCHAR */ if(p->cart[i].nameid>0){ if(itemdb_isequip(p->cart[i].nameid)==1){ mapitem.equip[eqcount].flag=0; @@ -389,10 +457,34 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){ } //printf("- Save cart data to MySQL!\n"); +#ifndef FASTCHAR memitemdata_to_sql(mapitem, eqcount, noteqcount, p->char_id,TABLE_CART); +#else /* FASTCHAR */ + if (diff) + memitemdata_to_sql(mapitem, eqcount, noteqcount, p->char_id,TABLE_CART); +#endif /* FASTCHAR */ //===================================================================================================== +#ifdef FASTCHAR + if ((p->base_exp != cp->base_exp) || (p->class != cp->class) || + (p->base_level != cp->base_level) || (p->job_level != cp->job_level) || + (p->job_exp != cp->job_exp) || (p->zeny != cp->zeny) || + (p->last_point.x != cp->last_point.x) || (p->last_point.y != cp->last_point.y) || + (p->max_hp != cp->max_hp) || (p->hp != cp->hp) || + (p->max_sp != cp->max_sp) || (p->sp != cp->sp) || + (p->status_point != cp->status_point) || (p->skill_point != cp->skill_point) || + (p->str != cp->str) || (p->agi != cp->agi) || (p->vit != cp->vit) || + (p->int_ != cp->int_) || (p->dex != cp->dex) || (p->luk != cp->luk) || + (p->option != cp->option) || (p->karma != cp->karma) || (p->manner != cp->manner) || + (p->party_id != cp->party_id) || (p->guild_id != cp->guild_id) || + (p->pet_id != cp->pet_id) || (p->hair != cp->hair) || (p->hair_color != cp->hair_color) || + (p->clothes_color != cp->clothes_color) || (p->weapon != cp->weapon) || + (p->shield != cp->shield) || (p->head_top != cp->head_top) || + (p->head_mid != cp->head_mid) || (p->head_bottom != cp->head_bottom) || + (p->partner_id != cp->partner_id)) { + +#endif /* FASTCHAR */ //}//---------------------------test count------------------------------ //check party_exist party_exist=0; @@ -449,6 +541,20 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){ printf("DB server Error (update `char`)- %s\n", mysql_error(&mysql_handle)); } +#ifdef FASTCHAR + } + + diff = 0; + + for(i=0;i<10;i++){ + if((strcmp(p->memo_point[i].map,cp->memo_point[i].map) == 0) && (p->memo_point[i].x == cp->memo_point[i].x) && (p->memo_point[i].y == cp->memo_point[i].y)) + continue; + diff = 1; + break; + } + + if (diff) { +#endif /* FASTCHAR */ //printf("- Save memo data to MySQL!\n"); //`memo` (`memo_id`,`char_id`,`map`,`x`,`y`) sprintf(tmp_sql,"DELETE FROM `%s` WHERE `char_id`='%d'",memo_db, p->char_id); @@ -465,7 +571,21 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){ printf("DB server Error (insert `memo`)- %s\n", mysql_error(&mysql_handle)); } } +#ifdef FASTCHAR + } +#endif /* FASTCHAR */ +#ifdef FASTCHAR + diff = 0; + for(i=0;i<MAX_SKILL;i++) + if((p->skill[i].id != cp->skill[i].id) || (p->skill[i].lv != cp->skill[i].lv) || + (p->skill[i].flag != cp->skill[i].flag)) { + diff = 1; + break; + } + + if (diff) { +#endif /* FASTCHAR */ //printf("- Save skill data to MySQL!\n"); //`skill` (`char_id`, `id`, `lv`) sprintf(tmp_sql,"DELETE FROM `%s` WHERE `char_id`='%d'",skill_db, p->char_id); @@ -477,7 +597,11 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){ for(i=0;i<MAX_SKILL;i++){ if(p->skill[i].id){ if (p->skill[i].id && p->skill[i].flag!=1) { +#ifndef FASTCHAR sprintf(tmp_sql,"INSERT delayed INTO `%s`(`char_id`, `id`, `lv`) VALUES ('%d', '%d','%d')", +#else /* FASTCHAR */ + sprintf(tmp_sql,"INSERT INTO `%s`(`char_id`, `id`, `lv`) VALUES ('%d', '%d','%d')", +#endif /* FASTCHAR */ skill_db, char_id, p->skill[i].id, (p->skill[i].flag==0)?p->skill[i].lv:p->skill[i].flag-2); if(mysql_query(&mysql_handle, tmp_sql)) { printf("DB server Error (insert `skill`)- %s\n", mysql_error(&mysql_handle)); @@ -485,8 +609,27 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){ } } } +#ifdef FASTCHAR + } +#endif /* FASTCHAR */ +#ifndef FASTCHAR +#else /* FASTCHAR */ + diff = 0; + for(i=0;i<p->global_reg_num;i++) { + if ((p->global_reg[i].str == NULL) && (cp->global_reg[i].str == NULL)) + continue; + if (((p->global_reg[i].str == NULL) != (cp->global_reg[i].str == NULL)) || + (p->global_reg[i].value != cp->global_reg[i].value) || + strcmp(p->global_reg[i].str, cp->global_reg[i].str) != 0) { + diff = 1; + break; + } + } + + if (diff) { +#endif /* FASTCHAR */ //printf("- Save global_reg_value data to MySQL!\n"); //`global_reg_value` (`char_id`, `str`, `value`) sprintf(tmp_sql,"DELETE FROM `%s` WHERE `type`=3 AND `char_id`='%d'",reg_db, p->char_id); @@ -506,26 +649,54 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){ } } } +#ifdef FASTCHAR + } +#endif /* FASTCHAR */ // Friends list // account_id, friend_id0, name0, ... tmp_p += sprintf(tmp_p, "REPLACE INTO `%s` (`id`, `account_id`",friend_db); +#ifdef FASTCHAR + diff = 0; + +#endif /* FASTCHAR */ for (i=0;i<20;i++) tmp_p += sprintf(tmp_p, ", `friend_id%d`, `name%d`", i, i); tmp_p += sprintf(tmp_p, ") VALUES (NULL, '%d'", char_id); +#ifndef FASTCHAR for (i=0;i<20;i++) +#else /* FASTCHAR */ + + for (i=0;i<20;i++) { +#endif /* FASTCHAR */ tmp_p += sprintf(tmp_p, ", '%d', '%s'", p->friend_id[i], p->friend_name[i]); +#ifdef FASTCHAR + if ((p->friend_id[i] != cp->friend_id[i]) || + strcmp(p->friend_name[i], cp->friend_name[i])) + diff = 1; + } +#endif /* FASTCHAR */ tmp_p += sprintf(tmp_p, ")"); +#ifndef FASTCHAR mysql_query(&mysql_handle, tmp_sql); +#else /* FASTCHAR */ + + if (diff) + mysql_query(&mysql_handle, tmp_sql); +#endif /* FASTCHAR */ printf("saving char is done.\n"); save_flag = 0; +#ifdef FASTCHAR + memcpy(cp, p, sizeof(struct mmo_charstatus)); + +#endif /* FASTCHAR */ return 0; } @@ -759,12 +930,22 @@ int memitemdata_to_sql(struct itemtemp mapitem, int eqcount, int noteqcount, int // printf("=================================================================================\n"); // } +#ifdef FASTCHAR + +#endif /* FASTCHAR */ return 0; } //===================================================================================================== int mmo_char_fromsql(int char_id, struct mmo_charstatus *p, int online){ int i, n; char *tmp_p = tmp_sql; +#ifdef FASTCHAR + struct mmo_charstatus *cp; + + cp = numdb_search(char_db_,char_id); + if (cp != NULL) + free(cp); +#endif /* FASTCHAR */ memset(p, 0, sizeof(struct mmo_charstatus)); @@ -1006,12 +1187,22 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus *p, int online){ printf("char data load success]\n"); //ok. all data load successfuly! +#ifdef FASTCHAR + cp = (struct mmo_charstatus *) malloc(sizeof(struct mmo_charstatus)); + memcpy(cp, p, sizeof(struct mmo_charstatus)); + numdb_insert(char_db_, char_id,cp); + +#endif /* FASTCHAR */ return 1; } //========================================================================================================== int mmo_char_sql_init(void) { int i; +#ifdef FASTCHAR + char_db_=numdb_init(); + +#endif /* FASTCHAR */ printf("init start.......\n"); // memory initialize // no need to set twice size in this routine. but some cause segmentation error. :P @@ -3205,4 +3396,13 @@ int do_init(int argc, char **argv){ return 0; } +#ifdef FASTCHAR + +#undef mysql_query + +int debug_mysql_query(char *file, int line, void *mysql, const char *q) { + printf("sql: %s:%d# %s\n", file, line, q); + return mysql_query((MYSQL *) mysql, q); +} +#endif /* FASTCHAR */ diff --git a/src/char_sql/char.h b/src/char_sql/char.h index 4b4fdaf04..da2300d38 100644 --- a/src/char_sql/char.h +++ b/src/char_sql/char.h @@ -73,6 +73,10 @@ extern char login_db_account_id[32]; extern int lowest_gm_level; +#ifdef FASTCHAR +extern int debug_mysql_query(char *file, int line, void *mysql, const char *q); + +#endif /* FASTCHAR */ #endif #include "inter.h" diff --git a/src/char_sql/int_guild.c b/src/char_sql/int_guild.c index def93d9f3..5c3480ca6 100644 --- a/src/char_sql/int_guild.c +++ b/src/char_sql/int_guild.c @@ -46,6 +46,9 @@ int mapif_guild_basicinfochanged(int guild_id,int type,const void *data,int len) int mapif_guild_info(int fd,struct guild *g); int guild_break_sub(void *key,void *data,va_list ap); +#ifdef FASTCHAR +#define mysql_query(_x, _y) debug_mysql_query(__FILE__, __LINE__, _x, _y) +#endif /* FASTCHAR */ // Save guild into sql int inter_guild_tosql(struct guild *g,int flag) @@ -65,7 +68,11 @@ int inter_guild_tosql(struct guild *g,int flag) if (g->guild_id<=0) return -1; +#ifndef FASTCHAR printf("(\033[1;35m%d\033[0m) Request save guild - ",g->guild_id); +#else /* FASTCHAR */ + printf("(\033[1;35m%d\033[0m) Request save guild -(flag 0x%x) ",g->guild_id, flag); +#endif /* FASTCHAR */ jstrescapecpy(t_name, g->name); @@ -199,6 +206,7 @@ int inter_guild_tosql(struct guild *g,int flag) } if (flag&2||guild_member==0){ +#ifndef FASTCHAR //printf("- Insert guild %d to guild_member\n",g->guild_id); for(i=0;i<g->max_member;i++){ if (g->member[i].account_id>0){ @@ -226,6 +234,48 @@ int inter_guild_tosql(struct guild *g,int flag) } } } +#else /* FASTCHAR */ + struct StringBuf sbuf; + struct StringBuf sbuf2; + int first = 1; + StringBuf_Init(&sbuf2); + StringBuf_Init(&sbuf); + + StringBuf_Printf(&sbuf,"REPLACE `%s` (`guild_id`,`account_id`,`char_id`,`hair`,`hair_color`,`gender`,`class`,`lv`,`exp`,`exp_payper`,`online`,`position`,`rsv1`,`rsv2`,`name`) VALUES \n", guild_member_db); + + StringBuf_Printf(&sbuf2, "UPDATE `%s` SET `guild_id`='%d' WHERE `char_id` IN (",char_db, g->guild_id); + + //printf("- Insert guild %d to guild_member\n",g->guild_id); + for(i=0;i<g->max_member;i++){ + if (g->member[i].account_id>0){ + struct guild_member *m = &g->member[i]; + if (first == 0) { + StringBuf_Printf(&sbuf , ", "); + StringBuf_Printf(&sbuf2, ", "); + } else + first = 0; + StringBuf_Printf(&sbuf, "('%d','%d','%d','%d','%d', '%d','%d','%d','%d','%d','%d','%d','%d','%d','%s')\n", + g->guild_id, + m->account_id,m->char_id, + m->hair,m->hair_color,m->gender, + m->class,m->lv,m->exp,m->exp_payper,m->online,m->position, + 0,0, + jstrescapecpy(t_member,m->name)); + + StringBuf_Printf(&sbuf2, "'%d'", m->char_id); + } + } + StringBuf_Printf(&sbuf2,")"); + + if(mysql_query(&mysql_handle, StringBuf_Value(&sbuf))) + printf("DB server Error - %s\n", mysql_error(&mysql_handle) ); + + if(mysql_query(&mysql_handle, StringBuf_Value(&sbuf2))) + printf("DB server Error - %s\n", mysql_error(&mysql_handle) ); + + StringBuf_Destroy(&sbuf2); + StringBuf_Destroy(&sbuf); +#endif /* FASTCHAR */ } if (flag&4||guild_member==0){ @@ -520,18 +570,42 @@ struct guild * inter_guild_fromsql(int guild_id) // Save guild_castle to sql int inter_guildcastle_tosql(struct guild_castle *gc) { +#ifdef FASTCHAR + struct guild_castle *gcopy; +#endif /* FASTCHAR */ // `guild_castle` (`castle_id`, `guild_id`, `economy`, `defense`, `triggerE`, `triggerD`, `nextTime`, `payTime`, `createTime`, `visibleC`, `visibleG0`, `visibleG1`, `visibleG2`, `visibleG3`, `visibleG4`, `visibleG5`, `visibleG6`, `visibleG7`) if (gc==NULL) return 0; //printf("Save to guild_castle\n"); +#ifndef FASTCHAR sprintf(tmp_sql,"DELETE FROM `%s` WHERE `castle_id`='%d'",guild_castle_db, gc->castle_id); //printf(" %s\n",tmp_sql); if(mysql_query(&mysql_handle, tmp_sql) ) { printf("DB server Error - %s\n", mysql_error(&mysql_handle) ); return 0; - } +#else /* FASTCHAR */ + + gcopy = numdb_search(castle_db_,gc->castle_id); + if (gcopy == NULL) { + gcopy = (struct guild_castle *) malloc(sizeof(struct guild_castle)); + numdb_insert(castle_db_, gc->castle_id, gcopy); + } else { + if ((gcopy->castle_id == gc->castle_id) && + (strcmp(gcopy->map_name, gc->map_name) == 0) && + (strcmp(gcopy->castle_event, gc->castle_event) == 0) && + (memcmp(&gcopy->guild_id, &gc->guild_id, &gc->GID7 - &gc->guild_id) == 0)) + return 0; +#endif /* FASTCHAR */ + } +#ifndef FASTCHAR sprintf(tmp_sql,"INSERT INTO `%s` " +#else /* FASTCHAR */ + + memcpy(gcopy, gc, sizeof(struct guild_castle)); + + sprintf(tmp_sql,"REPLACE INTO `%s` " +#endif /* FASTCHAR */ "(`castle_id`, `guild_id`, `economy`, `defense`, `triggerE`, `triggerD`, `nextTime`, `payTime`, `createTime`," "`visibleC`, `visibleG0`, `visibleG1`, `visibleG2`, `visibleG3`, `visibleG4`, `visibleG5`, `visibleG6`, `visibleG7`," "`Ghp0`, `Ghp1`, `Ghp2`, `Ghp3`, `Ghp4`, `Ghp5`, `Ghp6`, `Ghp7`)" @@ -564,9 +638,26 @@ int inter_guildcastle_tosql(struct guild_castle *gc) // Read guild_castle from sql int inter_guildcastle_fromsql(int castle_id,struct guild_castle *gc) { +#ifndef FASTCHAR +#else /* FASTCHAR */ + + struct guild_castle *gcopy; +#endif /* FASTCHAR */ if (gc==NULL) return 0; //printf("Read from guild_castle\n"); +#ifdef FASTCHAR + + gcopy = numdb_search(castle_db_,gc->castle_id); + if (gcopy == NULL) { + gcopy = (struct guild_castle *) malloc(sizeof(struct guild_castle)); + numdb_insert(castle_db_, gc->castle_id, gcopy); + } else { + memcpy(gc, gcopy, sizeof(struct guild_castle)); + return 0; + } + +#endif /* FASTCHAR */ memset(gc,0,sizeof(struct guild_castle)); gc->castle_id=castle_id; if (castle_id==-1) return 0; @@ -616,6 +707,11 @@ int inter_guildcastle_fromsql(int castle_id,struct guild_castle *gc) } mysql_free_result(sql_res) ; //resource free +#ifdef FASTCHAR + + memcpy(gcopy, gc, sizeof(struct guild_castle)); + +#endif /* FASTCHAR */ return 0; } diff --git a/src/char_sql/int_party.c b/src/char_sql/int_party.c index 297481453..a03936744 100644 --- a/src/char_sql/int_party.c +++ b/src/char_sql/int_party.c @@ -17,6 +17,10 @@ int mapif_party_broken(int party_id,int flag); int party_check_empty(struct party *p); int mapif_parse_PartyLeave(int fd,int party_id,int account_id); +#ifdef FASTCHAR +#define mysql_query(_x, _y) debug_mysql_query(__FILE__, __LINE__, _x, _y) + +#endif /* FASTCHAR */ // Save party to mysql int inter_party_tosql(int party_id,struct party *p) { diff --git a/src/char_sql/int_pet.c b/src/char_sql/int_pet.c index 14d2144c7..96ab3f6f4 100644 --- a/src/char_sql/int_pet.c +++ b/src/char_sql/int_pet.c @@ -12,6 +12,11 @@ struct s_pet *pet_pt; static int pet_newid = 100; +#ifdef FASTCHAR +#define mysql_query(_x, _y) debug_mysql_query(__FILE__, __LINE__, _x, _y) + + +#endif /* FASTCHAR */ //--------------------------------------------------------- int inter_pet_tosql(int pet_id, struct s_pet *p) { diff --git a/src/char_sql/int_storage.c b/src/char_sql/int_storage.c index 7c8c8ce4a..455ff42c4 100644 --- a/src/char_sql/int_storage.c +++ b/src/char_sql/int_storage.c @@ -13,6 +13,9 @@ struct storage *storage_pt=NULL; struct guild_storage *guild_storage_pt=NULL; +#ifdef FASTCHAR +#define mysql_query(_x, _y) debug_mysql_query(__FILE__, __LINE__, _x, _y) +#endif /* FASTCHAR */ // storage data -> DB conversion int storage_tosql(int account_id,struct storage *p){ |