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

📄 net.c

📁 石器时代8.0服务端完整源代码。可以直接编译
💻 C
📖 第 1 页 / 共 5 页
字号:
#define __NET_C__ #include "version.h"#include <stdio.h>#include <stdlib.h>#include <string.h>#include <errno.h>#include <unistd.h>#include <netdb.h>#include <sys/types.h>#include <sys/socket.h>#include <time.h>#include <sys/time.h>#include <netinet/in.h>#include <arpa/inet.h>#include <netinet/tcp.h>     //ttom+1#include <sys/timeb.h>#include "net.h"#include "buf.h"#include "link.h"#include "common.h"#include "msignal.h"#include "configfile.h"#include "util.h"#include "saacproto_cli.h"#include "lssproto_serv.h"#include "char.h"#include "handletime.h"#include "log.h"#include "object.h"#include "item_event.h"#include "enemy.h"// Arminius 7.31 cursed stone#include "battle.h"#include "version.h"#include "pet_event.h"#include "char_talk.h"#include "petmail.h"#ifdef _TEST_PETCREATE#include "chatmagic.h"#endif#ifdef _M_SERVER#include "mclient.h"#endif#ifdef _NPCSERVER_NEW#include "npcserver.h"#endif#define MIN(x,y)     ( ( (x) < (y) ) ? (x) : (y) )#define IS_2BYTEWORD( _a_ ) ( (char)(0x80) <= (_a_) && (_a_) <= (char)(0xFF) )#ifdef	_NEW_SERVER_BOOL bNewServer = TRUE;#elseBOOL bNewServer = FALSE;#endif // Nuke +1 0901: For state monitorint StateTable[WHILESAVEWAIT+1];int ITEM_getRatio();int CHAR_players();#define CONO_CHECK_LOGIN 0x001#define CONO_CHECK_ITEM 0x010#define CONO_CHECK_PET 0x100int cono_check=0x111;int     AC_WBSIZE = (65536*16);//ttom+1 for the performatcestatic unsigned int MAX_item_use=0;int i_shutdown_time=0;//ttomBOOL b_first_shutdown=FALSE;//ttomint mfdfulll = 0;/*------------------------------------------------------------ * 扔□田及橇谪 ------------------------------------------------------------*/typedef struct tag_serverState{    BOOL            acceptmore;     /*  1分匀凶日}accept 仄凶丐午                                        切斤仁匹}close 允月 */    unsigned int    fdid;           /*  fd 及骚曰袄 */    unsigned int    closeallsocketnum;  /*   closeallsocket   及酸曰及                                             醒*/	int				shutdown;		/*  扔□田毛shutdown允月乒□玉 									 *	0:骚橘 公木动陆:扑乓永玄扑乓永玄乒□玉									 * 乒□玉卞卅匀凶凛棉互  匀化月[									 */	int				dsptime;		/* shutdown 乒□玉及伐□弁  醒*/	int				limittime;		/* 仇木手 */}ServerState;typedef struct tagCONNECT{    BOOL  use;#if USE_MTIO#define MTIO_FIXED_BUFSIZE (65536)    char rb[MTIO_FIXED_BUFSIZE];    int rbuse;    char wb[MTIO_FIXED_BUFSIZE];    int wbuse;    pthread_mutex_t mutex;    /* Connect毛中元月午五卞勾井丹夫永弁 */#else    char *rb;    int rbuse;    char *wb;    int wbuse;    int check_rb_oneline_b;	int check_rb_time;#endif        struct sockaddr_in sin; /* 涛粮燮及失玉伊旦 */    ConnectType ctype;       /* 戊生弁扑亦件及潘   */    char    cdkey[CDKEYLEN];    /* CDKEY */    char    passwd[PASSWDLEN];  /* 由旦伐□玉 */    LoginType state;        /* 蜇箕及夫弘奶件橇谪 */	int		nstatecount;    char    charname[CHARNAMELEN];  /* 夫弘奶件  及平乓仿   */    int     charaindex;     /* char    尺及奶件犯永弁旦[                             * 夫弘奶件  卞袄互涩烂今木月[-1互犯白巧伙玄                             *     卞卅中凛[                             */    char    CAbuf[2048];         /*  CA() 毛做谅允月啃及田永白央 */    int     CAbufsiz;       /*  CAbuf 及扔奶术  */    struct timeval  lastCAsendtime;     /*    卞CA毛霜匀凶凛棉 */    char    CDbuf[2048];         /*  CD() 毛做谅允月啃及田永白央 */    int     CDbufsiz;       /*  CDbuf 及扔奶术  */    struct timeval  lastCDsendtime;     /*    卞CD毛霜匀凶凛棉 */    struct timeval  lastCharSaveTime; /*     卞平乓仿犯□正毛本□皮仄凶凛棉 */        struct timeval  lastprocesstime;    /*     卞皿夫玄戊伙毛质  仄凶凛棉*/    struct timeval  lastreadtime;       /*     卞read仄凶凛棉[晓午反切互丹*/        // Nuke start 08/27 : For acceleration avoidance    // WALK_TOLERANCE: Permit n W messages in a second (3: is the most restricted)    #define WALK_TOLERANCE 4    #define WALK_SPOOL 5    #define WALK_RESTORE 100    unsigned int        Walktime;    unsigned int        lastWalktime;    unsigned int        Walkcount;    int Walkspool;      // For walk burst after release key F10    int Walkrestore;    // B3_TOLERANCE: Time distance between recently 3 B message (8: is the latgest)    // BEO_TOLERANCE: Time distance between the lastmost B and EO (5: is the largest)    #define B3_TOLERANCE 5    #define BEO_TOLERANCE 3    #define BEO_SPOOL 10    #define BEO_RESTORE 100    unsigned int        Btime;    unsigned int        lastBtime;    unsigned int        lastlastBtime;    unsigned int        EOtime;#ifdef _BATTLE_TIMESPEED//	unsigned int		DefBtime;	int		BDTime;	int		CBTime;#endif#ifdef _TYPE_TOXICATION	int		toxication;#endif#ifdef _CHECK_GAMESPEED	int		gamespeed;#endif#ifdef _ITEM_ADDEXP	//vincent 经验提升	int		EDTime;#endif    //    unsigned int      BEO;    int BEOspool;    int BEOrestore;    // Nuke 0219: Avoid cheating    int die;    // Nuke end    // Nuke 0310    int credit;    int fcold;    // Nuke 0406: New Flow Control    int nu;    int nu_decrease;    int ke;    // Nuke 1213: Flow Control 2    int packetin;    // Nuke 0624: Avoid Null Connection    unsigned int cotime;    // Nuke 0626: For no enemy    int noenemy;    // Arminius 7.2: Ra's amulet    int eqnoenemy;#ifdef _Item_MoonAct	int eqrandenemy;#endif#ifdef _CHIKULA_STONE	int chistone;#endif	// Arminius 7.31: cursed stone    int stayencount;    /* close 允月屯五井升丹井及筏盛 */#if USE_MTIO        int     closed;#endif    	int		battlecharaindex[CONNECT_WINDOWBUFSIZE];	int		duelcharaindex[CONNECT_WINDOWBUFSIZE];				int		tradecardcharaindex[CONNECT_WINDOWBUFSIZE];			int		joinpartycharaindex[CONNECT_WINDOWBUFSIZE];			// CoolFish: Trade 2001/4/18	int		tradecharaindex[CONNECT_WINDOWBUFSIZE];    int     errornum;    int     fdid;        int     close_request; //the second have this        int appendwb_overflow_flag;  /* 1荚匹手appendWb互撩  仄凶日1卞允月 */    //ttom+1 avoidance the watch the battle be kept out    BOOL in_watch_mode;    BOOL b_shut_up;//for avoid the user wash the screen    BOOL b_pass;      //for avoid the unlimited area    struct timeval Wtime;    struct timeval WLtime;    BOOL b_first_warp;    int  state_trans;        // CoolFish: Trade 2001/4/18    char TradeTmp[256];#ifdef _ITEM_PILEFORTRADE	int tradelist;#endif    // Shan Recvdata Time    struct timeval lastrecvtime;      // 'FM' Stream Control time    struct timeval lastrecvtime_d;    // DENGON Talk Control time    // Arminius: 6.22 encounter    int CEP;	// Current Encounter Probability    // Arminius 7.12 login announce    int announced;	// shan battle delay time 2001/12/26    struct timeval battle_recvtime;#ifdef _NO_WARP	// shan hjj add Begin 	int seqno;    int selectbutton;	// shan End#endif		BOOL confirm_key;    // shan  trade(DoubleCheck)#ifdef _BLACK_MARKET	int  BMSellList[12];#endif}CONNECT;CONNECT *Connect;      /*戊生弁扑亦件忡切迕*//* 楮醒及燮  卞勾仃化歹井月方丹卞允月分仃及穴弁夫 */#define SINGLETHREAD#define MUTLITHREAD#define ANYTHREADServerState servstate;#if USE_MTIOpthread_mutex_t MTIO_servstate_m;     /* servstate 及夫永弁 */#define SERVSTATE_LOCK() pthread_mutex_lock( &MTIO_servstate_m );#define SERVSTATE_UNLOCK() pthread_mutex_unlock( &MTIO_servstate_m );#if 1#define CONNECT_LOCK_ARG2(i,j) fprintf(stderr,"LO T:%d(%d:%d) %s %d", (int)pthread_self(), i,j, __FILE__,__LINE__ );pthread_mutex_lock( &Connect[i].mutex );fprintf( stderr, "CK T:%d(%d:%d)\n" , (int)pthread_self(), i,j );#define CONNECT_UNLOCK_ARG2(i,j) fprintf(stderr,"UNLO T:%d(%d:%d) %s %d", (int)pthread_self(), i,j, __FILE__,__LINE__ );pthread_mutex_unlock( &Connect[i].mutex );fprintf( stderr, "CK T:%d(%d:%d)\n",(int)pthread_self(), i,j);#define CONNECT_LOCK(i) fprintf(stderr,"LO T:%d(%d) %s %d", (int)pthread_self(), i, __FILE__,__LINE__ );pthread_mutex_lock( &Connect[i].mutex );fprintf( stderr, "CK T:%d(%d)\n" ,(int)pthread_self(), i );#define CONNECT_UNLOCK(i) fprintf(stderr,"UNLO T:%d(%d) %s %d", (int)pthread_self(), i, __FILE__,__LINE__ );pthread_mutex_unlock( &Connect[i].mutex );fprintf( stderr, "CK T:%d(%d)\n",(int)pthread_self(), i);/* 晓筏及夫弘反户切扎仁切扎犯奴旦弁毛罹丹及匹旦伉□皿毛中木凶曰 */#define MTIO_DEBUG_LOG_REDUCE 1#else#define CONNECT_LOCK_ARG2(i,j) pthread_mutex_lock( &Connect[i].mutex );#define CONNECT_UNLOCK_ARG2(i,j) pthread_mutex_unlock( &Connect[i].mutex );#define CONNECT_LOCK(i) pthread_mutex_lock( &Connect[i].mutex );#define CONNECT_UNLOCK(i) pthread_mutex_unlock( &Connect[i].mutex );#define MTIO_DEBUG_LOG_REDUCE 0#endif#else#define SERVSTATE_LOCK()#define SERVSTATE_UNLOCK()#define CONNECT_LOCK_ARG2(i,j) #define CONNECT_UNLOCK_ARG2(i,j)#define CONNECT_LOCK(i) #define CONNECT_UNLOCK(i)#endif#ifdef _CHECK_BATTLE_IOint InBattleLoop =FALSE;int battle_write =0;int other_write =0;int battle_write_cnt =0;int other_write_cnt =0;#endif/*------------------------------------------------------------ * servstate毛赓渝祭允月[ * 娄醒}忒曰袄 *  卅仄 ------------------------------------------------------------*/ANYTHREAD static void SERVSTATE_initserverState( void ){    SERVSTATE_LOCK();    servstate.acceptmore = TRUE;    servstate.fdid = 0;    servstate.closeallsocketnum = -1;	servstate.shutdown = 0;	servstate.limittime = 0;	servstate.dsptime = 0;    SERVSTATE_UNLOCK();    }ANYTHREAD int SERVSTATE_SetAcceptMore( int nvalue ){    BOOL buf;    SERVSTATE_LOCK();    buf = servstate.acceptmore;    servstate.acceptmore = nvalue;    SERVSTATE_UNLOCK();    return buf;}ANYTHREAD static int SERVSTATE_incrementFdid( void ){    int ret;    SERVSTATE_LOCK();    ret = servstate.fdid++;    SERVSTATE_UNLOCK();    return ret;}ANYTHREAD static void SERVSTATE_setCloseallsocketnum( int a ){    SERVSTATE_LOCK();    servstate.closeallsocketnum = a;    SERVSTATE_UNLOCK();}ANYTHREAD static void SERVSTATE_incrementCloseallsocketnum(void){    SERVSTATE_LOCK();    servstate.closeallsocketnum ++;    SERVSTATE_UNLOCK();    }ANYTHREAD void SERVSTATE_decrementCloseallsocketnum(void){    SERVSTATE_LOCK();    servstate.closeallsocketnum --;    SERVSTATE_UNLOCK();    }ANYTHREAD int SERVSTATE_getCloseallsocketnum( void ){    int a;    SERVSTATE_LOCK();    a = servstate.closeallsocketnum;    SERVSTATE_UNLOCK();    return a;}ANYTHREAD static int SERVSTATE_getAcceptmore(void){    int a;    SERVSTATE_LOCK();    a = servstate.acceptmore;    SERVSTATE_UNLOCK();    return a;}ANYTHREAD int SERVSTATE_getShutdown(void){    int a;    SERVSTATE_LOCK();    a = servstate.shutdown;    SERVSTATE_UNLOCK();    return a;    }ANYTHREAD void SERVSTATE_setShutdown(int a){    SERVSTATE_LOCK();    servstate.shutdown = a;    SERVSTATE_UNLOCK();    }ANYTHREAD int SERVSTATE_getLimittime(void){    int a;    SERVSTATE_LOCK();    a = servstate.limittime;    SERVSTATE_UNLOCK();    return a;        }ANYTHREAD void SERVSTATE_setLimittime(int a){    SERVSTATE_LOCK();    servstate.limittime = a;    SERVSTATE_UNLOCK();}ANYTHREAD int SERVSTATE_getDsptime(void){    int a;    SERVSTATE_LOCK();    a = servstate.dsptime;    SERVSTATE_UNLOCK();    return a;        }ANYTHREAD void SERVSTATE_setDsptime(int a){    SERVSTATE_LOCK();    servstate.dsptime = a;    SERVSTATE_UNLOCK();}#if USE_MTIO == 0static int appendWB( int fd, char *buf, int size ){	if( fd != acfd ) {	    if( Connect[fd].wbuse + size >= WBSIZE ) {			print( "appendWB:err buffer over[%d]:%s \n",				Connect[fd].wbuse + size, Connect[fd].cdkey );		    	return -1;	    }	}else {	    if( Connect[fd].wbuse + size > AC_WBSIZE ) {			FILE *fp=NULL;			print( "appendWB:err buffer over[%d+%d]:(SAAC) \n", Connect[fd].wbuse, size);			if( (fp=fopen("appendWBerr.log", "a+"))==NULL) return -1;			fprintf( fp, "(SAAC) appendWB:err buffer over[%d+%d/%d]:\n", Connect[fd].wbuse, size, AC_WBSIZE);			fclose( fp);	    	return -1;	    }	}	    memcpy( Connect[fd].wb + Connect[fd].wbuse ,            buf, size );    Connect[fd].wbuse += size;    return size;}static int appendRB( int fd, char *buf, int size ){	if( fd != acfd ) {	    if( Connect[fd].rbuse + size > RBSIZE ) {			if( fd == mfd )	print( "appendRB:MSERVER err buffer over \n");			else print( "appendRB:OTHER(%d) err buffer over \n", fd);			return -1;	    }	}else {		if( strlen( buf) > size ){			print( "appendRB AC buffer len err : %d/%d=\n(%s)!!\n", strlen( buf), size, buf);

⌨️ 快捷键说明

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