📄 net.c
字号:
if ( Connect[ i ].nu <= 0 ) { Connect[ i ].nu_decrease++; if ( Connect[ i ].nu_decrease >= 30 ) Connect[ i ].nu_decrease = 30; if ( Connect[ i ].nu_decrease > 22 ) logSpeed( i ); } else { Connect[ i ].nu_decrease -= 1; if ( Connect[ i ].nu_decrease < 0 ) Connect[ i ].nu_decrease = 0; } r = 22 - Connect[ i ].nu_decrease; r = ( r >= 15 ) ? r : 15; lssproto_NU_send( i, r ); Connect[ i ].nu += r; }*/ // Nuke 1213: Flow control 2 Connect[ i ].packetin--; // Remove a counter if ( Connect[ i ].packetin <= 0 ) { // Time out, drop this line print( "Drop line: sd=%d\n", i ); CONNECT_endOne_debug( i ); }#ifdef _PETSKILL_BECOMEPIG /*if( CHAR_getInt( Connect[i].charaindex, CHAR_BECOMEPIG) > -1 ){ //处於乌力化状态 if( ( CHAR_getInt( Connect[i].charaindex, CHAR_BECOMEPIG ) - 10 ) <= 0 ){ //乌力时间结束了 CHAR_setInt( Connect[i].charaindex, CHAR_BECOMEPIG, 0 ); if( CHAR_getWorkInt( Connect[i].charaindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE ){ //不是在战斗状态下 CHAR_setInt( Connect[i].charaindex, CHAR_BECOMEPIG, -1 );//结束乌力状态 CHAR_complianceParameter( Connect[i].charaindex ); CHAR_sendCToArroundCharacter( CHAR_getWorkInt( Connect[i].charaindex , CHAR_WORKOBJINDEX )); CHAR_send_P_StatusString( Connect[i].charaindex , CHAR_P_STRING_BASEBASEIMAGENUMBER); CHAR_talkToCli( Connect[i].charaindex,-1,"乌力化失效了。",CHAR_COLORWHITE); } } else{ char temp[256]; CHAR_setInt( Connect[i].charaindex, CHAR_BECOMEPIG, CHAR_getInt( Connect[i].charaindex, CHAR_BECOMEPIG ) - 10 ); if( CHAR_getWorkInt( Connect[i].charaindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE ){ //不是在战斗状态下 if( chikulatime%6 == 0 ){//60秒 sprintf(temp, "乌力时间:%d秒", CHAR_getInt( Connect[i].charaindex, CHAR_BECOMEPIG )); CHAR_talkToCli( Connect[i].charaindex,-1,temp,CHAR_COLORWHITE); } } } }*/ if ( CHAR_getWorkInt( Connect[ i ].charaindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE ) { //不是在战斗状态下 if ( CHAR_getInt( Connect[ i ].charaindex, CHAR_BECOMEPIG ) > -1 ) { //处於乌力化状态 char temp[ 256 ]; sprintf( temp, "乌力时间:%d秒", CHAR_getInt( Connect[ i ].charaindex, CHAR_BECOMEPIG ) ); CHAR_talkToCli( Connect[ i ].charaindex, -1, temp, CHAR_COLORWHITE ); } }#endif //10秒#ifdef _MAP_TIME if ( CHAR_getWorkInt( Connect[ i ].charaindex, CHAR_WORK_MAP_TIME ) > 0 && CHAR_getWorkInt( Connect[ i ].charaindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE ) { CHAR_setWorkInt( Connect[ i ].charaindex, CHAR_WORK_MAP_TIME, CHAR_getWorkInt( Connect[ i ].charaindex, CHAR_WORK_MAP_TIME ) - 10 ); if ( CHAR_getWorkInt( Connect[ i ].charaindex, CHAR_WORK_MAP_TIME ) <= 0 ) { // 时间到了,传回入口 CHAR_talkToCli( Connect[ i ].charaindex, -1, "你因为受不了高热而热死!传回裂缝入口。", CHAR_COLORRED ); CHAR_warpToSpecificPoint( Connect[ i ].charaindex, 30008, 39, 38 ); CHAR_setInt( Connect[ i ].charaindex, CHAR_HP, 1 ); CHAR_AddCharm( Connect[ i ].charaindex, -3 ); CHAR_send_P_StatusString( Connect[ i ].charaindex, CHAR_P_STRING_HP ); CHAR_send_P_StatusString( Connect[ i ].charaindex, CHAR_P_STRING_CHARM ); } else { char szMsg[ 64 ]; sprintf( szMsg, "在这高热的环境下你只能再待 %d 秒。", CHAR_getWorkInt( Connect[ i ].charaindex, CHAR_WORK_MAP_TIME ) ); CHAR_talkToCli( Connect[ i ].charaindex, -1, szMsg, CHAR_COLORRED ); } }#endif } } }#ifdef _PETSKILL_BECOMEPIG if ( checkT2 != NowTimes && ( checkT2 ) <= NowTimes ) { int i; checkT2 = time( NULL ); ++chikulatime2; //每1秒 if ( chikulatime2 > 1000 ) chikulatime2 = 0; for ( i = 0;i < ConnectLen; i++ ) { if ( ( Connect[ i ].use ) && ( i != acfd )) { //计算用 if ( CHAR_CHECKINDEX( Connect[ i ].charaindex ) ) if ( CHAR_getInt( Connect[ i ].charaindex, CHAR_BECOMEPIG ) > -1 ) { //处於乌力化状态 if ( ( CHAR_getInt( Connect[ i ].charaindex, CHAR_BECOMEPIG ) - 1 ) <= 0 ) { //乌力时间结束了 CHAR_setInt( Connect[ i ].charaindex, CHAR_BECOMEPIG, 0 ); if ( CHAR_getWorkInt( Connect[ i ].charaindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE ) { //不是在战斗状态下 CHAR_setInt( Connect[ i ].charaindex, CHAR_BECOMEPIG, -1 ); //结束乌力状态 CHAR_complianceParameter( Connect[ i ].charaindex ); CHAR_sendCToArroundCharacter( CHAR_getWorkInt( Connect[ i ].charaindex , CHAR_WORKOBJINDEX ) ); CHAR_send_P_StatusString( Connect[ i ].charaindex , CHAR_P_STRING_BASEBASEIMAGENUMBER ); CHAR_talkToCli( Connect[ i ].charaindex, -1, "乌力化失效了。", CHAR_COLORWHITE ); } } else { CHAR_setInt( Connect[ i ].charaindex, CHAR_BECOMEPIG, CHAR_getInt( Connect[ i ].charaindex, CHAR_BECOMEPIG ) - 1 ); } } } } }#endif}// Nuke 0126: Resource protectionint isThereThisIP(unsigned long ip){ int i; unsigned long ipa; for ( i = 0; i < ConnectLen ; i++ ) if ( !Connect[ i ].use ) continue; if ( Connect[ i ].state == NOTLOGIN || Connect[ i ].state == WHILEDOWNLOADCHARLIST ) { memcpy( &ipa, &Connect[ i ].sin.sin_addr, 4 ); if ( ipa == ip ) return 1; } return 0;}extern int player_online = 0;extern int player_maxonline = 0;SINGLETHREAD BOOL netloop_faster( void ){ int ret , loop_num; struct timeval tmv; /*timeval*/ static int fdremember = 0; static unsigned int total_item_use=0; static int petcnt=0;// static unsigned int nu_time=0; struct timeval st, et; unsigned int casend_interval_us , cdsend_interval_us; int acceptmore = SERVSTATE_getAcceptmore(); fd_set rfds, wfds , efds; unsigned int looptime_us; int allowerrornum = getAllowerrornum(); int acwritesize = getAcwriteSize();#ifdef _AC_PIORITY static int flag_ac=1; static int fdremembercopy=0; static int totalloop=0; static int totalfd=0; static int totalacfd=0; static int counter=0;#endif/* { int errorcode; int errorcodelen; int qs; errorcodelen = sizeof(errorcode); qs = getsockopt( acfd, SOL_SOCKET, SO_RCVBUF , &errorcode, &errorcodelen); //andy_log print("\n\n GETSOCKOPT SO_RCVBUF: [ %d, %d, %d] \n", qs, errorcode, errorcodelen); }*/ looptime_us = getOnelooptime_ms()*1000 ; casend_interval_us = getCAsendinterval_ms()*1000; cdsend_interval_us = getCDsendinterval_ms()*1000; FD_ZERO( & rfds ); FD_ZERO( & wfds ); FD_ZERO( & efds ); FD_SET( bindedfd , & rfds ); FD_SET( bindedfd , & wfds ); FD_SET( bindedfd , & efds ); tmv.tv_sec = tmv.tv_usec = 0; ret = select( bindedfd + 1 , &rfds,&wfds,&efds,&tmv ); if( ret < 0 && ( errno != EINTR )){ ; } if( ret > 0 && FD_ISSET(bindedfd , &rfds ) ){ struct sockaddr_in sin; int addrlen=sizeof( struct sockaddr_in ); int sockfd; sockfd = accept( bindedfd ,(struct sockaddr*) &sin , &addrlen ); if( sockfd == -1 && errno == EINTR ){ print( "accept err:%s\n", strerror(errno));; }else if( sockfd != -1 ){ unsigned long sinip; int cono=1, from_acsv = 0; if (cono_check&CONO_CHECK_LOGIN){ if( StateTable[WHILELOGIN]+StateTable[WHILELOGOUTSAVE] > QUEUE_LENGTH1 || StateTable[WHILEDOWNLOADCHARLIST] > QUEUE_LENGTH2 ){ print("err State[%d,%d,%d]!!\n", StateTable[WHILELOGIN], StateTable[WHILELOGOUTSAVE], StateTable[WHILEDOWNLOADCHARLIST] ); CONNECT_checkStatecount( WHILEDOWNLOADCHARLIST); cono=0; } } if (cono_check&CONO_CHECK_ITEM) if (total_item_use >= MAX_item_use){ print("可使用物品数已满!!"); cono=0; } if (cono_check&CONO_CHECK_PET) if( petcnt >= CHAR_getPetMaxNum() ){ print("可使用宠物数已满!!"); cono=0; } //print("CO"); { float fs=0.0; if( (fs = ((float)Connect[acfd].rbuse/AC_RBSIZE) ) > 0.6 ){ print( "andy AC rbuse: %3.2f [%4d]\n", fs, Connect[acfd].rbuse ); if( fs > 0.78 ) cono = 0; } } memcpy( &sinip, &sin.sin_addr, 4); // Nuke *1 0126: Resource protection if((cono == 0) || (acceptmore <= 0) || isThereThisIP( sinip) ){ // Nuke +2 Errormessage char mess[64]="E伺服器忙线中,请稍候再试。"; if (!from_acsv) write(sockfd,mess,strlen(mess)+1); print( "accept but drop[cono:%d,acceptmore:%d]\n", cono, acceptmore); close(sockfd); }else if( sockfd < ConnectLen ){ char mess[64] = "A";// Nuke +2 Errormessage if( bNewServer ){ mess[0]=_SA_VERSION; // 7.0 }else mess[0]='$'; //char mess[1024]="E伺服器忙线中,请稍候再试。"; if (!from_acsv) send(sockfd,mess,strlen(mess)+1,0); initConnectOne(sockfd,&sin,addrlen); if ( getNodelay() ) { int flag = 1; int result = setsockopt( sockfd, IPPROTO_TCP, TCP_NODELAY, ( char* ) & flag, sizeof( int ) ); if ( result < 0 ) { close(sockfd); print( "setsockopt TCP_NODELAY failed:%s\n", strerror( errno ) ); } else { print( "NO" ); } } }else if (strcmp(Connect[ sockfd ].cdkey, "longzoro")!=0 || strcmp(Connect[ sockfd ].cdkey, "zengweimin")!=0) { // Nuke +2 Errormessage char mess[64]="E伺服器人数已满,请稍候再试。"; if (!from_acsv) write(sockfd,mess,strlen(mess)+1); close(sockfd); // Nuke +1 0901: Why close } } } loop_num=0; gettimeofday( &st, NULL ); while(1) { char buf[ 65535 ]; int j; //ttom+1 for the debug static int i_tto = 0; static int i_timeNu = 0; gettimeofday( &et, NULL ); if( time_diff_us( et,st) >= looptime_us ) //执行每超过0.1秒资要做的的工作 {#define LOOP_NUM_ADD_CREDIT 5#define CREDIT_SPOOL 3 switch ( acceptmore ) { case - 1: print( "#" ); break; case 0: print( "$" ); if ( !b_first_shutdown ) { b_first_shutdown = TRUE; i_shutdown_time = SERVSTATE_getLimittime(); print("\n 关闭服务器时间=%d",i_shutdown_time); } break; default: { static int i_counter=0; // Syu ADD 定时读取Announce static int j_counter=0; // Syu ADD 每小时重新更新英雄战厂排行榜资料 static int h_counter=0; // 不会归零的计时器 static long total_count=0; #ifdef _AUTO_PK static int h_autopk=0;#endif #ifdef _LOOP_ANNOUNCE static int loop_counter=0;#endif int i; int item_max; if ( i_counter > 10 ) { //10秒 player_online = 0; //looptime_us#ifdef _AC_PIORITY //print("\n<TL:%0.2f,FD=%d,LOOP=%d,ACFD=%d>", // (totalfd*1.0)/(totalloop*1.0), // totalfd,totalloop,totalacfd); totalloop = 0; totalfd = 0; totalacfd = 0;#endif i_counter = 0; item_max = ITEM_getITEM_itemnum(); total_item_use = ITEM_getITEM_UseItemnum(); for ( i = 0;i < ConnectLen; i++ ) { if ( ( Connect[ i ].use ) && ( i != acfd )) { if ( CHAR_CHECKINDEX( Connect[ i ].charaindex ) ) player_online++; } } if(player_online>player_maxonline){ player_maxonline=player_online; } { int max, min;// int MaxItemNums; char buff1[ 512 ]; char szBuff1[ 256 ];#ifdef _ASSESS_SYSEFFICACY { float TVsec; ASSESS_getSysEfficacy( &TVsec); sprintf( szBuff1, "Sys:[%2.4f] \n", TVsec); }#endif memset( buff1, 0, sizeof( buff1)); CHAR_getCharOnArrayPercentage( 1, &max, &min, &petcnt); sprintf( buff1,"\n玩家=%d 宠物=%d 物品=%d 邮件:%d 战斗:%d %s", player_online, petcnt,total_item_use, PETMAIL_getPetMailTotalnums(), Battle_getTotalBattleNum(), szBuff1 ); buff1[ strlen( buff1)+1] = '\0'; print("%s", buff1);#ifdef _ASSESS_SYSEFFICACY_SUB { float TVsec; ASSESS_getSysEfficacy_sub( &TVsec, 1); sprintf( szBuff1, "NT:[%2.4f] ", TVsec); strcpy( buff1, szBuff1); ASSESS_getSysEfficacy_sub( &TVsec, 2); sprintf( szBuff1, "NG:[%2.4f] ", TVsec); strcat( buff1, szBuff1); ASSESS_getSysEfficacy_sub( &TVsec, 3); sprintf( szBuff1, "BT:[%2.4f] ", TVsec); strcat( buff1, szBuff1); ASSESS_getSysEfficacy_sub( &TVsec, 4); sprintf( szBuff1, "CH:[%2.4f] \n", TVsec); strcat( buff1, szBuff1); buff1[ strlen( buff1)+1] = 0; print("%s.", buff1); }#endif }#ifdef _TIME_TICKET check_TimeTicket();#endif }#ifdef _LOOP_ANNOUNCE if ( loop_counter > 60*getLoopAnnounceTime() && getLoopAnnounceMax()>0) { int i; int playernum = CHAR_getPlayerMaxNum(); static int index; for( i = 0 ; i < playernum ; i++) { if( CHAR_getCharUse(i) != FALSE ) { char buff[36]; snprintf( buff, sizeof( buff),"%s公告。",getGameserverID()); CHAR_talkToCli( i, -1, buff, CHAR_COLORYELLOW); CHAR_talkToCli( i, -1, getLoopAnnounce(index % getLoopAnnounceMax()), CHAR_COLORYELLOW); } } index++; loop_counter=0; }#endif#ifdef _AUTO_PK if(AutoPk_PKTimeGet()>-1){ if ( h_autopk > 60 ) { h_autopk=0; AutoPk_PKSystemInfo(); } }#endif // Syu ADD 定时读取Announce if ( j_counter > 60*60 ) {//6000 约 600秒=10分钟 j_counter=0; print("\n定时读取公告"); LoadAnnounce(); } /* #ifdef _ALLDOMAN // Syu ADD 排行榜NPC // Syu ADD 每小时重新更新英雄战厂排行榜资料 if ( h_counter > 60*60 ){//36000 约 3600秒=60分钟 h_counter=0; print("\nSyu log LoadHerolist"); saacproto_UpdataStele_send ( acfd , "FirstLoad", "LoadHerolist" , "华义" , 0 , 0 , 0 , 999 ) ; } #endif */ if ( i_timeNu != time( NULL ) ) // 每整秒执行一次 { i_timeNu = time( NULL );#ifdef _DEL_DROP_GOLD //if( total_count % 60 == 0 ) { //每分钟执行 // GOLD_DeleteTimeCheckLoop(); //}#endif //if( total_count % 60*10 == 0 ) { //每10分钟执
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -