int main( int argc , char **argv ) { parseOpts( argc, argv ); // Nuke +1 1012: Loop counter int counter1 = 0; int counter2 = 0; int counter3 = 0; int counter4 = 0; signal(SIGUSR1, sigusr1); log_rotate_interval = 3600 * 24 * 7; Lock_Init(); // Arminius 7.17 memory lock UNlockM_Init(); if(readConfig( "acserv.cf" )<0){ log( "ÎÞ·¨ÔÚµ±Ç°Ä¿Â¼Àï¶ÁÈ¡ acserv.cf .\n" ); exit(1); } #ifdef _SASQL sasql_init(); #endif log( "¶ÁÈ¡Êý¾ÝĿ¼\n" ); dbRead( dbdir ); #ifdef _FAMILY log("¶ÁÈ¡ ¼Ò×åׯ԰\n"); readFMSMemo(fmsmemodir); log("¶ÁÈ¡ ¼Ò×åÁôÑÔ\n"); readFMPoint(fmpointdir); log("¶ÁÈ¡ ¼Ò×åĿ¼\n"); readFamily(familydir); #endif log( "×¼±¸ µµ°¸Ä¿Â¼\n" ); prepareDirectories( chardir ); log( "×¼±¸ ÈÕ־Ŀ¼\n" ); prepareDirectories( logdir ); log( "×¼±¸ ÓʼþĿ¼\n" ); prepareDirectories( maildir ); #ifdef _SLEEP_CHAR prepareDirectories( sleepchardir ); log( "×¼±¸ ˯Ãßµµ°¸Ä¿Â¼\n" ); #endif /* Ð×ÒýÔÈ»¯Ô¶ª¡õ»ïë Ðijð¸ê */ if( readMail(maildir) < 0 ){ log( "²»Äܳõʼ»¯Óʼþ\n" ); exit(1); } /* TCPSTRUCT ëâÙÓå¼À */ { int tcpr; if( ( tcpr = tcpstruct_init( NULL , port , 0 , CHARDATASIZE * 16 * MAXCONNECTION , 1 /* DEBUG */ ) ) < 0 ){ log( "²»ÄÜ¿ªÆôTCP: %d\n", tcpr ); return 1; } } saacproto_InitServer( netWrite , CHARDATASIZE ); { struct sigaction s,os; bzero( &s, sizeof(s)); s.sa_handler = sighandle; s.sa_flags = SA_NOMASK; sigaction( SIGTERM, &s, &os ); bzero( &s, sizeof(s)); s.sa_handler = sighandle; s.sa_flags = SA_NOMASK; sigaction( SIGINT, &s, &os ); bzero( &s, sizeof( s )); s.sa_handler = SIG_IGN; s.sa_flags = SA_NOMASK; sigaction( SIGPIPE, &s, &os ); } #ifdef _AC_SEND_FM_PK // WON ADD ׯ԰¶ÔÕ½ÁÐ±í´¢´æÔÚAC load_fm_pk_list(); #endif #ifdef _ACFMPK_LIST FMPK_LoadList(); #endif #ifdef _ALLDOMAN LOAD_herolist(); // Syu ADD ÅÅÐаñNPC #endif #ifdef _ANGEL_SUMMON initMissionTable(); #endif #ifdef _VIP log( "\n·þÎñ¶Ë°æ±¾: <%s »áÔ±°æ>\n" , SERVER_VERSION ); #else log( "\n·þÎñ¶Ë°æ±¾: <%s ÆÕͨ°æ>\n" , SERVER_VERSION ); #endif log( "\n·þÎñ¶Ë±àÒëÍê³Éʱ¼ä:%s %s by 17CSA¹¤×÷ÊÒ\n" , __DATE__ , __TIME__ ); log( "\n¿ªÊ¼¹¤×÷...\n" ); signal(SIGUSR1,sigusr1); // Arminius 7.20 memory lock int itime=0; while(1){ itime++; if(itime>cpuuse){ itime=0; usleep(1); } int newti,i; static time_t main_loop_time; sys_time = time(NULL); if( main_loop_time != sys_time){ main_loop_time = time(NULL); counter1++; counter2++; counter3++; counter4++; //andy add 2002/06/20 UNlockM_UnlockPlayer(); #ifdef _ANGEL_SUMMON checkMissionTimelimit(); #endif // Nuke *1 1012 if( counter1 > Total_Charlist ){ counter1=0; char *c = ctime( &main_loop_time ); if( c ){ struct timeval st,et; log( "\nTIME:%s\n",c ); gettimeofday( &st,NULL); dbFlush(dbdir); gettimeofday( &et,NULL); log( "Flushed db(%fsec)\n", time_diff(et,st) ); log( "µµ°¸±íÁÐ×ÜÊý:%d NG:%d\n", total_ok_charlist, total_ng_charlist ); } } // Nuke **1 1012 //if( ( counter % 600 ) == 0 ){ if( counter2 > Expired_mail ){ counter2=0; struct timeval st,et; gettimeofday( &st,NULL); expireMail(); gettimeofday( &et,NULL); log( "¹ýÆÚÓʼþ(%fsec)\n", time_diff(et,st) ); } #ifdef _FAMILY //if ((counter % 300) == 0) // 300( -> 60) if( counter4 > Write_Family ) // 300( -> 60) { counter4=0; struct timeval st, et; gettimeofday(&st, NULL); writeFamily(familydir); writeFMPoint(fmpointdir); writeFMSMemo(fmsmemodir); gettimeofday(&et, NULL); log("¼Ç¼¼Ò×å(%fsec)\n", time_diff(et, st)); } #endif } newti = tcpstruct_accept1(); if( newti >= 0 ){ log( "ͬÒâ: %d\n" , newti ); gs[newti].use = 1; } for(i=0;i<MAXCONNECTION;i++){ // char buf[CHARDATASIZE * 16; char buf[CHARDATASIZE]; int l; l = tcpstruct_readline_chop( i , buf , sizeof( buf )- 1); { if( !gs[i].use )continue; if( l > 0 ){ char debugfun[256]; buf[l]=0; if( saacproto_ServerDispatchMessage( i , buf, debugfun)<0){ // Nuke start //tcpstruct_close(i);// avoid the shutdown the gmsv ttom log( "GMSV(%s) ÏûÏ¢:%s\n", gs[i].name, debugfun); FILE *fp; if( (fp=fopen( "badgmsv.txt", "a+")) != NULL ){ fprintf( fp, "GMSV(%s) ÏûÏ¢:%s\n", gs[i].name, debugfun); fclose( fp); } } } else if( l == TCPSTRUCT_ETOOLONG ){ log( "ºÜ³¤:%d ·þÎñÆ÷Ãû::%s\n", i , gs[i].name ); FILE *fp; if( (fp=fopen( "badgmsv.txt", "a+")) != NULL ){ fprintf( fp, "ºÜ³¤:%d ·þÎñÆ÷Ãû::%s\n", i , gs[i].name); fclose( fp); } logout_game_server( i ); } else if( l < 0 ){ log( "¹Ø±Õ:%d ·þÎñÆ÷Ãû:%s\n", i , gs[i].name ); FILE *fp; if( (fp=fopen( "badgmsv.txt", "a+")) != NULL ){ fprintf( fp, "¹Ø±Õ:%d ·þÎñÆ÷Ãû:%s\n", i , gs[i].name); fclose( fp); } logout_game_server(i); } else if( l == 0 ){ ; } } } { static struct timeval tv_loop_store ; struct timeval now; double dif; gettimeofday( &now , NULL ); dif = time_diff( now, tv_loop_store ); if( dif > 0.5 ){ // CoolFish 0.1 -> 0.5 2001/5/19 //log( "Sl:%f" , dif ); } tv_loop_store = now; } /* ·¥¡õÊСõ¼°ÕýÄÌةʧËüÐþëƩÍÍÔÂ£Û ÕýÄÌةʧËüÐþØÆÐ×ÈÕ·òºëë·ÖØÆ»¯·¥¡õÊСõëڽØÆ»¯ØÆÒýµ¤£Û Æ¥±Ø¡õØ©ÈÓ¡õÌï¡õ±å ±Î¶Á±å·´É§ôÅÔÊÔ */ } return 0; }
int main( int argc , char **argv ) { parseOpts( argc, argv ); // Nuke +1 1012: Loop counter int counter1 = 0; int counter2 = 0; int counter3 = 0; int counter4 = 0; signal(SIGUSR1, sigusr1); log_rotate_interval = 3600 * 24 * 7; Lock_Init(); // Arminius 7.17 memory lock UNlockM_Init(); if(readConfig( "acserv.cf" )<0){ log( "���ڵ�ǰĿ¼���ȡ acserv.cf .\n" ); exit(1); } #ifdef _SASQL sasql_init(); #endif log( "��ȡ����Ŀ¼\n" ); dbRead( dbdir ); #ifdef _FAMILY log("��ȡ ����ׯ\n"); readFMSMemo(fmsmemodir); log("��ȡ ��������\n"); readFMPoint(fmpointdir); log("��ȡ ����Ŀ¼\n"); readFamily(familydir); #endif log( "�� ����Ŀ¼\n" ); prepareDirectories( chardir ); log( "�� ��־Ŀ¼\n" ); prepareDirectories( logdir ); log( "�� �ʼ�Ŀ¼\n" ); prepareDirectories( maildir ); #ifdef _SLEEP_CHAR prepareDirectories( sleepchardir ); log( "�� ˯�ߵ���Ŀ¼\n" ); #endif /* �����Ȼ��¶�����ë �ij�� */ if( readMail(maildir) < 0 ){ log( "���ܳ�ʼ���ʼ�\n" ); exit(1); } /* TCPSTRUCT ë����� */ { int tcpr; if( ( tcpr = tcpstruct_init( NULL , port , 0 , CHARDATASIZE * 16 * MAXCONNECTION , 1 /* DEBUG */ ) ) < 0 ){ log( "���ܿ���TCP: %d\n", tcpr ); return 1; } } saacproto_InitServer( netWrite , CHARDATASIZE ); { struct sigaction s,os; bzero( &s, sizeof(s)); s.sa_handler = sighandle; s.sa_flags = SA_NOMASK; sigaction( SIGTERM, &s, &os ); bzero( &s, sizeof(s)); s.sa_handler = sighandle; s.sa_flags = SA_NOMASK; sigaction( SIGINT, &s, &os ); bzero( &s, sizeof( s )); s.sa_handler = SIG_IGN; s.sa_flags = SA_NOMASK; sigaction( SIGPIPE, &s, &os ); } #ifdef _AC_SEND_FM_PK // WON ADD ׯ��ս�б�����AC load_fm_pk_list(); #endif #ifdef _ACFMPK_LIST FMPK_LoadList(); #endif #ifdef _ALLDOMAN LOAD_herolist(); // Syu ADD ���а�NPC #endif #ifdef _VIP log( "\n����˰汾: <%s ��Ա��>\n" , SERVER_VERSION ); #else log( "\n����˰汾: <%s ��ͨ��>\n" , SERVER_VERSION ); #endif log( "\n����˱������ʱ��:%s %s by ��zoro������\n" , __DATE__ , __TIME__ ); log( "\n��ʼ����...\n" ); signal(SIGUSR1,sigusr1); // Arminius 7.20 memory lock int itime=0; while(1){ itime++; if(itime>cpuuse){ itime=0; usleep(1); } int newti,i; static time_t main_loop_time; sys_time = time(NULL); if( main_loop_time != sys_time){ main_loop_time = time(NULL); counter1++; counter2++; counter3++; counter4++; //andy add 2002/06/20 UNlockM_UnlockPlayer(); #ifdef _ANGEL_SUMMON checkMissionTimelimit(); #endif // Nuke *1 1012 if( counter1 > Total_Charlist ){ counter1=0; char *c = ctime( &main_loop_time ); if( c ){ struct timeval st,et; log( "\nTIME:%s\n",c ); gettimeofday( &st,NULL); dbFlush(dbdir); gettimeofday( &et,NULL); log( "Flushed db(%fsec)\n", time_diff(et,st) ); log( "������������:%d NG:%d\n", total_ok_charlist, total_ng_charlist ); } } // Nuke **1 1012 //if( ( counter % 600 ) == 0 ){ if( counter2 > Expired_mail ){ counter2=0; struct timeval st,et; gettimeofday( &st,NULL); expireMail(); gettimeofday( &et,NULL); log( "�����ʼ�(%fsec)\n", time_diff(et,st) ); } #ifdef _FAMILY //if ((counter % 300) == 0) // 300( -> 60) if( counter4 > Write_Family ) // 300( -> 60) { counter4=0; struct timeval st, et; gettimeofday(&st, NULL); writeFamily(familydir); writeFMPoint(fmpointdir); writeFMSMemo(fmsmemodir); gettimeofday(&et, NULL); log("��¼����(%fsec)\n", time_diff(et, st)); } #endif } newti = tcpstruct_accept1(); if( newti >= 0 ){ log( "ͬ��: %d\n" , newti ); gs[newti].use = 1; } for(i=0;i<MAXCONNECTION;i++){ // char buf[CHARDATASIZE * 16; char buf[CHARDATASIZE]; int l; l = tcpstruct_readline_chop( i , buf , sizeof( buf )- 1); { if( !gs[i].use )continue; if( l > 0 ){ char debugfun[256]; buf[l]=0; if( saacproto_ServerDispatchMessage( i , buf, debugfun)<0){ // Nuke start tcpstruct_close(i);// avoid the shutdown the gmsv ttom log( "GMSV(%s) ��Ϣ:%s\n", gs[i].name, debugfun); } } else if( l == TCPSTRUCT_ETOOLONG ){ log( "�ܳ�:%d ��������::%s\n", i , gs[i].name ); logout_game_server( i ); } else if( l < 0 ){ log( "�ر�:%d ��������:%s\n", i , gs[i].name ); logout_game_server(i); } else if( l == 0 ){ ; } } } { static struct timeval tv_loop_store ; struct timeval now; double dif; gettimeofday( &now , NULL ); dif = time_diff( now, tv_loop_store ); if( dif > 0.5 ){ // CoolFish 0.1 -> 0.5 2001/5/19 //log( "Sl:%f" , dif ); } tv_loop_store = now; } /* �����С�������ةʧ����ëƩ���£� ����ةʧ���������շ��ë���ƻ������С�ëڽ�ƻ��������� ƥ�ء�ة�ӡ������ �ζ��巴ɧ������ */ } return 0; }
void cmdExecuteFlush() { dbFlush(); return; }
int IndexDbLevelDb::finalize(void) { { leveldb::WriteBatch wb_common; leveldb::DB* db_common; int rv = dbTryOpen(db_common, m_commonDbDir); if(rv < 0) { printf("ERROR: finalize: common db open: %s\n", m_commonDbDir.c_str()); return -1; } addFilesToFileList(db_common); dbFlush(db_common, &wb_common); dbClose(db_common); } // update UsrDb { leveldb::DB* dbUsrDb = NULL; leveldb::WriteBatch wb_usrdb; string curDir = m_dbDir + "/usr_db"; if(makeDirectory(curDir.c_str())) { return -1; } map<string, SiMap> refUsrFidMap; // store the file IDs a USR found for(const auto& itr : m_usr2referenceFileMap) { const string& usr = itr.first; SiMap& fidMap = refUsrFidMap[usr]; for(const auto& itr_file_list : itr.second) { fidMap[m_fileContextMap[itr_file_list].m_dbId] = 0; } } map<string, SiMap> defUsrFidMap; for(const auto& itr : m_usr2defineFileMap) { const string& usr = itr.first; SiMap& fidMap = defUsrFidMap[usr]; for(const auto& itr_file_list : itr.second) { fidMap[m_fileContextMap[itr_file_list].m_dbId] = 0; } } map<string, SiMap> overriderUsrFidMap; for(const auto& itr : m_usr2overriderFileMap) { const string& usr = itr.first; SiMap& fidMap = overriderUsrFidMap[usr]; for(const auto& itr_file_list : itr.second) { fidMap[m_fileContextMap[itr_file_list].m_dbId] = 0; } } char* errp = NULL; int cuId = strtol(m_compileUnitId.c_str(), &errp, 16); assert(*errp == '\0'); snprintf(m_CharBuff0, sizeof(m_CharBuff0), "%x", (cuId % USR_DB_NUM)); curDir.append(string("/") + string(m_CharBuff0)); timerStart(TIMER_USR_DB0); ////// // open db int rv = dbTryOpen(dbUsrDb, curDir); if(rv < 0) { printf("ERROR: finalize: common db open: %s\n", curDir.c_str()); return -1; } #ifdef USE_USR2FILE_TABLE2 writeUsrDb(refUsrFidMap, dbUsrDb, wb_usrdb, TABLE_NAME_USR_TO_GLOBAL_FILE_ID_REF); writeUsrDb(defUsrFidMap, dbUsrDb, wb_usrdb, TABLE_NAME_USR_TO_GLOBAL_FILE_ID_DEF2); writeUsrDb(overriderUsrFidMap, dbUsrDb, wb_usrdb, TABLE_NAME_USR_TO_GLOBAL_FILE_ID_OVERRIDER); #else writeUsrDb(refUsrFidMap, dbUsrDb, wb_usrdb, TABLE_NAME_USR_TO_GLOBAL_FILE_ID_REF); writeUsrDb(defUsrFidMap, dbUsrDb, wb_usrdb, TABLE_NAME_USR_TO_GLOBAL_FILE_ID_DEF); writeUsrDb(overriderUsrFidMap, dbUsrDb, wb_usrdb, TABLE_NAME_USR_TO_GLOBAL_FILE_ID_OVERRIDER); #endif dbFlush(dbUsrDb, &wb_usrdb); dbClose(dbUsrDb); timerStop(TIMER_USR_DB0); // close db ////// #ifdef TIMER printf("---- Statistics ----\n"); timerShow("time: TIMER_USR_DB0: ", TIMER_USR_DB0); timerShow("time: TIMER_USR_DB3: ", TIMER_USR_DB3); timerShow("time: TIMER_INS_REF: ", TIMER_INS_REF); timerShow("time: TIMER_INS_REF_1: ", TIMER_INS_REF_1); timerShow("time: TIMER_INS_REF_2: ", TIMER_INS_REF_2); timerShow("time: TIMER_INS_DECL: ", TIMER_INS_DECL); timerShow("time: TIMER_DB_SLEEP: ", TIMER_DB_SLEEP); #endif } #ifdef TIMER timerStart(TIMER_DB_WRITE); #endif { string valFiles; leveldb::WriteBatch wb; for(const auto &itr : m_fileContextMap) { //const string& filename = itr->first; const string& dbId = itr.second.m_dbId; valFiles += "," + dbId; } for(const auto &fctxItr : m_fileContextMap) { const string& filename = fctxItr.first; const FileContext& fctx = fctxItr.second; const string& dbId = fctx.m_dbId; // check if already exists if(m_finishedFiles.find(filename) != m_finishedFiles.end()) { continue; } // position to usr for(const auto& itr : fctx.m_positition2usrList) { setKeyValuePos2Usr(m_CharBuff0, m_CharBuff1, sizeof(m_CharBuff0), itr.first, itr.second); wb.Put(dbId + m_CharBuff0, m_CharBuff1); } // decl for(const auto& itr : fctx.m_declList) { wb.Put(dbId + itr.first, itr.second); } // override for(const auto& itr : fctx.m_usrId2overrideeMap) { #if (USE_BASE64 != 0) char* p = m_CharBuff0; p = encodeVal(p, itr.first); *p = '\0'; #else snprintf(m_CharBuff0, sizeof(m_CharBuff0), "%x", itr.first); #endif // overridee -> overrider wb.Put(dbId + TABLE_NAME_LOCAL_USR_ID_TO_OVERRIDER "|" + m_CharBuff0, itr.second); } for(const auto& itr : fctx.m_usrId2overriderMap) { const IiMap& usrMap = itr.second; #if (USE_BASE64 != 0) char* p = m_CharBuff0; p = encodeVal(p, itr.first); *p = '\0'; #else snprintf(m_CharBuff0, sizeof(m_CharBuff0), "%x", itr.first); #endif string val = ""; for(const auto& itr_usr : usrMap) { #if (USE_BASE64 != 0) char* p = m_CharBuff1; p = encodeVal(p, itr_usr.first); *p = '\0'; #else snprintf(m_CharBuff1, sizeof(m_CharBuff1), "%x", itr_usr.first); #endif if(val.empty()) { val = m_CharBuff1; } else { val.append(string(",") + m_CharBuff1); } } // overrider -> overridee wb.Put(dbId + TABLE_NAME_LOCAL_USR_ID_TO_OVERRIDEE "|" + m_CharBuff0, val); } // usr const SiMap& mapRef = fctx.m_usrIdTbl.GetTbl(); addIdList(&wb, mapRef, dbId + TABLE_NAME_LOCAL_USR_ID_TO_USR); for(const auto& itr : mapRef) { string key(dbId + TABLE_NAME_USR_TO_LOCAL_ID "|"); key.append(itr.first); #if (USE_BASE64 != 0) char* p = m_CharBuff1; p = encodeVal(p, itr.second); *p = '\0'; #else snprintf(m_CharBuff1, sizeof(m_CharBuff1), "%x", itr.second); #endif wb.Put(key, m_CharBuff1); } for(auto& itr : fctx.m_usrId2refMap) { int usrId = itr.first; #if (USE_BASE64 != 0) string key(dbId + TABLE_NAME_LOCAL_USR_ID_TO_REF "|"); char* p = m_CharBuff0; p = encodeVal(p, usrId); *p = '\0'; key.append(m_CharBuff0); #else snprintf(m_CharBuff0, sizeof(m_CharBuff0), "%x", usrId); string key(dbId + TABLE_NAME_LOCAL_USR_ID_TO_REF "|" + m_CharBuff0); #endif wb.Put(key, itr.second); } // inclusion for(auto& itr : fctx.m_line2inclusionfMap) { #if (USE_BASE64 != 0) string key(dbId + TABLE_NAME_LINE_TO_INCLUSION "|"); char* p = m_CharBuff0; p = encodeVal(p, itr.first); *p = '\0'; key.append(m_CharBuff0); #else // TODO: implement hex version //snprintf(m_CharBuff0, sizeof(m_CharBuff0), "%x", usrId); //string key(dbId + TABLE_NAME_LOCAL_USR_ID_TO_REF "|" + m_CharBuff0); #endif wb.Put(key, itr.second); } const SiMap& nameMap = fctx.m_nameIdTbl.GetTbl(); addIdList(&wb, nameMap, dbId + TABLE_NAME_TOKEN_ID_TO_NAME); wb.Put(dbId + TABLE_NAME_CUFILES, valFiles); wb.Put(dbId + TABLE_NAME_BUILD_INFO, m_compileUnit + "|" + filename + "|" + m_buildOpt); } // decide db directory char* errp = NULL; //int id = strtol(dbId.c_str(), &errp, 16); int id = strtol(m_compileUnitId.c_str(), &errp, 16); int idRem = id % DB_NUM; leveldb::DB* db; snprintf(m_CharBuff0, sizeof(m_CharBuff0), "%x", idRem); string dbDir = string(m_CharBuff0); int rv = dbTryOpen(db, m_dbDir + "/" + dbDir); if(rv < 0) { printf("ERROR: finalize: open: %s\n", m_commonDbDir.c_str()); return -1; } dbFlush(db, &wb); dbClose(db); } #ifdef TIMER timerStop(TIMER_DB_WRITE); timerShow("time: TIMER_DB_WRITE: ", TIMER_DB_WRITE); #endif delete m_defaultOptions.block_cache; return 0; }