diff options
Diffstat (limited to 'src/txt-converter/char')
-rw-r--r-- | src/txt-converter/char/GNUmakefile | 13 | ||||
-rw-r--r-- | src/txt-converter/char/Makefile | 8 | ||||
-rw-r--r-- | src/txt-converter/char/char-converter.c | 177 | ||||
-rw-r--r-- | src/txt-converter/char/char.h | 6 | ||||
-rw-r--r-- | src/txt-converter/char/strlib.c | 66 | ||||
-rw-r--r-- | src/txt-converter/char/strlib.h | 9 |
6 files changed, 97 insertions, 182 deletions
diff --git a/src/txt-converter/char/GNUmakefile b/src/txt-converter/char/GNUmakefile deleted file mode 100644 index 56723ca5a..000000000 --- a/src/txt-converter/char/GNUmakefile +++ /dev/null @@ -1,13 +0,0 @@ -all: char-converter -sql: char-converter - -COMMON_OBJ = ../../common/core.o ../../common/socket.o ../../common/timer.o ../../common/db.o ../../common/malloc.o - -char-converter: char-converter.o strlib.o $(COMMON_OBJ) - $(CC) -o ../../../$@ $^ $(LIB_S) - -char-converter.o: char-converter.c char.h strlib.h -strlib.o: strlib.c strlib.h -clean: - rm -f *.o ../../../char-converter - diff --git a/src/txt-converter/char/Makefile b/src/txt-converter/char/Makefile index 56723ca5a..6b85a04db 100644 --- a/src/txt-converter/char/Makefile +++ b/src/txt-converter/char/Makefile @@ -1,13 +1,13 @@ all: char-converter sql: char-converter -COMMON_OBJ = ../../common/core.o ../../common/socket.o ../../common/timer.o ../../common/db.o ../../common/malloc.o +COMMON_OBJ = ../../common/obj/core.o ../../common/obj/socket.o ../../common/obj/timer.o ../../common/obj/grfio.o ../../common/obj/db.o ../../common/obj/lock.o ../../common/obj/nullpo.o ../../common/obj/malloc.o ../../common/obj/showmsg.o ../../common/obj/strlib.o -char-converter: char-converter.o strlib.o $(COMMON_OBJ) +char-converter: char-converter.o $(COMMON_OBJ) $(CC) -o ../../../$@ $^ $(LIB_S) -char-converter.o: char-converter.c char.h strlib.h -strlib.o: strlib.c strlib.h +char-converter.o: char-converter.c char.h ../../common/strlib.h +strlib.o: strlib.c ../../common/strlib.h clean: rm -f *.o ../../../char-converter diff --git a/src/txt-converter/char/char-converter.c b/src/txt-converter/char/char-converter.c index 8928e240f..217bf2b15 100644 --- a/src/txt-converter/char/char-converter.c +++ b/src/txt-converter/char/char-converter.c @@ -16,16 +16,16 @@ #define STORAGE_MEMINC 16 - + #include "char.h" -#include "strlib.h" +#include "../../common/strlib.h" #ifdef MEMWATCH #include "memwatch.h" #endif - + char pet_txt[256]="save/pet.txt"; -char storage_txt[256]="save/storage.txt"; +char storage_txt[256]="save/storage.txt"; MYSQL mysql_handle; MYSQL_RES* sql_res ; @@ -39,7 +39,7 @@ char db_server_id[32] = "ragnarok"; char db_server_pw[32] = "ragnarok"; char db_server_logindb[32] = "ragnarok"; -struct storage *storage=NULL; +struct storage *storage_=NULL; struct mmo_map_server server[MAX_MAP_SERVERS]; int server_fd[MAX_MAP_SERVERS]; @@ -89,18 +89,18 @@ int inter_pet_fromstr(char *str, struct s_pet *p) int s; int tmp_int[16]; char tmp_str[256]; - + memset(p, 0, sizeof(struct s_pet)); - + // printf("sscanf pet main info\n"); s=sscanf(str,"%d, %d,%[^\t]\t%d, %d, %d, %d, %d, %d, %d, %d, %d", &tmp_int[0], &tmp_int[1], tmp_str, &tmp_int[2], &tmp_int[3], &tmp_int[4], &tmp_int[5], &tmp_int[6], &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10]); if(s!=12) return 1; - + p->pet_id = tmp_int[0]; - p->class = tmp_int[1]; + p->class_ = tmp_int[1]; memcpy(p->name, tmp_str, 24); p->account_id = tmp_int[2]; p->char_id = tmp_int[3]; @@ -126,11 +126,11 @@ int inter_pet_fromstr(char *str, struct s_pet *p) //--------------------------------------------------------- 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`,`incuvate`) - + char tmp_sql[65535]; MYSQL_RES* sql_res ; MYSQL_ROW sql_row ; - + jstrescapecpy (t_name, p->name); if(p->hungry < 0) p->hungry = 0; @@ -148,19 +148,19 @@ int inter_pet_tosql(int pet_id, struct s_pet *p) { sql_row = mysql_fetch_row(sql_res); //row fetching if (!sql_row) //no row -> insert sprintf(tmp_sql,"INSERT INTO `pet` (`pet_id`, `class`,`name`,`account_id`,`char_id`,`level`,`egg_id`,`equip`,`intimate`,`hungry`,`rename_flag`,`incuvate`) VALUES ('%d', '%d', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", - p->pet_id, p->class, t_name, p->account_id, p->char_id, p->level, p->egg_id, + p->pet_id, p->class_, t_name, p->account_id, p->char_id, p->level, p->egg_id, p->equip, p->intimate, p->hungry, p->rename_flag, p->incuvate); else //row reside -> updating sprintf(tmp_sql, "UPDATE `pet` 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',`incuvate`='%d' WHERE `pet_id`='%d'", - p->class, t_name, p->account_id, p->char_id, p->level, p->egg_id, + p->class_, t_name, p->account_id, p->char_id, p->level, p->egg_id, p->equip, p->intimate, p->hungry, p->rename_flag, p->incuvate, p->pet_id); mysql_free_result(sql_res) ; //resource free if(mysql_query(&mysql_handle, tmp_sql) ) { printf("DB server Error - %s\n", mysql_error(&mysql_handle) ); } - + printf ("pet dump success! - %d:%s\n", pet_id, p->name); - + return 0; } @@ -168,27 +168,27 @@ int storage_tosql(int account_id,struct storage *p){ // id -> DB dump // storage {`account_id`/`id`/`nameid`/`amount`/`equip`/`identify`/`refine`/`attribute`/`card0`/`card1`/`card2`/`card3`} int i,j; - + j=0; - + //printf ("starting storage dump to DB - id: %d\n", account_id); - + //delete old data. sprintf(tmp_sql,"DELETE FROM `storage` WHERE `account_id`='%d'",account_id); if(mysql_query(&mysql_handle, tmp_sql) ) { printf("DB server Error - %s\n", mysql_error(&mysql_handle) ); } - + //printf ("all storage item was deleted ok\n"); - + for(i=0;i<MAX_STORAGE;i++) { - //printf ("save storage num: %d (%d:%d)\n",i, p->storage[i].nameid , p->storage[i].amount); - - if( (p->storage[i].nameid) && (p->storage[i].amount) ){ + //printf ("save storage num: %d (%d:%d)\n",i, p->storage_[i].nameid , p->storage_[i].amount); + + if( (p->storage_[i].nameid) && (p->storage_[i].amount) ){ sprintf(tmp_sql,"INSERT INTO `storage` (`account_id`,`nameid`,`amount`,`equip`,`identify`,`refine`,`attribute`,`card0`,`card1`,`card2`,`card3`,`broken`) VALUES ('%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')", - p->account_id, p->storage[i].nameid, p->storage[i].amount, p->storage[i].equip, - p->storage[i].identify, p->storage[i].refine, p->storage[i].attribute, - p->storage[i].card[0], p->storage[i].card[1], p->storage[i].card[2], p->storage[i].card[3], p->storage[i].broken ); + p->account_id, p->storage_[i].nameid, p->storage_[i].amount, p->storage_[i].equip, + p->storage_[i].identify, p->storage_[i].refine, p->storage_[i].attribute, + p->storage_[i].card[0], p->storage_[i].card[1], p->storage_[i].card[2], p->storage_[i].card[3], p->storage_[i].broken ); //printf ("%s\n",tmp_sql); if(mysql_query(&mysql_handle, tmp_sql) ) { printf("DB server Error - %s\n", mysql_error(&mysql_handle) ); @@ -212,51 +212,51 @@ int storage_fromstr(char *str, struct storage *p) if(set!=2) return 0; if(str[next]=='\n' || str[next]=='\r') - return 1; + return 1; next++; for(i=0;str[next] && str[next]!='\t';i++){ if(sscanf(str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n", &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3], &tmp_int[4], &tmp_int[5], &tmp_int[6], &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], &tmp_int[11], &len) == 12) { - p->storage[i].id = tmp_int[0]; - p->storage[i].nameid = tmp_int[1]; - p->storage[i].amount = tmp_int[2]; - p->storage[i].equip = tmp_int[3]; - p->storage[i].identify = tmp_int[4]; - p->storage[i].refine = tmp_int[5]; - p->storage[i].attribute = tmp_int[6]; - p->storage[i].card[0] = tmp_int[7]; - p->storage[i].card[1] = tmp_int[8]; - p->storage[i].card[2] = tmp_int[9]; - p->storage[i].card[3] = tmp_int[10]; - p->storage[i].broken = tmp_int[11]; + p->storage_[i].id = tmp_int[0]; + p->storage_[i].nameid = tmp_int[1]; + p->storage_[i].amount = tmp_int[2]; + p->storage_[i].equip = tmp_int[3]; + p->storage_[i].identify = tmp_int[4]; + p->storage_[i].refine = tmp_int[5]; + p->storage_[i].attribute = tmp_int[6]; + p->storage_[i].card[0] = tmp_int[7]; + p->storage_[i].card[1] = tmp_int[8]; + p->storage_[i].card[2] = tmp_int[9]; + p->storage_[i].card[3] = tmp_int[10]; + p->storage_[i].broken = tmp_int[11]; next += len; if (str[next] == ' ') - next++; + next++; } else if(sscanf(str + next, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d%n", &tmp_int[0], &tmp_int[1], &tmp_int[2], &tmp_int[3], &tmp_int[4], &tmp_int[5], &tmp_int[6], &tmp_int[7], &tmp_int[8], &tmp_int[9], &tmp_int[10], &len) == 11) { - p->storage[i].id = tmp_int[0]; - p->storage[i].nameid = tmp_int[1]; - p->storage[i].amount = tmp_int[2]; - p->storage[i].equip = tmp_int[3]; - p->storage[i].identify = tmp_int[4]; - p->storage[i].refine = tmp_int[5]; - p->storage[i].attribute = tmp_int[6]; - p->storage[i].card[0] = tmp_int[7]; - p->storage[i].card[1] = tmp_int[8]; - p->storage[i].card[2] = tmp_int[9]; - p->storage[i].card[3] = tmp_int[10]; - p->storage[i].broken = 0; + p->storage_[i].id = tmp_int[0]; + p->storage_[i].nameid = tmp_int[1]; + p->storage_[i].amount = tmp_int[2]; + p->storage_[i].equip = tmp_int[3]; + p->storage_[i].identify = tmp_int[4]; + p->storage_[i].refine = tmp_int[5]; + p->storage_[i].attribute = tmp_int[6]; + p->storage_[i].card[0] = tmp_int[7]; + p->storage_[i].card[1] = tmp_int[8]; + p->storage_[i].card[2] = tmp_int[9]; + p->storage_[i].card[3] = tmp_int[10]; + p->storage_[i].broken = 0; next += len; if (str[next] == ' ') - next++; + next++; } - + else return 0; } return 1; @@ -337,7 +337,7 @@ int mmo_char_fromstr(char *str, struct mmo_charstatus *p) { p->char_id = tmp_int[0]; p->account_id = tmp_int[1]; p->char_num = tmp_int[2]; - p->class = tmp_int[3]; + p->class_ = tmp_int[3]; p->base_level = tmp_int[4]; p->job_level = tmp_int[5]; p->base_exp = tmp_int[6]; @@ -508,10 +508,10 @@ int mmo_char_fromstr(char *str, struct mmo_charstatus *p) { //========================================================================================================== int mmo_char_tosql(int char_id, struct mmo_charstatus *p){ int i,save_flag; - + save_flag = char_id; printf("request save char data... (%d)\n",char_id); - + //`char`( `char_id`,`account_id`,`char_num`,`name`,`class`,`base_level`,`job_level`,`base_exp`,`job_exp`,`zeny`, //9 //`str`,`agi`,`vit`,`int`,`dex`,`luk`, //15 //`max_hp`,`hp`,`max_sp`,`sp`,`status_point`,`skill_point`, //21 @@ -525,7 +525,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){ "`option`='%d',`karma`='%d',`manner`='%d',`party_id`='%d',`guild_id`='%d',`pet_id`='%d'," "`hair`='%d',`hair_color`='%d',`clothes_color`='%d',`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', `partner_id` = '%d'", - char_id,p->account_id,p->char_num,p->name,p->class, p->base_level, p->job_level, + char_id,p->account_id,p->char_num,p->name,p->class_, p->base_level, p->job_level, 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, @@ -535,17 +535,17 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){ p->last_point.map, p->last_point.x, p->last_point.y, p->save_point.map, p->save_point.x, p->save_point.y, p->partner_id ); - + if(mysql_query(&mysql_handle, tmp_sql) ) { printf("DB server Error (update `char`)- %s\n", mysql_error(&mysql_handle) ); } - + //`memo` (`memo_id`,`char_id`,`map`,`x`,`y`) sprintf(tmp_sql,"DELETE FROM `memo` WHERE `char_id`='%d'",char_id); if(mysql_query(&mysql_handle, tmp_sql) ) { printf("DB server Error (delete `memo`)- %s\n", mysql_error(&mysql_handle) ); } - + //insert here. for(i=0;i<10;i++){ if(p->memo_point[i].map[0]){ @@ -560,7 +560,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){ if(mysql_query(&mysql_handle, tmp_sql) ) { printf("DB server Error (delete `inventory`)- %s\n", mysql_error(&mysql_handle) ); } - + //insert here. for(i=0;i<MAX_INVENTORY;i++){ if(p->inventory[i].nameid){ @@ -579,7 +579,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){ if(mysql_query(&mysql_handle, tmp_sql) ) { printf("DB server Error (delete `cart_inventory`)- %s\n", mysql_error(&mysql_handle) ); } - + //insert here. for(i=0;i<MAX_CART;i++){ if(p->cart[i].nameid){ @@ -593,14 +593,14 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){ } } } - - + + //`skill` (`char_id`, `id`, `lv`) sprintf(tmp_sql,"DELETE FROM `skill` WHERE `char_id`='%d'",char_id); if(mysql_query(&mysql_handle, tmp_sql) ) { printf("DB server Error (delete `skill`)- %s\n", mysql_error(&mysql_handle) ); } - + //insert here. for(i=0;i<MAX_SKILL;i++){ if(p->skill[i].id){ @@ -618,7 +618,7 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){ if(mysql_query(&mysql_handle, tmp_sql) ) { printf("DB server Error (delete `global_reg_value`)- %s\n", mysql_error(&mysql_handle) ); } - + //insert here. for(i=0;i<p->global_reg_num;i++){ if(p->global_reg[i].value !=0){ @@ -629,10 +629,10 @@ int mmo_char_tosql(int char_id, struct mmo_charstatus *p){ } } } - + printf("saving char is done... (%d)\n",char_id); save_flag = 0; - + return 0; } //========================================================================================================== @@ -645,7 +645,7 @@ int mmo_char_init(void){ char input; FILE *fp; - + //DB connection initialized mysql_init(&mysql_handle); printf("Connect DB server.... (inter server)\n"); @@ -658,7 +658,7 @@ int mmo_char_init(void){ else { printf ("connect success! (inter server)\n"); } - + printf("Warning : Make sure you backup your databases before continuing!\n"); @@ -667,14 +667,14 @@ int mmo_char_init(void){ if(input == 'y' || input == 'Y'){ printf("\nConverting Character Database...\n"); fp=fopen("save/athena.txt","r"); - char_dat=malloc(sizeof(char_dat[0])*256); + char_dat = (struct mmo_charstatus*)malloc(sizeof(char_dat[0])*256); char_max=256; if(fp==NULL) return 0; while(fgets(line, 65535, fp)){ if(char_num>=char_max){ char_max+=256; - char_dat=realloc(char_dat, sizeof(char_dat[0]) *char_max); + char_dat = (struct mmo_charstatus*)realloc(char_dat, sizeof(char_dat[0]) *char_max); } memset(&char_dat[char_num], 0, sizeof(char_dat[0])); ret=mmo_char_fromstr(line, &char_dat[char_num]); @@ -689,8 +689,8 @@ int mmo_char_init(void){ printf("char data convert end\n"); fclose(fp); } - - while(getchar() != '\n'); + + while(getchar() != '\n'); printf("\nDo you wish to convert your Storage Database to SQL? (y/n) : "); input=getchar(); if(input == 'y' || input == 'Y') { @@ -700,25 +700,25 @@ int mmo_char_init(void){ printf("cant't read : %s\n",storage_txt); return 0; } - + while(fgets(line,65535,fp)){ set=sscanf(line,"%d,%d",&tmp_int[0],&tmp_int[1]); if(set==2) { if(i==0){ - storage=malloc(sizeof(struct storage)); + storage_ = (struct storage*)malloc(sizeof(struct storage)); }else{ - storage=realloc(storage,sizeof(struct storage)*(i+1)); + storage_ = (struct storage*)realloc(storage_,sizeof(struct storage)*(i+1)); } - memset(&storage[i],0,sizeof(struct storage)); - storage[i].account_id=tmp_int[0]; - storage_fromstr(line,&storage[i]); - storage_tosql(tmp_int[0],&storage[i]); //to sql. (dump) + memset(&storage_[i],0,sizeof(struct storage)); + storage_[i].account_id=tmp_int[0]; + storage_fromstr(line,&storage_[i]); + storage_tosql(tmp_int[0],&storage_[i]); //to sql. (dump) i++; } } fclose(fp); } - + while(getchar() != '\n'); printf("\nDo you wish to convert your Pet Database to SQL? (y/n) : "); input=getchar(); @@ -726,8 +726,8 @@ int mmo_char_init(void){ printf("\nConverting Pet Database...\n"); if( (fp=fopen(pet_txt,"r")) ==NULL ) return 1; - - p=malloc(sizeof(struct s_pet)); + + p = (struct s_pet*)malloc(sizeof(struct s_pet)); while(fgets(line, sizeof(line), fp)){ if(p==NULL){ printf("int_pet: out of memory!\n"); @@ -789,10 +789,13 @@ int inter_config_read(const char *cfgName) { else if(strcmpi(w1,"db_server_logindb")==0){ strcpy(db_server_logindb, w2); printf ("set db_server_logindb : %s\n",w2); + //support the import command, just like any other config + }else if(strcmpi(w1,"import")==0){ + inter_config_read(w2); } } fclose(fp); - + printf("Reading interserver configuration: Done\n"); return 0; @@ -825,7 +828,7 @@ int char_config_read(const char *cfgName) { } fclose(fp); printf("Reading configuration: Done\n"); - + return 0; } diff --git a/src/txt-converter/char/char.h b/src/txt-converter/char/char.h index b5864b31c..e1d5c90dc 100644 --- a/src/txt-converter/char/char.h +++ b/src/txt-converter/char/char.h @@ -24,9 +24,9 @@ struct mmo_map_server{ char map[MAX_MAP_PER_SERVER][16]; }; -int mapif_sendall(unsigned char *buf,unsigned int len); -int mapif_sendallwos(int fd,unsigned char *buf,unsigned int len); -int mapif_send(int fd,unsigned char *buf,unsigned int len); +int mapif_sendall(char *buf,unsigned int len); +int mapif_sendallwos(int fd,char *buf,unsigned int len); +int mapif_send(int fd,char *buf,unsigned int len); extern int autosave_interval; diff --git a/src/txt-converter/char/strlib.c b/src/txt-converter/char/strlib.c deleted file mode 100644 index 60803c1d1..000000000 --- a/src/txt-converter/char/strlib.c +++ /dev/null @@ -1,66 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "strlib.h" - -//----------------------------------------------- -// string lib. -unsigned char* jstrescape (unsigned char* pt) { - //copy from here - unsigned char * ptr; - int i =0, j=0; - - //copy string to temporary - ptr = malloc(J_MAX_MALLOC_SIZE); - strcpy (ptr,pt); - - while (ptr[i] != '\0') { - switch (ptr[i]) { - case '\'': - pt[j++] = '\\'; - pt[j++] = ptr[i++]; - break; - default: - pt[j++] = ptr[i++]; - } - } - pt[j++] = '\0'; - free (ptr); - return (unsigned char*) &pt[0]; -} - -unsigned char* jstrescapecpy (unsigned char* pt,unsigned char* spt) { - //copy from here - int i =0, j=0; - - while (spt[i] != '\0') { - switch (spt[i]) { - case '\'': - pt[j++] = '\\'; - pt[j++] = spt[i++]; - break; - default: - pt[j++] = spt[i++]; - } - } - pt[j++] = '\0'; - return (unsigned char*) &pt[0]; -} -int jmemescapecpy (unsigned char* pt,unsigned char* spt, int size) { - //copy from here - int i =0, j=0; - - while (i < size) { - switch (spt[i]) { - case '\'': - pt[j++] = '\\'; - pt[j++] = spt[i++]; - break; - default: - pt[j++] = spt[i++]; - } - } - // copy size is 0 ~ (j-1) - return j; -} diff --git a/src/txt-converter/char/strlib.h b/src/txt-converter/char/strlib.h deleted file mode 100644 index 442cfac29..000000000 --- a/src/txt-converter/char/strlib.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _J_STR_H_ -#define _J_STR_H_ -#define J_MAX_MALLOC_SIZE 65535 -//string functions. -//code by Jioh L. Jung -unsigned char* jstrescape (unsigned char* pt); -unsigned char* jstrescapecpy (unsigned char* pt,unsigned char* spt); -int jmemescapecpy (unsigned char* pt,unsigned char* spt, int size); -#endif |