⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 石器时代8.0服务端完整源代码。可以直接编译
💻 C
📖 第 1 页 / 共 4 页
字号:
        log( "服务器密码正确 %s\n" , svname );    } else {        log( "服务器密码错误 %s\n" , svname );        snprintf( result , resultlen , FAILED );        snprintf( retdata , retdatalen , "bad passwd" );        return 0;    }    {        int i;        for(i=0;i<MAXCONNECTION;i++){            if( gs[i].use &&                strcmp( gs[i].name , svname ) == 0 ){                snprintf( result, resultlen, FAILED );                snprintf( retdata , retdatalen, "duplicate login" );                return 0;            }         }    }    snprintf( gs[ti].name , sizeof(gs[ti].name), "%s" , svname );	gs[ti].fd = ti;    snprintf( result , resultlen ,SUCCESSFUL );    snprintf( retdata , retdatalen , "Nothing special" );    DeleteMemLockServer(svname);	// Arminius 7.31 unlock server    return 0;}int logout_game_server( int ti ){    gs[ti].use = 0;	gs[ti].fd = -1;    gs[ti].name[0] = 0;    tcpstruct_close( ti );    return 0;}int is_game_server_login( int ti ){    return gs[ti].use;}static int readConfig( char *path ){    char buf[2048];    FILE *fp;    fp = fopen( path , "r" );    if( fp == NULL ){ return -2; }    while( fgets( buf , sizeof( buf ) , fp )){        char command[1024];        char param[2048];        chop(buf);                easyGetTokenFromString( buf , 1 , command , sizeof( command ));        easyGetTokenFromString( buf , 2 , param , sizeof( param ));        if( strcmp( command , "port" ) == 0 ){            port = atoi( param );        		log( "端口:%d\n",port );        } else if( strcmp( command , "logdir" ) == 0 ){            snprintf( logdir , sizeof( logdir) , param );            log( "日志目录:%s\n",logdir );        } else if( strcmp( command , "lockdir" ) == 0 ){            snprintf( lockdir , sizeof( lockdir) , param );            log( "锁定目录:%s\n",lockdir );        } else if( strcmp( command , "chardir" ) == 0 ){            snprintf( chardir , sizeof( chardir) , param );            log( "档案目录:%s\n",chardir );#ifdef _SLEEP_CHAR			snprintf( sleepchardir , sizeof( sleepchardir), "%s_sleep", chardir);						log( "睡眠目录:%s\n",sleepchardir );#endif        } else if( strcmp( command , "pass" ) == 0 ){            snprintf( svpass , sizeof( svpass ) , param );            log( "密码:%s\n",svpass );        } else if( strcmp( command , "wklogdir" ) == 0 ){            snprintf( wklogdir , sizeof( wklogdir) , param );            log( "工作日志:%s\n",wklogdir );        } else if( strcmp( command , "dbdir" ) == 0 ){            snprintf( dbdir , sizeof( dbdir) , param );                log( "数据目录:%s\n",dbdir );                } else if( strcmp( command, "rotate_interval" ) == 0 ){            log_rotate_interval = atoi( param );            log( "日志循环间隔:%d\n",log_rotate_interval );         } else if( strcmp( command, "maildir" ) == 0 ){            snprintf( maildir, sizeof( maildir ), param );            log( "邮件目录:%s\n",maildir );#ifdef	__FAMILY        // CoolFish: Family 2001/5/9        } else if( strcmp( command, "familydir" ) == 0 ){            snprintf( familydir, sizeof( familydir ), param );            log( "家族目录:%s\n",familydir );        } else if( strcmp( command, "fmpointdir" ) == 0 ){            snprintf( fmpointdir, sizeof( fmpointdir ), param );            log( "庄园表列:%s\n",fmpointdir );        } else if( strcmp( command, "fmsmemodir" ) == 0 ){            snprintf( fmsmemodir, sizeof( fmsmemodir ), param );            log( "家族备份:%s\n",fmsmemodir );#endif#ifdef _LOCK_SERVER        } else if( strcmp( command, "SANAME" ) == 0 ){            snprintf( SaName, sizeof( SaName ), param );            log( "家族备份:%s\n",SaName );        } else if( strcmp( command, "LSADDRESS" ) == 0 ){            snprintf( LSADDRESS, sizeof( LSADDRESS ), param );            log( "上锁服务器地址:%s\n",LSADDRESS );        } else if( strcmp( command, "LSPORT" ) == 0 ){//TESTNAME						LSPORT = atoi( param);						log( "上锁服务器端口:%d\n",LSPORT );				} else if( strcmp( command, "TESTNAME" ) == 0 ){            snprintf( TESTNAME, sizeof( TESTNAME ), param );            log( "测试名:%s\n",TESTNAME );#endif#ifdef _OACSTRUCT_TCP				} else if( strcmp( command, "OACBIND" ) == 0 ){            OACbindtype = atoi( param );            log( "人物列表:%d\n",OACbindtype );#endif        } else if( strcmp( command, "saacname" ) == 0 ){ // 星系名					snprintf( saacname, sizeof( saacname ), param );					log( "saac名:%s\n",saacname );			  } else if( strcmp( command , "Total_Charlist" ) == 0 ){        	Total_Charlist = atoi( param );        	log( "更新人物点数间隔:%d\n",Total_Charlist );        } else if( strcmp( command , "Expired_mail" ) == 0 ){        	Expired_mail = atoi( param );        	log( "更新进期邮件间隔:%d\n",Expired_mail );        } else if( strcmp( command , "Del_Family_or_Member" ) == 0 ){        	Del_Family_or_Member = atoi( param );        	log( "删除家族成员间隔:%d\n",Del_Family_or_Member );        } else if( strcmp( command , "Write_Family" ) == 0 ){        	Write_Family = atoi( param );        	log( "更新家族信息间隔:%d\n",Write_Family );#ifdef _NEW_PLAYERGOLD        } else if( strcmp( command , "NEW_PLAYERGOLD" ) == 0 ){        	New_PlayerGold = atoi( param );        	log( "新帐号给钱:%d\n",New_PlayerGold );#endif		}    }    fclose(fp);    return 0;}static void parseOpts( int argc, char **argv ){    int c , option_index;		while(1){        static struct option long_options[] = {            {"wkport" , 1 , 0 , 'w'},            {"help" , 0 , 0 , 'h' },            {0,0,0,0}        };        c = getopt_long( argc , argv , "w:h" , long_options , &option_index );        if( c == -1 )break;        switch( c ){        case 'h':            fprintf( stderr ,                     "使用方法: saac [-h] [-w port] [-w port] ... \n"                     "-h : 显示saac的帮助\n"                     "-w port : 添加一个工作站进程端口\n"                     "Copyright 2006 龙zoro工作室 "                     "( Longzoro System Supply )\n");            exit(0);            break;        case 'w':			wknum ++;#ifndef _FIX_WORKS			log( "添加工作站端口 %d\n", atoi ( optarg ));            addWorkerPort( atoi( optarg ));#endif            break;        default:            log( "不能读懂选项 %c\n" , c );            exit(0);        }    }}doubletime_diff(struct timeval subtrahend,          struct timeval subtractor);int main( int argc , char **argv ){    // Nuke +1 1012: Loop counter    int counter = 0;    signal(SIGUSR1, sigusr1);    log_rotate_interval = 3600 * 24 * 7;    Lock_Init();	// Arminius 7.17 memory lock#ifdef _SASQL1    sasql_init();#endif#ifdef _SASQL    sasql_init();#endif#ifdef _UNLOCKPOOL	init_UnlockPool();#endif#ifdef _LOCK_SERVER	LServerInit();#endif#ifdef _PAUCTION_MAN	IAData_Init();#endif#ifdef _NEW_PLAYERGOLD	NEWPLAYER_FreeGoldInit();#endif#ifdef _UNIVERSE_CHATROOM	CHATROOM_Init();#endif	UNlockM_Init();    initWorkerPort();    parseOpts( argc, argv );    if(readConfig( "acserv.cf" )<0){        log( "无法在当前目录里读取 acserv.cf .\n" );        exit(1);    }#ifdef _DEATH_CONTEND	if( PKLIST_InitPkTeamList( 2000 ) == -1 ) exit(1);	if( PKLIST_LoadUserfromFile( "pklist", "user1.txt" ) != -1 ){		PKLIST_CutStartUserfromFile( "pklist", "d.txt" );	}	if( PKLIST_LoadPkTeamListfromFile( "pklist", "pk_list_team.txt" ) == - 1 ) exit(1);		PKLIST_alteUserfromFile( "pklist", "alteuser.txt");	PKLIST_CheckRepeatBattleHistory();	PKLIST_Sort_PKListSort();		PKLIST_CheckAllUser();	PKLIST_BackupPkTeamListfromFile( "pklist", "pk_list_team.txt" );#endif    log( "读取数据目录\n" );    dbRead( dbdir );#ifdef _DEFEND_NEWUSERS	DEFEND_InitList();#endif#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( lockdir );    log( "准备 邮件目录\n" );    prepareDirectories( maildir );#ifdef _SLEEP_CHAR    prepareDirectories( sleepchardir );    log( "准备 睡眠档案目录\n" );#endif    /* 凶引匀化月丢□伙毛  心仇戈 */    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 );    connectToWorker();#ifdef _OACSTRUCT_TCP	{		int ret;		if( (ret=OAC_InitTcpIp( OACbindtype, NULL, 0)) != OK ){			log( "开启TCP/ID错误:%d\n", ret );			return 1;		}	}#endif#ifdef _LOCK_SERVER	if( connectToLServer( LSADDRESS, LSPORT) == FALSE )	{		log("%s", "登陆锁定服务器失败!!\n");			return 1;	}else	{		log("%s", "连接锁定服务器成功!!");		usleep( 100*10000);		LServer_SALogin_send();	}#endif    {        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 _BAD_PLAYER            // WON ADD 送坏玩家去关       	log("\n 开启送坏玩家进监狱!!");	BadPlayer();#endif	  #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 _RACEMAN	initRankTable();#endif		log( "\n版本:龙zoro版SAAC服务端v1.1\n" );		    log( "\n开始循环\n" );    signal(SIGUSR1,sigusr1);	// Arminius 7.20 memory lock#ifdef _CHANGEGALAXY	signal(SIGUSR2, sighandle);	// Robin 2003/10/27 星系移民#endif	while(1){        int newti,i;        static time_t main_loop_time;		#if 1		sys_time = time(NULL);		if( main_loop_time != sys_time){#else		if( main_loop_time != time(NULL)){#endif            main_loop_time = time(NULL);            counter++;			//andy add 2002/06/20			UNlockM_UnlockPlayer();#ifdef _ANGEL_SUMMON			checkMissionTimelimit();#endif#ifdef _UNLOCKPOOL			UnlockPoolProc();#endif            // Nuke *1 1012            if( ( counter % Total_Charlist ) == 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 ){                struct timeval st,et;                gettimeofday( &st,NULL);                expireMail();                gettimeofday( &et,NULL);                log( "过期邮件(%fsec)\n", time_diff(et,st) );            }#ifdef _NEW_PLAYERGOLD			if( ( counter % 300 ) == 0 ){				backupNEWPlayerListFile( "newuser.txt", "newuser.bak");			}#endif#ifdef	__FAMILY#ifndef _DEATH_FAMILY_LOGIN_CHECK   // WON ADD 家族战登入检查			if ((counter % /*10800*/600) == 0)	// 3hr( -> 1min)            {            	struct timeval st, et;            	time_t t1;            	gettimeofday(&st, NULL);            	time(&t1);            	delovertimeFMMem(t1);            	gettimeofday(&et, NULL);            	log("删除家族或成员(%fsec)\n", time_diff(et, st));            }#endif            if ((counter % 300) == 0) // 300( -> 60)            {            	struct timeval st, et;            	gettimeofday(&st, NULL);            	writeFamily(familydir);            	writeFMPoint(fmpointdir);            	writeFMSMemo(fmsmemodir);            	gettimeofday(&et, NULL);            	log("记录家族(%fsec)\n", time_diff(et, st));            }#endif        }#ifdef _OACSTRUCT_TCP		OAC_select();		OAC_ReadMessLine();#endif        newti = tcpstruct_accept1();        if( newti >= 0 ){			log( "同意: %d\n" , newti );			gs[newti].use = 1;        }#ifdef _LOCK_SERVER		{			int mlen;			char buf[4096];			if( CHECK_LS_BEUSE() == TRUE )	{				TcpIp_LS_accept();			}			//Show_LS_MEMBufferList();			mlen = MMGet_LsReadBuflist( buf, sizeof( buf));			if( mlen > 0 )	{				if( lockproto_SaacDispatchMessage( buf) < 0 )	{					log( "锁定信息:%s", buf);				}			}			CHECK_LSTYPE();#ifdef _TEST_LOCKSERVER			TEST_TOLOCKSERVER();#endif		}#endif#ifdef _FIX_WORKS		{			int wkti=-1;			int tis[BACKLOGNUM];			newti = tcpstruct_work_accept( tis , 1);			if( newti == 1 )	{				log( "同意工作站: %d\n" , newti );			}			for( i=0; i<MAXWORKCONNECTION; i++){//				char buf6[CHARDATASIZE*16];				char buf6[256];				if( MEMBuffer_getWkLineReadBuffer( i, buf6, sizeof(buf6), WK_R) <= 0 ){					continue;				}				wkti = i;//#ifndef _TIMEOUTKICK				{					int j;					for( j=0;; j++)	{						if( buf6[j] == '\n' ) buf6[j]= 0;						if( buf6[j] == 0 )break;					}				} //#endif				doWorker( wkti, buf6 );			}		}#endif        for(i=0;i<MAXCONNECTION;i++){            char buf[CHARDATASIZE*16];            int l;            l = tcpstruct_readline_chop( i , buf , sizeof( buf )- 1);			if( isWorker( i ) ){#ifndef _FIX_WORKS                if( l > 0 ){                    doWorker( i , buf );                } else if( l == TCPSTRUCT_ETOOLONG || l < 0 ){                    checkWorkerClosed( i );                    tcpstruct_close( i );                } else if( l == 0 ){                    ;                }#endif            } else {                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 );#ifdef _AC_UNLOCK_GS_PLAYER     // WON ADD 自动UNLOCK					DeleteMemLockServer(gs[i].name);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -