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

📄 net.c

📁 石器时代8.0服务端完整源代码。可以直接编译
💻 C
📖 第 1 页 / 共 5 页
字号:
    buf[bufuse-1] = '\0';    lssproto_CD_send(fd, buf );    CONNECT_setCDbufsiz(fd,0);}/*------------------------------------------------------------ * CD毛霜月[ * 娄醒 * 忒曰袄 *  卅仄 ------------------------------------------------------------*/ANYTHREAD void CDcheck( void ){    int     i;    unsigned int interval_us = getCDsendinterval_ms()*1000;    for(i=0; i<ConnectLen; i++ ){        struct timeval t;        if( !CONNECT_getUse_debug(i,1082) ) continue;        CONNECT_getLastCDsendtime( i, &t );        if( time_diff_us( NowTime, t ) > interval_us ){            CDsend( i);            CONNECT_setLastCDsendtime( i , &NowTime );        }    }}ANYTHREAD void CDflush( int charaindex ){    int i;    i = getfdFromCharaIndex( charaindex);    if( i == -1 )return;    CDsend(i);}void chardatasavecheck( void ){    int i;    int interval = getCharSavesendinterval();    static struct timeval chardatasavecheck_store;    if( NowTime.tv_sec > (chardatasavecheck_store.tv_sec +10)){        chardatasavecheck_store = NowTime;                for( i = 0; i < ConnectLen; i ++) {            CONNECT_LOCK(i);            if( Connect[i].use == TRUE                 && Connect[i].state == LOGIN                 && NowTime.tv_sec - Connect[i].lastCharSaveTime.tv_sec                 > interval ){                Connect[i].lastCharSaveTime = NowTime;                CONNECT_UNLOCK(i);                CHAR_charSaveFromConnect( i, FALSE );            } else {                CONNECT_UNLOCK(i);            }        }    } else {        ;    }} #ifdef _DEATH_FAMILY_STRUCT		// WON ADD 家族战存放胜负资料void Init_FM_PK_STRUCT(){	saacproto_Init_FM_PK_STRUC_send( acfd  );}#endif#ifdef _GM_BROADCAST					// WON ADD 客服公告系统void Init_GM_BROADCAST( int loop, int time, int wait, char *msg ){	int i, count = 0;	char *temp;	BS.loop = loop;	BS.time = time;	BS.wait = wait;	BS.next_msg = 0;	// 清空msg	memset( BS.msg, -1, sizeof(BS.msg) );    // 载入公告讯息    if( ( temp = strtok( msg, " " ) ) ){		strcpy( BS.msg[count], temp );        for( i=1; i<10; i++ ){			char *temp1;            if( ( temp1 = strtok( NULL, " " ) ) ){                strcpy( BS.msg[++count], temp1 );			}		}	}	// 公告讯息数	BS.max_msg_line = count;	return;}void GM_BROADCAST(){    int i;    static struct timeval broadcast;	int next_msg = BS.next_msg;	static int wait_time=0;	if( BS.loop <= 0 ) return;    if( NowTime.tv_sec > (broadcast.tv_sec + BS.time + wait_time) ){        broadcast = NowTime;		wait_time = 0;		if( BS.msg[next_msg] != NULL ){			for( i = 0; i < ConnectLen; i ++) {				if( Connect[i].use == TRUE ){					if( Connect[i].charaindex >= 0 )						CHAR_talkToCli( Connect[i].charaindex, -1, BS.msg[next_msg], CHAR_COLORYELLOW);									}			}		}			if( ++BS.next_msg > BS.max_msg_line ){						BS.next_msg = 0;			wait_time = BS.wait;			// BS.loop = 1000 时一直公告			if( BS.loop < 1000 )	BS.loop--;		}    }}#endif/*------------------------------------------------------------ * fd 互 valid 卅手及井升丹井毛譬屯月 * 娄醒 *  fd          int         fd * 忒曰袄 *  valid   TRUE(1) *  invalid FALSE(0) ------------------------------------------------------------*/ANYTHREAD INLINE int CONNECT_checkfd( int fd ){    if( 0 > fd ||  fd >= ConnectLen ){        return FALSE;    }    CONNECT_LOCK(fd);    if( Connect[fd].use == FALSE ){        CONNECT_UNLOCK(fd);        return FALSE;    } else {        CONNECT_UNLOCK(fd);        return TRUE;    }}/*------------------------------------------------------------ * cdkey 井日 fd 毛  月[ * 娄醒 *  cd      char*       cdkey * 忒曰袄 *  白央奶伙犯奴旦弁伉皿正  方匀化} -1 及凛反巨仿□ ------------------------------------------------------------*/ANYTHREAD int getfdFromCdkey( char* cd ){    int i;    for( i = 0 ;i < ConnectLen ; i ++ ){        CONNECT_LOCK(i);        if( Connect[i].use == TRUE &&            strcmp( Connect[i].cdkey , cd ) == 0 ){            CONNECT_UNLOCK(i);            return i;        }        CONNECT_UNLOCK(i);    }    return -1;}/*------------------------------------------------------------ * charaindex 井日 fd 毛  月[ *   陆质  及民尼永弁毛聂仁仄凶[ * 娄醒 *  charaindex      int     平乓仿及奶件犯永弁旦 * 忒曰袄 *  白央奶伙犯奴旦弁伉皿正  方匀化} -1 及凛反巨仿□ ------------------------------------------------------------*/ANYTHREAD int getfdFromCharaIndex( int charaindex ){#if 1	int ret;	if( !CHAR_CHECKINDEX( charaindex)) return -1;	if( CHAR_getInt( charaindex, CHAR_WHICHTYPE) != CHAR_TYPEPLAYER) return -1;	ret = CHAR_getWorkInt( charaindex, CHAR_WORKFD);	if( ret < 0 || ret >= ConnectLen ) return -1;	return ret;#else    int i;    for( i = 0 ;i < ConnectLen ; i ++ ){        CONNECT_LOCK(i);        if( Connect[i].use == TRUE            && Connect[i].charaindex == charaindex ){            CONNECT_UNLOCK(i);            return i;        }        CONNECT_UNLOCK(i);    }    return -1;#endif}/*------------------------------------------------------------ * charaindex 井日 cdkey 毛  月[ * 娄醒 *  charaindex  int     平乓仿及奶件犯永弁旦 * 忒曰袄 *  0卅日岳  }  卅日撩   ------------------------------------------------------------*/ANYTHREAD int getcdkeyFromCharaIndex( int charaindex , char *out, int outlen ){    int i;    for( i = 0 ;i < ConnectLen ; i ++ ){        CONNECT_LOCK(i);        if( Connect[i].use == TRUE            && Connect[i].charaindex == charaindex ){            snprintf( out, outlen, "%s" , Connect[i].cdkey );            CONNECT_UNLOCK(i);            return 0;        }        CONNECT_UNLOCK(i);    }    return -1;}/*------------------------------------------------------------ *   元fdid 及蛊毛茧允 * 娄醒 *  fdid    int     fd及id * 忒曰袄 *  -1 及凛反巨仿□ ------------------------------------------------------------*/ANYTHREAD int getfdFromFdid( int fdid ){    int i;    for( i=0; i<ConnectLen ; i ++ ){        CONNECT_LOCK(i);        if( Connect[i].use == TRUE            && Connect[i].fdid == fdid ){            CONNECT_UNLOCK(i);            return i;        }        CONNECT_UNLOCK(i);    }    return -1;}/*------------------------------------------------------------ * fdid 井日平乓仿及index 毛手午户月[ * 娄醒 *  fdid    int     fd及id * 忒曰袄 *  -1 及凛反夫弘奶件  及平乓仿反心勾井日卅井匀凶[0动晓卅日 * 夫弘奶件  及平乓仿及平乓仿反中木勾尺及 index ------------------------------------------------------------*/ANYTHREAD int getCharindexFromFdid( int fdid ){    int i;    for( i=0; i<ConnectLen ; i ++ ){        CONNECT_LOCK(i);        if( Connect[i].use == TRUE            && Connect[i].fdid == fdid &&            Connect[i].charaindex >= 0 ){            int a = Connect[i].charaindex;            CONNECT_UNLOCK(i);            return a;        }        CONNECT_UNLOCK(i);    }    return -1;}/*------------------------------------------------------------ * 平乓仿index 井日 fdid 毛手午户月[ * 娄醒 *  charind  int     白央奶伙犯奴旦弁伉皿正 * 井尹曰切 fdid    分匀凶日平乓仿ind互云井仄中 ------------------------------------------------------------*/ANYTHREAD int getFdidFromCharaIndex( int charind ){    int i;    for( i=0; i<ConnectLen ; i ++ ){        CONNECT_LOCK(i);        if( Connect[i].use == TRUE            && Connect[i].charaindex == charind ){            int a = Connect[i].fdid;            CONNECT_UNLOCK(i);            return a;        }        CONNECT_UNLOCK(i);    }    return -1;}/*------------------------------------------------------------ * fd卞喃曰癫化日木凶涛粮互弁仿奶失件玄分午}BOOL毛忒允 * 称中巨仿□民尼永弁反仄卅中[ * 娄醒 *  fd  int     白央奶伙犯奴旦弁伉皿正 ------------------------------------------------------------*/ANYTHREAD BOOL CONNECT_isCLI( int fd ){    int a;    CONNECT_LOCK(fd);    a = ( Connect[fd].ctype == CLI ? TRUE : FALSE  );    CONNECT_UNLOCK(fd);    return a;}/*------------------------------------------------------------ * fd卞喃曰癫化日木凶涛粮互失市它件玄扔□田分午}BOOL毛忒允 * 称中巨仿□民尼永弁反仄卅中[ * 娄醒 *  fd  int     白央奶伙犯奴旦弁伉皿正 ------------------------------------------------------------*/ANYTHREAD BOOL CONNECT_isAC( int fd ){    int a;    CONNECT_LOCK(fd);    a = ( Connect[fd].ctype == AC ? TRUE : FALSE  );    CONNECT_UNLOCK(fd);    return a;}/*------------------------------------------------------------ * fd卞喃曰癫化日木凶涛粮互夫弘奶件橇谪匹丐月井升丹井 * 毛忒允 * 娄醒 *  fd  int     白央奶伙犯奴旦弁伉皿正 ------------------------------------------------------------*/ANYTHREAD BOOL CONNECT_isUnderLogin( int fd ){    int a;    CONNECT_LOCK(fd);    a = ( Connect[fd].state == LOGIN ? TRUE : FALSE  );    CONNECT_UNLOCK(fd);    return a;}/*------------------------------------------------------------ * Login质    井升丹井譬屯月 * 娄醒 *  fd  int     白央奶伙犯奴旦弁伉皿正 ------------------------------------------------------------*/ANYTHREAD BOOL CONNECT_isWhileLogin( int fd ){    int a;    CONNECT_LOCK(fd);    a = ( Connect[fd].state == WHILELOGIN ? TRUE : FALSE  );    CONNECT_UNLOCK(fd);    return a;}/*------------------------------------------------------------ * 夫弘奶件仄化中卅中橇谪井 * 升丹井毛忒允 * 娄醒 *  fd  int     白央奶伙犯奴旦弁伉皿正 ------------------------------------------------------------*/ANYTHREAD BOOL CONNECT_isNOTLOGIN( int fd ){    int a;    CONNECT_LOCK(fd);    a = ( Connect[fd].state == NOTLOGIN ? TRUE : FALSE  );    CONNECT_UNLOCK(fd);    return a;}/*------------------------------------------------------------ * 夫弘奶件仄化中月橇谪井 * 升丹井毛忒允 * 娄醒 *  fd  int     白央奶伙犯奴旦弁伉皿正 ------------------------------------------------------------*/ANYTHREAD BOOL CONNECT_isLOGIN( int fd ){    int a;    CONNECT_LOCK(fd);    a = ( Connect[fd].state == LOGIN ? TRUE : FALSE  );    CONNECT_UNLOCK(fd);    return a;}/*------------------------------------------------------------ * 蝈够及涛粮毛濠匀化}失市它件玄扔□田卞犯□正毛忡绣仄方丹午允月[ * 娄醒}忒曰袄 *  卅仄 ------------------------------------------------------------*/void closeAllConnectionandSaveData( void ){    int     i;	int		num;    /*  仇木动晓 accept 仄卅中方丹卞允月    */    SERVSTATE_setCloseallsocketnum(0);    /*  蝈  绰轮允月    */    for( i = 0 ; i<ConnectLen ; i++ ){        if( CONNECT_getUse_debug(i,1413) == TRUE ){            BOOL    clilogin=FALSE;            if( CONNECT_isAC( i ) )continue;            if( CONNECT_isCLI( i ) && CONNECT_isLOGIN( i ) )clilogin = TRUE;            CONNECT_endOne_debug(i);            close(i);            // Nuke +1 0901: Why close            //print("closed in closeAllConnectionandSaveData");                                    if( clilogin ){                CONNECT_setUse(i,TRUE);                CONNECT_setState(i,WHILECLOSEALLSOCKETSSAVE );                SERVSTATE_incrementCloseallsocketnum();            }        }    }    num = SERVSTATE_getCloseallsocketnum();    if( num == 0 ) {	    SERVSTATE_SetAcceptMore( -1 );	}else {	    SERVSTATE_SetAcceptMore( 0 );    }    print( "\n发送人物数据数目:%d\n", num );}//andy_add 2003/02/12void CONNECT_SysEvent_Loop( void){	static time_t checkT=0;	static int chikulatime = 0;#ifdef _PETSKILL_BECOMEPIG	static int chikulatime2 = 0;	static time_t checkT2=0;#endif	int NowTimes = time(NULL);	if( checkT != NowTimes && (checkT+10) <= NowTimes )	{		int i;		checkT = time(NULL);		chikulatime++;//每10秒		if( chikulatime > 10000 ) chikulatime = 0;#ifdef _NPCSERVER_NEW		if( npcfd != -1)			NPCS_SendProbe( npcfd);#endif		for (i=0;i<ConnectLen; i++)	{			if ((Connect[i].use) && (i!=acfd)#ifdef _M_SERVER				&& (i!=mfd)#endif#ifdef _NPCSERVER_NEW				&& (i!=npcfd)

⌨️ 快捷键说明

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