/*========================================== * 初期化 *------------------------------------------ */ void do_init_storage(void) { storage_db = numdb_init(); guild_storage_db = numdb_init(); return; }
/*========================================== * 初期化とか *------------------------------------------ */ int do_init_storage(void) // map.c::do_init()から呼ばれる { storage_db=numdb_init(); guild_storage_db=numdb_init(); return 1; }
/*========================================== * *------------------------------------------ */ int do_init_itemdb(void) { item_db = numdb_init(); itemdb_read(); return 0; }
// パーティデータのロード int inter_party_init() { char line[8192]; struct party *p; FILE *fp; int c=0; party_db=numdb_init(); if( (fp=fopen(party_txt,"r"))==NULL ) return 1; while(fgets(line,sizeof(line),fp)){ int i,j=0; if( sscanf(line,"%d\t%%newid%%\n%n",&i,&j)==1 && j>0 && party_newid<=i){ party_newid=i; continue; } p=(struct party *)aCalloc(1,sizeof(struct party)); if(inter_party_fromstr(line,p)==0 && p->party_id>0){ if( p->party_id >= party_newid) party_newid=p->party_id+1; numdb_insert(party_db,p->party_id,p); party_check_empty(p); } else{ printf("int_party: broken data [%s] line %d\n",party_txt,c+1); free(p); } c++; } fclose(fp); // printf("int_party: %s read done (%d parties)\n",party_txt,c); return 0; }
// パーティデータのロード int inter_party_init() { char line[8192]; struct party *p; FILE *fp; int c=0; party_db=numdb_init(); if( (fp=fopen(party_txt,"r"))==NULL ) return 1; while(fgets(line,sizeof(line),fp)){ p=malloc(sizeof(struct party)); if(p==NULL){ printf("int_party: out of memory!\n"); exit(0); } if(inter_party_fromstr(line,p)==0 && p->party_id>0){ if( p->party_id >= party_newid) party_newid=p->party_id+1; numdb_insert(party_db,p->party_id,p); party_check_empty(p); } else{ printf("int_party: broken data [%s] line %d\n",party_txt,c); } c++; } fclose(fp); // printf("int_party: %s read done (%d parties)\n",party_txt,c); return 0; }
// initialize int inter_init(const char *file) { //int i; ShowInfo ("interserver initialize...\n"); inter_config_read(file); //DB connection initialized mysql_init(&mysql_handle); ShowInfo("Connect Character DB server.... (Character Server)\n"); if(!mysql_real_connect(&mysql_handle, char_server_ip, char_server_id, char_server_pw, char_server_db ,char_server_port, (char *)NULL, 0)) { //pointer check ShowFatalError("%s\n",mysql_error(&mysql_handle)); exit(1); } else if (inter_sql_test()) { ShowStatus("Connect Success! (Character Server)\n"); } mysql_init(&lmysql_handle); ShowInfo("Connect Character DB server.... (login server)\n"); if(!mysql_real_connect(&lmysql_handle, login_server_ip, login_server_id, login_server_pw, login_server_db ,login_server_port, (char *)NULL, 0)) { //pointer check ShowFatalError("%s\n",mysql_error(&lmysql_handle)); exit(1); }else { ShowStatus ("Connect Success! (Login Server)\n"); } if(strlen(default_codepage) > 0 ) { sprintf( tmp_sql, "SET NAMES %s", default_codepage ); 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); } if (mysql_query(&lmysql_handle, tmp_sql)) { ShowSQL("DB error - %s\n",mysql_error(&lmysql_handle)); ShowDebug("at %s:%d - %s\n", __FILE__,__LINE__,tmp_sql); } } wis_db = numdb_init(); inter_guild_sql_init(); inter_storage_sql_init(); inter_party_sql_init(); inter_pet_sql_init(); inter_accreg_sql_init(); //printf ("interserver timer initializing : %d sec...\n",autosave_interval); //i=add_timer_interval(gettick()+autosave_interval,inter_save_timer,0,0,autosave_interval); return 0; }
/*========================================== * 傭兵データファイルの読み込み *------------------------------------------ */ static bool mercdb_txt_read(void) { FILE *fp; bool ret = true; merc_db = numdb_init(); if((fp = fopen(merc_txt, "r")) == NULL) { printf("mercdb_txt_read: open [%s] failed !\n", merc_txt); ret = false; } else { int count = 0; char line[8192]; while(fgets(line, sizeof(line), fp)) { struct mmo_mercstatus *m = (struct mmo_mercstatus *)aCalloc(1, sizeof(struct mmo_mercstatus)); if(merc_fromstr(line, m) == 0 && m->merc_id > 0) { if(m->merc_id >= merc_newid) merc_newid = m->merc_id + 1; numdb_insert(merc_db, m->merc_id, m); } else { printf("int_merc: broken data [%s] line %d\n", merc_txt, count); aFree(m); } count++; } fclose(fp); } #ifdef TXT_JOURNAL if( merc_journal_enable ) { // ジャーナルデータのロールフォワード if( journal_load( &merc_journal, sizeof(struct mmo_mercstatus), merc_journal_file ) ) { int c = journal_rollforward( &merc_journal, merc_journal_rollforward ); printf("int_merc: journal: roll-forward (%d)\n", c ); // ロールフォワードしたので、txt データを保存する ( journal も新規作成される) mercdb_txt_sync(); } else { // ジャーナルを新規作成する journal_final( &merc_journal ); journal_create( &merc_journal, sizeof(struct mmo_mercstatus), merc_journal_cache, merc_journal_file ); } } #endif return ret; }
/*========================================== * アカウント変数の読み込み *------------------------------------------ */ static bool accregdb_txt_read(void) { FILE *fp; bool ret = true; accreg_db = numdb_init(); if((fp = fopen(accreg_txt, "r")) == NULL) { printf("accregdb_txt_read: open [%s] failed !\n", accreg_txt); ret = false; } else { int count = 0; char line[8192]; while(fgets(line, sizeof(line), fp)) { struct accreg *reg = (struct accreg *)aCalloc(1, sizeof(struct accreg)); if(accregdb_fromstr(line, reg) == 0 && reg->account_id > 0) { numdb_insert(accreg_db, reg->account_id, reg); } else { printf("inter: accreg: broken data [%s] line %d\n", accreg_txt, count); aFree(reg); } count++; } fclose(fp); } #ifdef TXT_JOURNAL if( accreg_journal_enable ) { // ジャーナルデータのロールフォワード if( journal_load( &accreg_journal, sizeof(struct accreg), accreg_journal_file ) ) { int c = journal_rollforward( &accreg_journal, accregdb_journal_rollforward ); printf("inter: accreg_journal: roll-forward (%d)\n", c ); // ロールフォワードしたので、txt データを保存する ( journal も新規作成される) accregdb_txt_sync(); } else { // ジャーナルを新規作成する journal_final( &accreg_journal ); journal_create( &accreg_journal, sizeof(struct accreg), accreg_journal_cache, accreg_journal_file ); } } #endif return ret; }
/*========================================== * map鯖初期化の大元 *------------------------------------------ */ int do_init(int argc,char *argv[]) { srand(gettick()); if(map_config_read((argc<2)? MAP_CONF_NAME:argv[1])) exit(1); battle_config_read((argc>2)? argv[2]:BATTLE_CONF_FILENAME); atcommand_config_read((argc>3)? argv[3]:ATCOMMAND_CONF_FILENAME); script_config_read((argc>4)? argv[4]:SCRIPT_CONF_NAME); msg_config_read((argc>5)? argv[5]:MSG_CONF_NAME); atexit(do_final); id_db = numdb_init(); map_db = strdb_init(16); nick_db = strdb_init(24); charid_db = numdb_init(); grfio_init((argc>6)? argv[6]:GRF_PATH_FILENAME); map_readallmap(); add_timer_func_list(map_clearflooritem_timer,"map_clearflooritem_timer"); do_init_chrif(); do_init_clif(); do_init_itemdb(); do_init_mob(); // npcの初期化時内でmob_spawnして、mob_dbを参照するのでinit_npcより先 do_init_script(); do_init_npc(); do_init_pc(); do_init_storage(); do_init_party(); do_init_guild(); do_init_skill(); do_init_pet(); npc_event_do_oninit(); // npcのOnInitイベント実行 return 0; }
//------------------------------ // Init inter-server for parties //------------------------------ void inter_party_init() { char line[8192]; struct party *p; FILE *fp; int c = 0; int i, j; party_db = numdb_init(); if ((fp = fopen(party_txt, "r")) == NULL) return; while(fgets(line, sizeof(line), fp)) { // fgets reads until maximum one less than size and add '\0' -> so, it's not necessary to add -1 if ((line[0] == '/' && line[1] == '/') || line[0] == '\0' || line[0] == '\n' || line[0] == '\r') continue; // it's not necessary to remove 'carriage return ('\n' or '\r') j = 0; if (sscanf(line, "%d\t%%newid%%\n%n", &i, &j) == 1 && j > 0) { if (party_newid < i) party_newid = i; continue; } CALLOC(p, struct party, 1); if (inter_party_fromstr(line, p) == 0 && p->party_id > 0) { if (p->party_id >= party_newid) party_newid = p->party_id + 1; numdb_insert(party_db, (CPU_INT)p->party_id, p); party_check_empty(p); } else { printf("int_party: broken data [%s] line %d\n", party_txt, c + 1); FREE(p); } c++; } fclose(fp); // printf("int_party: %s read done (%d parties)\n", party_txt, c); return; }
int read_gm_account() { char line[8192]; struct gm_account *p; FILE *fp; int c=0; gm_account_db = numdb_init(); printf("Starting reading gm_account\n"); if( (fp=fopen("conf/GM_account.txt","r"))==NULL ) return 1; while(fgets(line,sizeof(line),fp)) { if(line[0] == '/' || line[1] == '/' || line[2] == '/') continue; p = (struct gm_account*)malloc(sizeof(struct gm_account)); if(p==NULL) { printf("gm_account: out of memory!\n"); exit(0); } if(sscanf(line,"%d %d",&p->account_id,&p->level) != 2 || p->level <= 0) { printf("gm_account: broken data [conf/GM_account.txt] line %d\n",c); continue; } else { if(p->level > 99) p->level = 99; numdb_insert(gm_account_db,p->account_id,p); c++; printf("GM ID: %d Level: %d\n",p->account_id,p->level); } } fclose(fp); printf("%d ID of gm_accounts read.\n",c); return 0; }
// 初期化 void do_init_party(void) { party_db=numdb_init(); add_timer_func_list(party_send_xy_timer,"party_send_xy_timer"); add_timer_interval(gettick()+PARTY_SEND_XY_INVERVAL,party_send_xy_timer,0,0,PARTY_SEND_XY_INVERVAL); }
/*========================================== * 初期化 *------------------------------------------ */ bool mercdb_sql_init(void) { merc_db = numdb_init(); return true; }
/*========================================== * 初期化 *------------------------------------------ */ bool questdb_sql_init(void) { quest_db = numdb_init(); return true; }
/*========================================== * Initializes db. *------------------------------------------ */ void status_init() { scdata_db = numdb_init(); status_load_scdata(scdata_txt); }
//--------------------------------------------------------- // 倉庫データを読み込む int inter_storage_init() { char line[65536]; int c=0,tmp_int; struct storage *s; struct guild_storage *gs; FILE *fp; storage_db = numdb_init(); fp=fopen(storage_txt,"r"); if(fp==NULL){ ShowError("cant't read : %s\n",storage_txt); return 1; } while(fgets(line,65535,fp)){ sscanf(line,"%d",&tmp_int); s = (struct storage*)aCalloc(sizeof(struct storage), 1); if(s==NULL){ ShowFatalError("int_storage: out of memory!\n"); exit(0); } // memset(s,0,sizeof(struct storage)); aCalloc does this... s->account_id=tmp_int; if(s->account_id > 0 && storage_fromstr(line,s) == 0) { numdb_insert(storage_db,s->account_id,s); } else{ ShowError("int_storage: broken data [%s] line %d\n",storage_txt,c); aFree(s); } c++; } fclose(fp); c = 0; guild_storage_db = numdb_init(); fp=fopen(guild_storage_txt,"r"); if(fp==NULL){ ShowError("cant't read : %s\n",guild_storage_txt); return 1; } while(fgets(line,65535,fp)){ sscanf(line,"%d",&tmp_int); gs = (struct guild_storage*)aCalloc(sizeof(struct guild_storage), 1); if(gs==NULL){ ShowFatalError("int_storage: out of memory!\n"); exit(0); } // memset(gs,0,sizeof(struct guild_storage)); aCalloc... gs->guild_id=tmp_int; if(gs->guild_id > 0 && guild_storage_fromstr(line,gs) == 0) { numdb_insert(guild_storage_db,gs->guild_id,gs); } else{ ShowError("int_storage: broken data [%s] line %d\n",guild_storage_txt,c); aFree(gs); } c++; } fclose(fp); return 0; }
/*========================================== * 初期化 *------------------------------------------ */ bool storagedb_sql_init(void) { storage_db = numdb_init(); gstorage_db = numdb_init(); return true; }
/*========================================== * 初期化 *------------------------------------------ */ bool homundb_sql_init(void) { homun_db = numdb_init(); return true; }