Ejemplo n.º 1
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 _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;       
}
Ejemplo n.º 2
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;       
}