void countAthena() { int total = 0; std::string input; std::ifstream fp(ATHENA_FILE); char *buffer = new char[65536]; while (fp.good()) { std::getline(fp,input); mmo_charstatus *thisChar = new struct mmo_charstatus; strcpy(buffer,input.c_str()); if (mmo_char_fromstr(buffer, thisChar)) { total++; values.push_back(thisChar->zeny); } delete thisChar; } std::cout << "Parsed a total of " << total << " lines in " << ATHENA_FILE << std::endl << std::endl; delete [] buffer; fp.close(); }
int char_convert(void) { char input, line[65536]; int tmp_int[2], c; FILE *fp; c = 0; printf("\nDo you wish to convert your Character Database to SQL? (y/n) : "); input = getchar(); if(input == 'y' || input == 'Y') { int i, j; struct mmo_chardata cd; printf("\nConverting Character Database...\n"); fp = fopen(char_txt,"r"); if(fp == NULL) { printf("cant't read : %s\n",char_txt); return 1; } while(fgets(line, sizeof(line)-1, fp)) { c++; j = -1; if(sscanf(line,"%d\t%%newid%%%n",&i,&j) == 1 && j > 0 && (line[j] == '\n' || line[j] == '\r')) continue; memset(&cd, 0, sizeof(cd)); if(mmo_char_fromstr(line, &cd) == 0) { int char_id = cd.st.char_id; mmo_char_tosql(char_id , &cd.st); mmo_char_reg_tosql(char_id, cd.reg.global_num, cd.reg.global); mmo_friend_tosql(char_id, &cd.st); } else { printf("mmo_char: broken data [%s] line %d\n", char_txt, c); } } fclose(fp); } while(getchar() != '\n'); c = 0; printf("\nDo you wish to convert your Storage Database to SQL? (y/n) : "); input = getchar(); if(input == 'y' || input == 'Y') { struct storage s; printf("\nConverting Storage Database...\n"); fp = fopen(storage_txt,"r"); if(fp == NULL) { printf("cant't read : %s\n",storage_txt); return 1; } while(fgets(line, sizeof(line)-1, fp)) { c++; memset(&s,0,sizeof(s)); if(sscanf(line,"%d,%d",&tmp_int[0],&tmp_int[1]) == 2) { s.account_id = tmp_int[0]; } if(s.account_id > 0 && storage_fromstr(line,&s) == 0) { char_sql_saveitem(s.store_item,MAX_STORAGE,s.account_id,TABLE_STORAGE); } else { printf("storage: broken data [%s] line %d\n",storage_txt,c); } } fclose(fp); } while(getchar() != '\n'); c = 0; printf("\nDo you wish to convert your Pet Database to SQL? (y/n) : "); input = getchar(); if(input == 'y' || input == 'Y') { struct s_pet p; printf("\nConverting Pet Database...\n"); fp = fopen(pet_txt,"r"); if(fp == NULL) { printf("cant't read : %s\n",pet_txt); return 1; } while(fgets(line, sizeof(line)-1, fp)) { c++; memset(&p, 0, sizeof(p)); if(pet_fromstr(line, &p) == 0 && p.pet_id > 0) { pet_tosql(p.pet_id,&p); } else { printf("pet: broken data [%s] line %d\n", pet_txt, c); } } fclose(fp); } while(getchar() != '\n'); c = 0; printf("\nDo you wish to convert your Party Database to SQL? (y/n) : "); input = getchar(); if(input == 'y' || input == 'Y') { struct party p; printf("\nConverting Party Database...\n"); fp = fopen(party_txt,"r"); if(fp == NULL) { printf("cant't read : %s\n",party_txt); return 1; } while(fgets(line, sizeof(line)-1, fp)) { c++; memset(&p, 0, sizeof(p)); if(party_fromstr(line,&p) == 0 && p.party_id > 0) { party_tosql(&p); } else { printf("party: broken data [%s] line %d\n",party_txt,c); } } fclose(fp); } while(getchar() != '\n'); c = 0; printf("\nDo you wish to convert your Guild Database to SQL? (y/n) : "); input = getchar(); if(input == 'y' || input == 'Y') { struct guild g; printf("\nConverting Guild Database...\n"); fp = fopen(guild_txt,"r"); if(fp == NULL) { printf("cant't read : %s\n",guild_txt); return 1; } while(fgets(line, sizeof(line)-1, fp)) { c++; memset(&g, 0, sizeof(g)); if(guild_fromstr(line,&g) == 0 && g.guild_id > 0) { guild_tosql(&g); } else { printf("guild: broken data [%s] line %d\n",guild_txt,c); } } fclose(fp); } while(getchar() != '\n'); c = 0; printf("\nDo you wish to convert your Guild Castle Database to SQL? (y/n) : "); input = getchar(); if(input == 'y' || input == 'Y') { struct guild_castle gc; printf("\nConverting Guild Castle Database...\n"); fp = fopen(castle_txt,"r"); if(fp == NULL) { printf("cant't read : %s\n",castle_txt); return 1; } while(fgets(line, sizeof(line)-1, fp)) { c++; memset(&gc, 0, sizeof(gc)); if(guildcastle_fromstr(line,&gc) == 0) { guildcastle_tosql(&gc); } else { printf("guildcastle: broken data [%s] line %d\n",castle_txt,c); } } fclose(fp); } while(getchar() != '\n'); c = 0; printf("\nDo you wish to convert your Guild Storage Database to SQL? (y/n) : "); input = getchar(); if(input == 'y' || input == 'Y') { struct guild_storage gs; printf("\nConverting Guild Storage Database...\n"); fp = fopen(guild_storage_txt,"r"); if(fp == NULL) { printf("cant't read : %s\n",guild_storage_txt); return 1; } while(fgets(line, sizeof(line)-1, fp)) { c++; memset(&gs, 0, sizeof(gs)); if(sscanf(line,"%d,%d",&tmp_int[0],&tmp_int[1]) == 2) gs.guild_id = tmp_int[0]; if(gs.guild_id > 0 && gstorage_fromstr(line,&gs) == 0) { char_sql_saveitem(gs.store_item,MAX_GUILD_STORAGE,gs.guild_id,TABLE_GUILD_STORAGE); } else { printf("gstorage: broken data [%s] line %d\n",guild_storage_txt,c); } } fclose(fp); } while(getchar() != '\n'); c = 0; printf("\nDo you wish to convert your Homunculus Database to SQL? (y/n) : "); input = getchar(); if(input == 'y' || input == 'Y') { struct mmo_homunstatus h; printf("\nConverting Homunculus Database...\n"); fp = fopen(homun_txt,"r"); if(fp == NULL) { printf("cant't read : %s\n",homun_txt); return 1; } while(fgets(line, sizeof(line)-1, fp)) { c++; memset(&h, 0, sizeof(h)); if(homun_fromstr(line, &h) == 0 && h.homun_id > 0) { homun_tosql(h.homun_id,&h); } else { printf("homun: broken data [%s] line %d\n", homun_txt, c); } } fclose(fp); } while(getchar() != '\n'); return 0; }
int convert_init(void) { char line[65536]; int ret; int tmp_int[2], lineno, count; char input; FILE *fp; ShowWarning("Make sure you backup your databases before continuing!\n"); ShowMessage("\n"); ShowNotice("Do you wish to convert your Character Database to SQL? (y/n) : "); input = getchar(); if(input == 'y' || input == 'Y') { struct character_data char_dat; struct accreg reg; ShowStatus("Converting Character Database...\n"); if( (fp = fopen(char_txt, "r")) == NULL ) { ShowError("Unable to open file [%s]!\n", char_txt); return 0; } lineno = count = 0; while(fgets(line, sizeof(line), fp)) { lineno++; memset(&char_dat, 0, sizeof(struct character_data)); ret=mmo_char_fromstr(line, &char_dat.status, char_dat.global, &char_dat.global_num); if(ret > 0) { count++; parse_friend_txt(&char_dat.status); //Retrieve friends. mmo_char_tosql(char_dat.status.char_id , &char_dat.status); memset(®, 0, sizeof(reg)); reg.account_id = char_dat.status.account_id; reg.char_id = char_dat.status.char_id; reg.reg_num = char_dat.global_num; memcpy(®.reg, &char_dat.global, reg.reg_num*sizeof(struct global_reg)); inter_accreg_tosql(reg.account_id, reg.char_id, ®, 3); //Type 3: Character regs } else { ShowError("Error %d converting character line [%s] (at %s:%d).\n", ret, line, char_txt, lineno); } } ShowStatus("Converted %d characters.\n", count); fclose(fp); ShowStatus("Converting Account variables Database...\n"); if( (fp = fopen(accreg_txt, "r")) == NULL ) { ShowError("Unable to open file %s!", accreg_txt); return 1; } lineno = count = 0; while(fgets(line, sizeof(line), fp)) { lineno++; memset (®, 0, sizeof(struct accreg)); if(inter_accreg_fromstr(line, ®) == 0 && reg.account_id > 0) { count++; inter_accreg_tosql(reg.account_id, 0, ®, 2); //Type 2: Account regs } else { ShowError("accreg reading: broken data [%s] at %s:%d\n", line, accreg_txt, lineno); } } ShowStatus("Converted %d account registries.\n", count); fclose(fp); } while(getchar() != '\n'); ShowMessage("\n"); ShowNotice("Do you wish to convert your Storage Database to SQL? (y/n) : "); input = getchar(); if(input == 'y' || input == 'Y') { struct storage_data storage; ShowMessage("\n"); ShowStatus("Converting Storage Database...\n"); if( (fp = fopen(storage_txt,"r")) == NULL ) { ShowError("can't read : %s\n", storage_txt); return 0; } lineno = count = 0; while(fgets(line, sizeof(line), fp)) { int account_id; lineno++; if( sscanf(line,"%d,%d",&tmp_int[0],&tmp_int[1]) != 2 ) continue; memset(&storage, 0, sizeof(struct storage_data)); if( storage_fromstr(line,&account_id,&storage) ) { count++; storage_tosql(account_id,&storage); //to sql. (dump) } else ShowError("Error parsing storage line [%s] (at %s:%d)\n", line, storage_txt, lineno); } ShowStatus("Converted %d storages.\n", count); fclose(fp); } //FIXME: CONVERT STATUS DATA HERE!!! while(getchar() != '\n'); ShowMessage("\n"); ShowNotice("Do you wish to convert your Pet Database to SQL? (y/n) : "); input=getchar(); if(input == 'y' || input == 'Y') { struct s_pet p; ShowMessage("\n"); ShowStatus("Converting Pet Database...\n"); if( (fp = fopen(pet_txt, "r")) == NULL ) { ShowError("Unable to open file %s!", pet_txt); return 1; } lineno = count = 0; while(fgets(line, sizeof(line), fp)) { lineno++; memset (&p, 0, sizeof(struct s_pet)); if(inter_pet_fromstr(line, &p)==0 && p.pet_id>0) { count++; inter_pet_tosql(p.pet_id,&p); } else { ShowError("pet reading: broken data [%s] at %s:%d\n", line, pet_txt, lineno); } } ShowStatus("Converted %d pets.\n", count); fclose(fp); } //FIXME: CONVERT HOMUNCULUS DATA AND SKILLS HERE!!! while(getchar() != '\n'); ShowMessage("\n"); ShowNotice("Do you wish to convert your Party Database to SQL? (y/n) : "); input=getchar(); if(input == 'y' || input == 'Y') { struct party p; ShowMessage("\n"); ShowStatus("Converting Party Database...\n"); if( (fp = fopen(party_txt, "r")) == NULL ) { ShowError("Unable to open file %s!", party_txt); return 1; } lineno = count = 0; while(fgets(line, sizeof(line), fp)) { lineno++; memset (&p, 0, sizeof(struct party)); if(inter_party_fromstr(line, &p) == 0 && p.party_id > 0 && inter_party_tosql(&p, PS_CREATE, 0)) count++; else{ ShowError("party reading: broken data [%s] at %s:%d\n", line, pet_txt, lineno); } } ShowStatus("Converted %d parties.\n", count); fclose(fp); } while(getchar() != '\n'); ShowMessage("\n"); ShowNotice("Do you wish to convert your Guilds and Castles Database to SQL? (y/n) : "); input=getchar(); if(input == 'y' || input == 'Y') { struct guild g; struct guild_castle gc; ShowMessage("\n"); ShowStatus("Converting Guild Database...\n"); if( (fp = fopen(guild_txt, "r")) == NULL ) { ShowError("Unable to open file %s!", guild_txt); return 1; } lineno = count = 0; while(fgets(line, sizeof(line), fp)) { lineno++; memset (&g, 0, sizeof(struct guild)); if (inter_guild_fromstr(line, &g) == 0 && g.guild_id > 0 && inter_guild_tosql(&g,GS_MASK)) count++; else ShowError("guild reading: broken data [%s] at %s:%d\n", line, guild_txt, lineno); } ShowStatus("Converted %d guilds.\n", count); fclose(fp); ShowStatus("Converting Guild Castles Database...\n"); if( (fp = fopen(castle_txt, "r")) == NULL ) { ShowError("Unable to open file %s!", castle_txt); return 1; } lineno = count = 0; while(fgets(line, sizeof(line), fp)) { lineno++; memset(&gc, 0, sizeof(struct guild_castle)); if (inter_guildcastle_fromstr(line, &gc) == 0) { inter_guildcastle_tosql(&gc); count++; } else ShowError("guild castle reading: broken data [%s] at %s:%d\n", line, castle_txt, lineno); } ShowStatus("Converted %d guild castles.\n", count); fclose(fp); } while(getchar() != '\n'); ShowMessage("\n"); ShowNotice("Do you wish to convert your Guild Storage Database to SQL? (y/n) : "); input=getchar(); if(input == 'y' || input == 'Y') { struct guild_storage storage_; ShowMessage("\n"); ShowStatus("Converting Guild Storage Database...\n"); if( (fp = fopen(guild_storage_txt, "r")) == NULL ) { ShowError("can't read : %s\n", guild_storage_txt); return 0; } lineno = count = 0; while(fgets(line, sizeof(line), fp)) { lineno++; memset(&storage_, 0, sizeof(struct guild_storage)); if (sscanf(line,"%d",&storage_.guild_id) == 1 && storage_.guild_id > 0 && guild_storage_fromstr(line,&storage_) == 0 ) { count++; guild_storage_tosql(storage_.guild_id, &storage_); } else ShowError("Error parsing guild storage line [%s] (at %s:%d)\n", line, guild_storage_txt, lineno); } ShowStatus("Converted %d guild storages.\n", count); fclose(fp); } return 0; }