summaryrefslogtreecommitdiff
path: root/src/txt-converter/char/char-converter.c
diff options
context:
space:
mode:
author(no author) <(no author)@54d463be-8e91-2dee-dedb-b68131a5f0ec>2005-01-23 20:38:44 +0000
committer(no author) <(no author)@54d463be-8e91-2dee-dedb-b68131a5f0ec>2005-01-23 20:38:44 +0000
commit2c5fabbc0b492cb5456e670ce9eb2352a11d5e3b (patch)
tree89c47d81729687d5a69cadde99ee350306eb814f /src/txt-converter/char/char-converter.c
parentc4e6857d4774b25dcd9b9137f76c14c92015d691 (diff)
downloadhercules-2c5fabbc0b492cb5456e670ce9eb2352a11d5e3b.tar.gz
hercules-2c5fabbc0b492cb5456e670ce9eb2352a11d5e3b.tar.bz2
hercules-2c5fabbc0b492cb5456e670ce9eb2352a11d5e3b.tar.xz
hercules-2c5fabbc0b492cb5456e670ce9eb2352a11d5e3b.zip
update
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/branches/stable@968 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/txt-converter/char/char-converter.c')
-rw-r--r--src/txt-converter/char/char-converter.c106
1 files changed, 53 insertions, 53 deletions
diff --git a/src/txt-converter/char/char-converter.c b/src/txt-converter/char/char-converter.c
index 7b35fda63..1c5028d7e 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 "../../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 ;
@@ -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,22 +168,22 @@ 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) ){
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,
@@ -212,7 +212,7 @@ 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",
@@ -233,7 +233,7 @@ int storage_fromstr(char *str, struct storage *p)
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",
@@ -251,12 +251,12 @@ int storage_fromstr(char *str, struct storage *p)
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].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,14 +700,14 @@ 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];
@@ -718,7 +718,7 @@ int mmo_char_init(void){
}
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");
@@ -792,7 +792,7 @@ int inter_config_read(const char *cfgName) {
}
}
fclose(fp);
-
+
printf("Reading interserver configuration: Done\n");
return 0;
@@ -825,7 +825,7 @@ int char_config_read(const char *cfgName) {
}
fclose(fp);
printf("Reading configuration: Done\n");
-
+
return 0;
}