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

📄 net.c

📁 石器时代8.0服务端完整源代码。可以直接编译
💻 C
📖 第 1 页 / 共 5 页
字号:
#endif			) {								if( chikulatime%6 == 0 ){ // 每60秒					// shan 2001/12/27 Begin					if( CHAR_getWorkInt( Connect[i].charaindex, CHAR_WORKBATTLEMODE)							!=BATTLE_CHARMODE_NONE){						struct timeval recvtime;						CONNECT_GetBattleRecvTime( i, &recvtime);														if( time_diff( NowTime, recvtime) > 360 ){																CONNECT_endOne_debug(i);							close(i);						}													}					// End				}//%30				if( chikulatime%30 == 0 ){ // 每300秒#ifdef _ITEM_ADDEXP	//vincent 经验提升					if( CHAR_getWorkInt(Connect[i].charaindex,CHAR_WORKITEM_ADDEXP)>0 && 					   CHAR_getInt( Connect[i].charaindex, CHAR_WHICHTYPE) == CHAR_TYPEPLAYER ){#if 1						int charaindex, exptime;						charaindex = Connect[i].charaindex;						exptime = CHAR_getWorkInt( charaindex, CHAR_WORKITEM_ADDEXPTIME) - 300;						if( exptime <= 0 ) {							CHAR_setWorkInt( charaindex, CHAR_WORKITEM_ADDEXP, 0);							CHAR_setWorkInt( charaindex, CHAR_WORKITEM_ADDEXPTIME, 0);							CHAR_talkToCli( charaindex,-1,"提升学习经验的能力消失了!",CHAR_COLORYELLOW);						}						else {							CHAR_setWorkInt( charaindex, CHAR_WORKITEM_ADDEXPTIME, exptime);							//print("\n 检查ADDEXPTIME %d ", exptime);														if( (exptime % (60*60)) < 300 && exptime >= (60*60) )							{								char msg[1024];								sprintf( msg, "提升学习经验的能力剩大约 %d 小时。", (int)(exptime/(60*60)) );								//sprintf( msg, "提升学习经验的能力剩大约 %d 分。", (int)(exptime/(60)) );								CHAR_talkToCli( charaindex, -1, msg, CHAR_COLORYELLOW);							}						}#else						if(Connect[i].EDTime < CHAR_getWorkInt(Connect[i].charaindex,CHAR_WORKITEM_ADDEXPTIME)){//功能作用有效期限							Connect[i].EDTime=Connect[i].EDTime+300;						}else{							Connect[i].EDTime = 0;							CHAR_setWorkInt( Connect[i].charaindex, CHAR_WORKITEM_ADDEXP, 0);							CHAR_setWorkInt( Connect[i].charaindex, CHAR_WORKITEM_ADDEXPTIME, 0);							CHAR_talkToCli(Connect[i].charaindex,-1,"提升学习经验的能力消失了!",CHAR_COLORYELLOW);						}#endif					}#endif#ifdef _ITEM_METAMO					if( CHAR_getWorkInt( Connect[i].charaindex, CHAR_WORKITEMMETAMO) < NowTime.tv_sec 							&& CHAR_getWorkInt( Connect[i].charaindex, CHAR_WORKITEMMETAMO) != 0 ){							CHAR_setWorkInt( Connect[i].charaindex, CHAR_WORKITEMMETAMO, 0);							CHAR_setWorkInt( Connect[i].charaindex, CHAR_WORKNPCMETAMO, 0 ); //与npc对话後的变身也要变回来							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);					}#endif#ifdef _ITEM_TIME_LIMIT					ITEM_TimeLimit(Connect[i].charaindex);	// (可开放) shan time limit of item. code:shan#endif				}//%30#ifndef _USER_CHARLOOPS				//here 原地遇敌				if( Connect[i].stayencount ) {					if( Connect[i].BDTime < time( NULL) )	{						if( CHAR_getWorkInt(Connect[i].charaindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE){							lssproto_EN_recv( i, CHAR_getInt(Connect[i].charaindex,CHAR_X),								CHAR_getInt(Connect[i].charaindex,CHAR_Y));							Connect[i].BDTime = time( NULL);						}					}				}#endif#ifdef _CHIKULA_STONE				if( chikulatime%3 == 0 && getChiStone( i) > 0)	{	//自动补血					CHAR_AutoChikulaStone( Connect[i].charaindex, getChiStone( i));				}#endif				if( chikulatime%6 == 0 )	{	//水世界状态#ifdef _STATUS_WATERWORD					CHAR_CheckWaterStatus( Connect[i].charaindex);#endif					// Nuke 0626: No enemy					if (Connect[i].noenemy>0) {						Connect[i].noenemy--;						if (Connect[i].noenemy==0) {							CHAR_talkToCli(CONNECT_getCharaindex(i),-1,"守护消失了。",CHAR_COLORWHITE);						}					}				}				//每10秒#ifdef _TYPE_TOXICATION	//中毒				if( Connect[i].toxication > 0 ){					CHAR_ComToxicationHp( Connect[i].charaindex);				}#endif				// Nuke 0624 Avoid Useless Connection				if (Connect[i].state == NOTLOGIN) {					Connect[i].cotime++;					if (Connect[i].cotime>30) {						print( "LATE" );						CONNECT_endOne_debug(i);						close(i);					}				}else{					Connect[i].cotime=0;				}				if ((Connect[i].nu <= 22)) {					int r;					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);					close(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)#ifdef _M_SERVER				&& (i!=mfd)#endif#ifdef _NPCSERVER_NEW				&& (i!=npcfd)#endif			){				//计算用				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;}#if USE_MTIO == 0int player_online = 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 fdset;    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#if 0#ifdef _M_SERVER	static unsigned int m_time=0;	unsigned int mm;	static int connectnum = 0;	if (mfd < 0){		mm=time(NULL);		if( (mm - m_time > 120) && connectnum < 5 ){			m_time = mm;			mfd = connectmServer(getmservername(),getmserverport());			connectnum ++;			if (mfd != -1){				initConnectOne(mfd,NULL,0);				print("connect to mserver successed\n");				connectnum = 0; //重设连线次数			}else{				print("connect to mserver failed\n");			}		}	}else	{		connectnum = 0;	}#endif#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);	}*/#ifdef _NPCSERVER_NEW	{		static unsigned int NStime=0;		static int connectNpcnum = 0;		if( (NStime + 120) < time(NULL) && connectNpcnum < 10 ){			NStime = time(NULL);			if (npcfd < 0){				npcfd = connectNpcServer( getnpcserveraddr(), getnpcserverport());				connectNpcnum ++;				if (npcfd != -1){					initConnectOne( npcfd, NULL, 0);					print("connect to NpcServer successed\n");					NPCS_NpcSLogin_send( npcfd);					connectNpcnum = 0; //重设连线次数				}			}else	{				connectNpcnum = 0;			}		}	}#endif    looptime_us = getOnelooptime_ms()*1000 ;    casend_interval_us = getCAsendinterval_ms()*1000;    cdsend_interval_us = getCDsendinterval_ms()*1000;    FD_ZERO( &fdset );    FD_SET( bindedfd ,& fdset);    tmv.tv_sec = tmv.tv_usec = 0;    ret = select( bindedfd + 1 , &fdset,(fd_set*)NULL,(fd_set*)NULL,&tmv );    if( ret < 0 && ( errno != EINTR )){        print( "accept select() error:%s\n", strerror(errno));    }    if( ret > 0 && FD_ISSET(bindedfd , &fdset ) ){        struct sockaddr_in sin;        int addrlen=sizeof( struct sockaddr_in );        int sockfd;        sockfd = accept( bindedfd ,(struct sockaddr*) &sin  , &addrlen );        if( sockfd == -1 && errno == EINTR ){            ;        }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("err item_use full!!");					cono=0;				}			if (cono_check&CONO_CHECK_PET)				if( petcnt >= CHAR_getPetMaxNum() ){					print("err pet_use full!!");					cono=0;				}			{				char temp[80];				sprintf(temp,"%d.%d.%d.%d",				((unsigned char *)&sin.sin_addr)[0],				((unsigned char *)&sin.sin_addr)[1],				((unsigned char *)&sin.sin_addr)[2],				((unsigned char *)&sin.sin_addr)[3]);				if (strcmp(getAccountservername(),temp)==0) {					cono=1; from_acsv=1;					print("From acsv. ");				}#ifdef _M_SERVER				if (strcmp(getmservername(),temp) == 0){					cono=1;					print("From mserver\n");				}#endif			}            //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[1024]="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[1024] = "A";// Nuke +2 Errormessage				if( bNewServer )#ifdef _SA_VERSION_70         // WON ADD 石器时代7.0 的版本控制					mess[0]='F';	  // 7.0#endif				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 ){		                print("setsockopt TCP_NODELAY failed:%s\n",		                      strerror( errno ));		            } else {		                print( "NO" );                    }		        }            }else {                    // Nuke +2 Errormessage	                                 char mess[1024]="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*2];		int	j;        //ttom+1 for the debug        static int i_tto=0;        static int i_timeNu=0;		      

⌨️ 快捷键说明

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