#define _MAIN_C_ #ifdef _SASQL1 #include "sasql.h" #endif #include "main.h" #include "util.h" #include "mail.h" #include "db.h" #include "saacproto_util.h" #include "saacproto_serv.h" #ifdef _UNIVERSE_CHATROOM #include "chatroom.h" #endif // CoolFish: Family 2001/5/9 #include "acfamily.h" #include "version.h" #ifdef _DEATH_CONTEND #include "deathcontend.h" #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "saacproto_work.h" #ifdef _OACSTRUCT_TCP #include "saacproto_oac.h" #endif #ifdef _PAUCTION_MAN #include "auction.h" #endif #include "lock.h" #define BACKLOGNUM 5 #ifdef _FIX_WORKS #include "saacproto_work.h" int worksockfd; #endif #ifdef _LOCK_SERVER #include "saacproto_lserver.h" #endif #ifdef _SEND_EFFECT // WON ADD 送下雪、下雨等特效 #include "recv.h" #endif #include "defend.h" #include "char.h" #ifdef _SASQL #include "sasql.h" #endif #ifndef _FIX_WORKS struct membuf { int use; char buf[512]; // char buf[1024*128]; int len; int next; }; struct connection { int use; int fd; int mbtop_ri; int mbtop_wi; struct sockaddr_in remoteaddr; int closed_by_remote; }; #else #endif struct membuf *mb; int mbsize; int mbuse ; int mainsockfd; /* accept 及 域娄醒卞中木月 */ struct sockaddr_in localaddr; /* bind 允月失玉伊旦 */ struct connection *con; /* 戊生弁扑亦件 */ static int mb_finder=0; /* mb及坞五毛腹绸允月凶户及 腹绸玄永皿及匏 筏盛迕 */ // WON FIX char tmpbuf[65536]; //char tmpbuf[65536*3]; /* read迕 */ struct timeval select_timeout; time_t sys_time =0; // Robin add extern gmsv gs[MAXCONNECTION]; int tcpstruct_init( char *addr, int port, int timeout_ms, int mem_use, int deb); int tcpstruct_accept1( void ); int tcpstruct_accept( int *tis , int ticount ); int tcpstruct_close( int ti ); int tcpstruct_read( int ti , char *buf , int len ); int tcpstruct_readline( int ti , char *buf , int len ,int k ,int r); int tcpstruct_readline_chop( int ti , char *buf, int len ); int tcpstruct_write( int ti , char *buf , int len ); int tcpstruct_countmbuse( void ); int tcpstruct_connect( char *addr , int port ); #ifndef _FIX_WORKS void set_nodelay( int sock ); #define OK 0 /* 岳 */ #define TCPSTRUCT_ENOMEM -1 /* malloc 撩 */ #define TCPSTRUCT_ESOCK -2 /* socket 撩 */ #define TCPSTRUCT_EBIND -3 /* bind 撩 */ #define TCPSTRUCT_ELISTEN -4 /* listen 撩 */ #define TCPSTRUCT_EBUG -6 /* 田弘匹丐月 */ #define TCPSTRUCT_EINVCIND -7 /* con尺及index互云井仄中方 */ #define TCPSTRUCT_EREADFIN -8 /* read 允月犯□正互卅仁化 closed by remote */ #define TCPSTRUCT_EHOST -9 /* gethostbyname 撩 */ #define TCPSTRUCT_ECONNECT -10 /* connect 撩 */ #define TCPSTRUCT_ECFULL -11 /* con 互中匀天中 */ #define TCPSTRUCT_ETOOLONG -12 /* 垫互卅互允亢 */ #define TCPSTRUCT_EMBFULL -13 /* mb 互中匀天中 */ #define TCPSTRUCT_ECLOSEAGAIN -14 /* close 互2荚今木凶 */ #endif int port; /* 必□丞扔□田□互涛粮仄化仁月禾□玄 */ int Total_Charlist; int Expired_mail; int Del_Family_or_Member; int Write_Family; #ifdef _NEW_PLAYERGOLD int New_PlayerGold; #endif // Nuke start char *chartime() { static char buf[80]; time_t t; t=time(0); strcpy(buf,ctime(&t)); buf[strlen(buf)-1]=0; return(buf); } /* sigaction白弁 */ void sighandle( int a ) { if (a==SIGUSR1) log("sigusr1信号!\n"); if (a==SIGUSR2) { sigusr2( a); log("sigusr2信号!\n"); return; } #ifdef _SQL_BACKGROUND if(!sasql_initonline()) log("\n数据库保存失败!\n"); #endif log("得到一个信号! 异常中断......\n" ); exit(1); } void sigusr2(int a); // Arminius 7.20 memory unlock void sigusr1(int a) { int i; FILE *f; char key[4096],buf[4096]; signal(SIGUSR1, sigusr1); f = fopen("./unlock.arg", "r"); if (f) { memset(key, 0, 4096); fread(key, 4096, 1, f); for (i=0; i ./sigusr1.result", buf); system(key); break; #ifdef _CK_ONLINE_PLAYER_COUNT // WON ADD 计算线上人数 case 'W': PlayerCount(); break; #endif #ifdef _SEND_EFFECT // WON ADD 送下雪、下雨等特效 case 'E': log("\nAC 向 GS 发送下雪特效!!\n"); SendEffect(&key[1]); break; #endif #ifdef _BAD_PLAYER // WON ADD 送坏玩家去关 case 'B': log("\nAC 发送坏玩家监狱!!\n"); BadPlayer(); break; #endif #ifdef _RECAL_BACKUP_PLAYER // WON 回溯功能 case 'U': log("\n发送备份人物资料"); // 得到备份人物资料 send_backup_player_data(); break; #endif #ifdef _GM_BROADCAST // WON ADD 客服公告系统 case 'G': log("\n won test 1 ==> _GM_BROADCAST" ); broadcast(key); break; #endif #ifdef _KILLDEADWORKER // 将所有Worker初始化 case 'K': log("\nKILL ALL WORKER!!!!!\n"); initWorkerPort(); break; #endif case 'L': // Robin 列出所有Server连线 log("\nList All Server Conncet!!!!!\n"); for( i =0; i = 0 ){ wk[i].ti = ti; } else { exit(1); } } } #endif } static int countWorker( void ); // Nuke int addWorkerTask( char *id , char *pas , char *flag, void (*callbk)( int ti , int result , char *cp0 , char *cp1 , char *cp2 , char *cp3 , char *cp4, int i0 , int i1) , int ti , char *cparam0 , char *cparam1 , char *cparam2 , char *cparam3 , char *cparam4 , int iparam0 , int iparam1) { int i; // Spock +1 2000/11/2 char *process = cparam3; for(i=0;i= MAXWK ) worker_finder = 0; n = worker_finder; if( wk[n].use && wk[n].status == WKSTAT_IDLE ){ char s[256]; log("使用工作站:%d \n", n); // Nuke { int i; for (i=0;id[i];i++) if (id[i]==' ') return -1; } // Spock 2000/11/2 snprintf( s , sizeof( s ) , "%s %s %s %s\n", id , pas , flag , process); // Spock end #ifdef _FIX_WORKS if( cWork_write( wk[n].ti, s, strlen(s)) <= 0 ) { #else if( tcpstruct_write( wk[n].ti , s , strlen(s)) != strlen(s) ){ #endif return -1; } else { } snprintf( wk[n].cparam[0] , CHARDATASIZE , "%s", cparam0 ); snprintf( wk[n].cparam[1] , CHARDATASIZE , "%s", cparam1 ); snprintf( wk[n].cparam[2] , CHARDATASIZE , "%s", cparam2 ); snprintf( wk[n].cparam[3] , CHARDATASIZE , "%s", cparam3 ); snprintf( wk[n].cparam[4] , CHARDATASIZE , "%s", cparam4 ); wk[n].iparam[0] = iparam0; wk[n].iparam[1] = iparam1; wk[n].status = WKSTAT_WAITING; wk[n].callback = callbk; wk[n].request_ti = ti ; wk[n].last_query = time(NULL); return 0; } } log( "工作站繁忙或工作站停止工作. 活动中的工作站有:%d\n", countWorker() ); return -1; } static int countWorker( void ) { int i,c=0; for(i=0;i 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 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); log("\n用户(%s) 登出! 玩家解锁!!\n", gs[i].name ); #endif logout_game_server( i ); } else if( l < 0 ){ log( "关闭:%d 服务器名:%s\n", i , gs[i].name ); #ifdef _UNIVERSE_CHATROOM CHATROOM_GSClosedHandle( i); #endif #ifdef _AC_UNLOCK_GS_PLAYER // WON ADD 自动UNLOCK DeleteMemLockServer(gs[i].name); log("\n用户(%s) 登出! 玩家解锁!!\n", gs[i].name ); #endif #ifdef _WORKER_AUTO_LOGOUT // WON ADD GS断线自动送LOGOUT给WORKER Worker_auto_logout( i, gs[i].name ); #endif 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; } /* 伐□市□及正奶丞失它玄毛譬屯月[ 正奶丞失它玄仄凶日夫弘毛分仄化伐□市□毛诮仄化仄引丹[ 匹必□丞扔□田□卞 蔽读卞反骚襞允月 */ { int i; time_t thre = time(NULL) - WKTIMEOUT; for(i =0;i= 0 && con[i].closed_by_remote ==0 ){ FD_SET( con[i].fd , & rfds ); FD_SET( con[i].fd , & wfds ); FD_SET( con[i].fd , & efds ); } } t = select_timeout; sret = select( 1024, & rfds , (fd_set*)NULL, & efds , &t); if( sret > 0 ) { for(i=0;i< MAXCONNECTION;i++){ if( ( con[i].fd >= 0 ) && FD_ISSET( con[i].fd , &rfds ) ){ int fr = getFreeMem( ); int rr , readsize ; if( fr <= 0 ) continue; if( fr > sizeof(tmpbuf ) ){ readsize = sizeof( tmpbuf); } else { readsize = fr; } rr = read( con[i].fd , tmpbuf , readsize ); if( rr <= 0 ){ con[i].closed_by_remote = 1; } else { appendReadBuffer( i , tmpbuf , rr ); } } } } /* write */ t = select_timeout; sret = select( 1024, (fd_set*)NULL, &wfds, & efds , &t); if( sret > 0 ) { for(i=0;i= 0 ) && FD_ISSET( con[i].fd , &wfds )){ char send_buf[4096]; int l , rr; memset( send_buf, 0, sizeof( send_buf)); l = consumeMemBufList( con[i].mbtop_wi ,send_buf, sizeof(send_buf),0 , 1 ); rr = write( con[i].fd , send_buf , l ); if( rr < 0 ){ con[i].closed_by_remote = 1; } else { consumeMemBufList( con[i].mbtop_wi , send_buf, l, 1 , 0 ); } } } } for( i=0; i0 to avoid signal interrupt in select if( (asret>0) && FD_ISSET( mainsockfd , & rfds )){ struct sockaddr_in c; int len , newsockfd; int newcon; bzero( &c , sizeof( c )); len = sizeof( c ); fprintf( stderr, "i can accept " ); newcon = findregBlankCon( ); if( newcon < 0 ) continue; newsockfd = accept( mainsockfd, (struct sockaddr*)&c , &len ); log( "同意: %d\n" , newsockfd ); if( newsockfd < 0 ){ unregMemBuf( newcon ); continue; } set_nodelay( newsockfd ); con[newcon].fd = newsockfd; memcpy( &con[newcon].remoteaddr , &c ,sizeof(c)); tis[accepted] = newcon; accepted ++; } } return accepted; } int tcpstruct_close( int ti ) { if( ti < 0 || ti >= MAXCONNECTION )return TCPSTRUCT_EINVCIND; if( con[ti].use == 0 ){ return TCPSTRUCT_ECLOSEAGAIN; } close( con[ti].fd ); con[ti].use = 0; con[ti].fd = -1; /* 伉旦玄毛凶升匀化蝈 毛弁伉失允月 */ consumeMemBufList( con[ti].mbtop_ri , NULL, mbsize * sizeof( mb[0].buf ), 1, 0 ); consumeMemBufList( con[ti].mbtop_wi , NULL, mbsize * sizeof( mb[0].buf ), 1, 0 ); unregMemBuf( con[ti].mbtop_ri ); unregMemBuf( con[ti].mbtop_wi ); con[ti].mbtop_ri = -1; con[ti].mbtop_wi = -1; return OK; } /* 心仇戈手及互手丹卅仁化}仄井手 remoteclose 分匀凶日 -1 毛井尹允 */ int tcpstruct_read( int ti , char *buf , int len ) { int l; if( ti < 0 || ti >= MAXCONNECTION || con[ti].use == 0 ) return TCPSTRUCT_EINVCIND; l = consumeMemBufList( con[ti].mbtop_ri , buf , len , 1 , 1); if( l == 0 && con[ti].closed_by_remote ) return TCPSTRUCT_EREADFIN; return l; } /* 1垫毛方心仇戈[ int kend : 1卅日垫 及 \n 毛诮允 int kend_r : 1卅日垫 及 \r 手诮允(丐木壬) 心仇戈手及互手丹卅仁化}井勾 remote closed 分匀凶日-1毛井尹允 // Nuke Read 1 line if kend==1 then delete \n at the tail if kend_r== 1 then delete \r at the tail (if any) if no data read, it means 'remote closed' then return -1 */ int tcpstruct_readline( int ti , char *buf , int len , int kend , int kend_r ) { int l; int minus = 0; if( ti < 0 || ti >= MAXCONNECTION || con[ti].use == 0 ) return TCPSTRUCT_EINVCIND; l = getLineReadBuffer( ti , buf , len ); if( l == 0 ){ if( con[ti].closed_by_remote ){ return TCPSTRUCT_EREADFIN; } else { return 0; } } if( kend ){ if( buf[l-1]=='\n' ){ buf[l-1] = 0; minus =-1; } } if( kend_r ){ if( buf[l-1]=='\r' ){ buf[l-1] = 0; minus = -1; } if( buf[l-2]=='\r' ){ buf[l-2] = 0; minus = -2; } } return l + minus; } int tcpstruct_readline_chop( int ti , char *buf, int len ) { return tcpstruct_readline( ti , buf , len , 1,1); } int tcpstruct_write( int ti , char *buf , int len ) { if( ti < 0 || ti >= MAXCONNECTION || con[ti].use == 0 ) return TCPSTRUCT_EINVCIND; return appendWriteBuffer( ti , buf , len ); } int tcpstruct_connect( char *addr , int port ) { int newti ; int s, r; struct sockaddr_in svaddr; struct hostent *he; s = socket( AF_INET, SOCK_STREAM , 0 ); if(s<0)return -2; bzero( &svaddr , sizeof( svaddr )); svaddr.sin_family = AF_INET; svaddr.sin_port = htons( port ); if( inet_aton( addr, &svaddr.sin_addr ) == 0 ){ he = gethostbyname( addr ); if( he == NULL ){ return TCPSTRUCT_EHOST; } memcpy( & svaddr.sin_addr.s_addr , he->h_addr , sizeof( struct in_addr)); } r = connect( s , ( struct sockaddr*)&svaddr,sizeof(svaddr)); if( r < 0 ){ return TCPSTRUCT_ECONNECT; } set_nodelay( s ); newti = findregBlankCon( ); if( newti < 0 ){ fprintf( stderr , "连接失败: newti:%d\n", newti ); return TCPSTRUCT_ECFULL; } con[newti].fd = s; memcpy( & con[newti].remoteaddr , &svaddr , sizeof( struct sockaddr_in)); return newti; } static int appendReadBuffer( int index , char *data , int len ) { int top; top = con[index].mbtop_ri; for(;;){ int nextind = mb[top].next; if( nextind == -1 ) break; top = nextind; } return appendMemBufList( top , data , len ); } static int appendWriteBuffer( int index , char *data , int len ) { int top; top = con[index].mbtop_wi; for(;;){ int nextind = mb[top].next; if( nextind == -1 ) break; top = nextind; } return appendMemBufList( top , data , len ); } static int appendMemBufList( int top , char *data , int len ) { int fr = getFreeMem( ); int rest = len; int data_topaddr = 0; if( len >= fr ){ FILE *fp; if( (fp=fopen( "badsysinfo.txt", "a+")) != NULL ){ fprintf( fp, "appendMemBufList() len:%d / fr:%d err !! \n", len, fr); fclose( fp); } //andy_log log( "appendMemBufList() len:%d / fr:%d err !! \n", len, fr); return -1; } data[len] = 0; for(;;){ int blanksize = sizeof( mb[0].buf ) - mb[top].len; int cpsize = ( rest <= blanksize ) ? rest : blanksize; memcpy( mb[top].buf + mb[top].len , data + data_topaddr , cpsize ); mb[top].len += cpsize; if( rest <= blanksize ){ return len; } else { int newmb; rest -= cpsize; data_topaddr += cpsize; if( (newmb = findregBlankMemBuf( ) ) == TCPSTRUCT_EMBFULL ){ FILE *fp; if( (fp=fopen( "badsysinfo.txt", "a+")) != NULL ){ fprintf( fp, "find newmb == TCPSTRUCT_EMBFULL err data:%s !!\n", data); fclose( fp); } log( "find newmb == TCPSTRUCT_EMBFULL err data:%s !!\n", data); } mb[top].next = newmb; top = mb[top].next; } } return TCPSTRUCT_EBUG; } static int consumeMemBufList( int top , char *out , int len , int consumeflag , int copyflag ) { int total = 0; int top_store = top; for(;;){ int cpsize; if( top == -1 ) break; cpsize = ( mb[top].len <= ( len - total) ) ? mb[top].len : ( len - total ); if( copyflag ) memcpy( out + total , mb[top].buf , cpsize ); total += cpsize; if( consumeflag ){ mb[top].len -= cpsize; if( mb[top].len > 0 ){ /* 勾井中反凶仄化卅中及匹memmove */ memmove( mb[top].buf , mb[top].buf + cpsize , sizeof( mb[top].buf ) - cpsize ); } } top = mb[top].next; if( total == len ){ break; } } if( consumeflag ){ /* 卅互今互0卞卅匀化月卅日荸 [匹手 赓及支勾反荸 仄卅中冗 */ top = mb[top_store].next; for(;;){ if( top == -1 )break; if( mb[top].len == 0 ){ int prev; mb[top_store].next = mb[top].next; prev = top; top = mb[top].next; unregMemBuf( prev ); } else { top = mb[top].next; } } } return total; } static int getLineReadBuffer( int index , char *buf, int len ) { int top = con[index].mbtop_ri; int ti = 0 , breakflag = 0; for(;;){ int i; int l = mb[top].len; if( top == -1 )break; for( i=0 ; i < l ; i++){ if( mb[top].buf[i] == '\n' ){ breakflag = 1; break; } ti ++; } if( breakflag )break; top = mb[top].next; } if( ti > len ){ /* 1垫互卅互允亢月[ 卅巨仿□毛井尹六 */ return TCPSTRUCT_ETOOLONG; } /* 垫互敦岳仄化卅中 */ if( breakflag == 0 ){ return 0; } return consumeMemBufList( con[index].mbtop_ri , buf , ti+1 , 1 , 1 ); } /* 心仇户月 赢今毛忒允 int index : con index return: 反巨仿□ 0动晓及桦宁反 read 仄化手方中赢今[ mbsize 井日mbuse 毛娄中化扔奶术毛井仃月分仃[ 仇引井中芴曰及坌反 骰允月[公氏卅称井中袄卞仇分歹日卅仁化手第[ */ static int getFreeMem( void ) { return ( mbsize - mbuse ) * sizeof( mb[0].buf ); } /* membuf 及坞五毛茧仄分允[ return : 心勾井匀凶日 >=0 匹 index. 心勾井日卅井匀凶日 腹绸及午五卞反 mb_finder 毛勾井丹[ 仇木匹腹绸仄化} 卞reg允月[ */ static int findregBlankMemBuf( void ) { int i; for(i=0;i= mbsize || mb_finder < 0 ) mb_finder = 0; if( mb[mb_finder].use == 0 ){ mb[mb_finder].use = 1; mb[mb_finder].len = 0; mb[mb_finder].next = -1; mbuse ++; return mb_finder; } } return TCPSTRUCT_EMBFULL; } /* mb 毛荸 允月 */ static int unregMemBuf( int index ) { mb[index].use=0; mb[index].next = -1; mb[index].len = 0; mbuse --; return OK; } static int findregBlankCon( void ) { int i; // Nuke changed 0->1 //for(i=0;i15) || (toinfo <0) || ( toinfo >15)) continue; // 是否要移民出去或移民进来 if( !strcmp( servername[frominfo], saacname) || !strcmp( servername[toinfo], saacname) ) { log(" from:%s to:%s ", servername[frominfo], servername[toinfo]); // 锁帐号 #ifdef _LOCK_ADD_NAME InsertMemLock( getHash(playerinfo) & 0xff, playerinfo, "", "", "星系移民", 0, "0"); #else InsertMemLock( getHash(playerinfo) & 0xff, playerinfo, "", "星系移民", 0, "0"); #endif // 踢人 log("移民前踢人 "); for(i=0;i%s->%s", i, gs[i].name, playerinfo); } } } //else //{ // continue; //} } // 列表档案改名备份 //sprintf( backup_movelist, "%s.old", listfilename); //rename( listfilename, backup_movelist); fclose( listfile); } signal(SIGUSR2, sighandle); } #ifdef _ANGEL_SUMMON #define MISSIONFILE "db/missiontable.txt" static int initMissionTable( void ) { FILE *fp; char onedata[1024]; char buf[1024]; int index =0; memset( missiontable, 0, sizeof(missiontable)); fp = fopen( MISSIONFILE, "r"); if( !fp ) { log("\n加载任务错误!!!! \n"); //return false; } log("\n加载任务..."); while(1) { // if( fgets( onedata, sizeof(onedata), fp) == NULL) break; if( onedata[0] == NULL || onedata[0] == '#' ) continue; //easyGetTokenFromBuf( onedata, ',', 1, buf, sizeof( buf)); //index = atoi( buf); easyGetTokenFromBuf( onedata, ',', 1, buf, sizeof( buf)); if( buf[0] == NULL ) continue; strcpy( missiontable[index].angelinfo, buf); easyGetTokenFromBuf( onedata, ',', 2, buf, sizeof( buf)); if( buf[0] == NULL ) continue; strcpy( missiontable[index].heroinfo, buf); easyGetTokenFromBuf( onedata, ',', 3, buf, sizeof( buf)); if( buf[0] == NULL ) continue; missiontable[index].mission = atoi( buf); easyGetTokenFromBuf( onedata, ',', 4, buf, sizeof( buf)); if( buf[0] == NULL ) continue; missiontable[index].flag = atoi( buf); easyGetTokenFromBuf( onedata, ',', 5, buf, sizeof( buf)); if( buf[0] == NULL ) continue; missiontable[index].time = atoi( buf); easyGetTokenFromBuf( onedata, ',', 6, buf, sizeof( buf)); if( buf[0] == NULL ) continue; missiontable[index].limittime = atoi( buf); log(" %d=%s,%s,%d,%d,%d,%d \n", index, missiontable[index].angelinfo, missiontable[index].heroinfo, missiontable[index].mission, missiontable[index].flag, missiontable[index].time, missiontable[index].limittime ); index++; if( index >= MAXMISSIONTABLE) break; } fclose( fp); log("..成功! \n"); //return true; } int saveMissionTable( void ) { FILE *fp; char onedata[1024]; char buf[1024]; int index =0; fp = fopen( MISSIONFILE, "w"); if( !fp ) { log("\n打开任务错误!!!! \n"); //return false; } log("\n\n保存任务..."); for( index =0; index < MAXMISSIONTABLE; index++) { if( missiontable[index].angelinfo[0] == NULL ) continue; sprintf( onedata, "%s,%s,%d,%d,%d,%d\n", missiontable[index].angelinfo, missiontable[index].heroinfo, missiontable[index].mission, missiontable[index].flag, missiontable[index].time, missiontable[index].limittime ); fputs( onedata, fp); } fclose( fp); log("..成功! \n"); //return true; } void delMissionTableOnedata( int index) { int gi; log("\n删除任务:%d:%s:%s \n", index, missiontable[index].angelinfo, missiontable[index].heroinfo); if( index <0 || index >=MAXMISSIONTABLE) return; strcpy( missiontable[index].angelinfo, ""); strcpy( missiontable[index].heroinfo, ""); missiontable[index].mission = 0; missiontable[index].flag = MISSION_NONE; missiontable[index].time = 0; missiontable[index].limittime = 0; for( gi=0; gi missiontable[index].time + ANSWERTIME*60*60 ) { delMissionTableOnedata( index);// 删 } // 等待领奖完成 limittime小时 else if( ( missiontable[index].flag == MISSION_DOING || missiontable[index].flag == MISSION_HERO_COMPLETE ) && ( sys_time > (missiontable[index].time + missiontable[index].limittime*60*60)) ) { char buf[1024]; int gi; // 改TIMEOVER log(" 任务及领奖时间过:%d ", index); missiontable[index].flag = MISSION_TIMEOVER; missiontable[index].time = time(NULL); missiontable[index].limittime = BOUNDSTIME; sprintf( buf, "%d|%s|%s|%d|%d|%d|%d ", index, missiontable[index].angelinfo, missiontable[index].heroinfo, missiontable[index].mission, missiontable[index].flag, missiontable[index].time, missiontable[index].limittime ); for( gi=0; gi missiontable[index].time + BOUNDSTIME*60*60 ) { // log(" 领奖时间过:%d ", index); // delMissionTableOnedata( index);// 删 //} // 资料保留时间(BOUNDSTIME小时) else if( missiontable[index].flag == MISSION_TIMEOVER && sys_time > missiontable[index].time + BOUNDSTIME*60*60 ) { log(" 保留时间过:%d ", index); delMissionTableOnedata( index);// 删 } } saveMissionTable(); lastcheck = sys_time; } #endif #ifdef _RACEMAN //#define RANKFILE "race/ranktable.txt" struct RankTable ranktable[DEFMAXRANK]; static int initRankTable( void ) { //FILE *fp; memset( ranktable, 0, sizeof(ranktable)); /* fp = fopen( RANKFILE, "r"); if( !fp ) { log("\n\n Load RankTable ERROR!!!! \n\n"); } log("\n\n Load RankTable... \n"); */ return; } #endif