?? net.c
字號(hào):
} if( Connect[fd].rbuse + size > AC_RBSIZE ) { print( "appendRB AC err buffer over:\n(%s)\n len:%d - rbuse:%d \n", buf, strlen(buf), Connect[fd].rbuse); return -1; } } memcpy( Connect[fd].rb + Connect[fd].rbuse , buf, size ); Connect[fd].rbuse += size; return size;}static int shiftWB( int fd, int len ){ if( Connect[fd].wbuse < len ) { print( "shiftWB: err\n"); return -1; } memmove( Connect[fd].wb, Connect[fd].wb + len, Connect[fd].wbuse - len ); Connect[fd].wbuse -= len; if( Connect[fd].wbuse < 0 ) { print( "shiftWB:wbuse err\n"); Connect[fd].wbuse = 0; } return len;}static int shiftRB( int fd, int len ){ if( Connect[fd].rbuse < len ) { print( "shiftRB: err\n"); return -1; } memmove( Connect[fd].rb, Connect[fd].rb + len, Connect[fd].rbuse - len ); Connect[fd].rbuse -= len; if( Connect[fd].rbuse < 0 ) { print( "shiftRB:rbuse err\n"); Connect[fd].rbuse = 0; } return len;}SINGLETHREAD int lsrpcClientWriteFunc( int fd , char* buf , int size ){ int r; if( Connect[fd].use == FALSE ){ return FALSE; } if( Connect[fd].appendwb_overflow_flag ){ print( "lsrpcClientWriteFunc: buffer overflow fd:%d\n" , fd ); return -1; } r = appendWB( fd, buf , size); // Nuke *1 0907: Ignore acfd from WB error if(( r < 0 ) && (fd != acfd)) { Connect[fd].appendwb_overflow_flag = 1; CONNECT_endOne_debug(fd); close(fd); // Nuke + 1 0901: Why close // print("closed in lsrpcClientWriteFunc"); } return r;}static int logRBuseErr = 0;SINGLETHREAD BOOL GetOneLine_fix( int fd, char *buf, int max ){ int i; if( Connect[fd].rbuse == 0 ) return FALSE; if( Connect[fd].check_rb_oneline_b == 0 && Connect[fd].check_rb_oneline_b == Connect[fd].rbuse ){ return FALSE; } for( i = 0; i < Connect[fd].rbuse && i < ( max -1); i ++ ){ if( Connect[fd].rb[i] == '\n' ){ memcpy( buf, Connect[fd].rb, i+1); buf[i+1]='\0'; shiftRB( fd, i+1 );//--------/* //andy_log if( strstr( Connect[fd].rb , "ACCharLoad") != NULL && Connect[fd].check_rb_oneline_b != 0 )//Connect[fd].rb LogAcMess( fd, "GetOne", Connect[fd].rb );*///-------- logRBuseErr = 0; Connect[fd].check_rb_oneline_b=0; Connect[fd].check_rb_time = 0; return TRUE; } } //print("rbuse lens: %d!!\n", Connect[fd].rbuse); logRBuseErr++;//-------- //andy_log if( fd == acfd && strstr( Connect[fd].rb , "ACCharLoad") != NULL && logRBuseErr >= 50 ){//Connect[fd].rb char buf[AC_RBSIZE]; memcpy( buf, Connect[fd].rb, Connect[fd].rbuse+1); buf[Connect[fd].rbuse+1]=0; LogAcMess( fd, "RBUFFER", buf ); logRBuseErr=0; }//-------- Connect[fd].check_rb_oneline_b = Connect[fd].rbuse; return FALSE;}#endif /* if USE_MTIO == 0*/ANYTHREAD BOOL initConnectOne( int sockfd, struct sockaddr_in* sin ,int len ){ CONNECT_LOCK(sockfd); Connect[sockfd].use = TRUE; Connect[sockfd].ctype = NOTDETECTED;#if USE_MTIO Connect[sockfd].closed = 0; #else Connect[sockfd].wbuse = Connect[sockfd].rbuse = 0; Connect[sockfd].check_rb_oneline_b = 0; Connect[sockfd].check_rb_time = 0;#endif memset( Connect[sockfd].cdkey , 0 , sizeof( Connect[sockfd].cdkey ) ); memset( Connect[sockfd].passwd, 0 , sizeof( Connect[sockfd].passwd) ); Connect[sockfd].state = NOTLOGIN; Connect[sockfd].nstatecount = 0; memset( Connect[sockfd].charname,0, sizeof(Connect[sockfd].charname)); Connect[sockfd].charaindex = -1; Connect[sockfd].CAbufsiz = 0; Connect[sockfd].CDbufsiz = 0; Connect[sockfd].rbuse = 0; Connect[sockfd].wbuse = 0; Connect[sockfd].check_rb_oneline_b = 0; Connect[sockfd].check_rb_time = 0; Connect[sockfd].close_request = 0; /* 濠蠅邰菲白仿弘 */ // Nuke 08/27 For acceleration avoidance Connect[sockfd].Walktime = 0; Connect[sockfd].lastWalktime = 0; Connect[sockfd].Walkcount = 0; Connect[sockfd].Walkspool = WALK_SPOOL; Connect[sockfd].Walkrestore = WALK_RESTORE; Connect[sockfd].Btime = 0; Connect[sockfd].lastBtime = 0; Connect[sockfd].lastlastBtime = 0; Connect[sockfd].EOtime = 0; Connect[sockfd].nu_decrease = 0;#ifdef _BATTLE_TIMESPEED// Connect[sockfd].DefBtime = 0; Connect[sockfd].BDTime = 0; Connect[sockfd].CBTime = 0;#endif#ifdef _CHECK_GAMESPEED Connect[sockfd].gamespeed = 0;#endif#ifdef _TYPE_TOXICATION Connect[sockfd].toxication = 0;#endif#ifdef _ITEM_ADDEXP //vincent 經(jīng)驗(yàn)提升 Connect[sockfd].EDTime = 0;#endif// Connect[sockfd].BEO = 0; Connect[sockfd].BEOspool = BEO_SPOOL; Connect[sockfd].BEOrestore = BEO_RESTORE; //ttom Connect[sockfd].b_shut_up=FALSE; Connect[sockfd].Wtime.tv_sec=0;// Connect[sockfd].Wtime.tv_usec=0;// Connect[sockfd].WLtime.tv_sec=0;// Connect[sockfd].WLtime.tv_usec=0;// Connect[sockfd].b_first_warp=FALSE; Connect[sockfd].state_trans=0;//avoid the trans // Nuke Connect[sockfd].die=0; Connect[sockfd].credit=3; Connect[sockfd].fcold=0; // Nuke 0406: New Flow Control Connect[sockfd].nu=30; Connect[sockfd].ke=10; // Nuke 1213: Flow Control 2 Connect[sockfd].packetin=30; // if 10x10 seconds no packet, drop the line // Nuke 0624: Avoid Useless Connection Connect[sockfd].cotime=0; // Nuke 0626: For no enemy Connect[sockfd].noenemy=0; // Arminius 7.2: Ra's amulet Connect[sockfd].eqnoenemy = 0;#ifdef _Item_MoonAct Connect[sockfd].eqrandenemy = 0;#endif#ifdef _CHIKULA_STONE Connect[sockfd].chistone = 0;#endif // Arminius 7.31: cursed stone Connect[sockfd].stayencount = 0; // CoolFish: Init Trade 2001/4/18 memset(&Connect[sockfd].TradeTmp, 0, sizeof(Connect[sockfd].TradeTmp));#ifdef _ITEM_PILEFORTRADE Connect[sockfd].tradelist = -1;#endif // Arminius 6.22 Encounter Connect[sockfd].CEP = 0; // Arminius 7.12 login announce Connect[sockfd].announced=0;#ifdef _NO_WARP // shan hjj add Begin Connect[sockfd].seqno=-1; Connect[sockfd].selectbutton=1; // shan End#endif Connect[sockfd].confirm_key=FALSE; // shan trade(DoubleCheck) if( sin != NULL )memcpy( &Connect[sockfd].sin , sin , len ); memset( &Connect[sockfd].lastprocesstime, 0 , sizeof(Connect[sockfd].lastprocesstime) ); memcpy( &Connect[sockfd].lastCAsendtime, &NowTime , sizeof(Connect[sockfd].lastCAsendtime) ); memcpy( &Connect[sockfd].lastCDsendtime, &NowTime , sizeof(Connect[sockfd].lastCDsendtime) ); memcpy( &Connect[sockfd].lastCharSaveTime, &NowTime , sizeof(Connect[sockfd].lastCharSaveTime) ); // Shan Add memcpy( &Connect[sockfd].lastrecvtime, &NowTime , sizeof(Connect[sockfd].lastrecvtime) ); memcpy( &Connect[sockfd].lastrecvtime_d, &NowTime , sizeof(Connect[sockfd].lastrecvtime_d) ); memcpy( &Connect[sockfd].battle_recvtime, &NowTime , sizeof(Connect[sockfd].battle_recvtime) );#ifdef _BLACK_MARKET { int i; for(i=0; i<12; i++) Connect[sockfd].BMSellList[i] = -1; }#endif memcpy( &Connect[sockfd].lastreadtime , &NowTime, sizeof(struct timeval)); Connect[sockfd].lastreadtime.tv_sec -= DEBUG_ADJUSTTIME; Connect[sockfd].errornum = 0; Connect[sockfd].fdid = SERVSTATE_incrementFdid(); CONNECT_UNLOCK(sockfd); Connect[sockfd].appendwb_overflow_flag = 0; return TRUE;}ANYTHREAD BOOL _CONNECT_endOne( char *file, int fromline, int sockfd , int line ){ CONNECT_LOCK_ARG2(sockfd,line); if( Connect[sockfd].use == FALSE ){ CONNECT_UNLOCK_ARG2(sockfd,line); //andy_log print("連接已關(guān)閉[%d]!!\n", sockfd ); return TRUE; } Connect[sockfd].use = FALSE; if( Connect[sockfd].ctype == CLI && Connect[sockfd].charaindex >= 0 ){ CONNECT_UNLOCK_ARG2( sockfd,line ); if( !CHAR_logout( sockfd,TRUE )) { print( "err %s:%d from %s:%d \n", __FILE__, __LINE__, file, fromline); } CONNECT_LOCK_ARG2( sockfd ,line); } unsigned long ip; int a,b,c,d; int i; ip=CONNECT_get_userip(sockfd); a=(ip % 0x100); ip=ip / 0x100; b=(ip % 0x100); ip=ip / 0x100; c=(ip % 0x100); ip=ip / 0x100; d=(ip % 0x100); print( "賬號(hào)=%s 編號(hào)=%d\n", Connect[sockfd].cdkey,sockfd ); for(i=0;i<getMaxLockip();i++) if(cmpLockip(i,a,b,c,d,0))return;#if USE_MTIO == 0 Connect[sockfd].rbuse = Connect[sockfd].wbuse = 0;#else Connect[sockfd].wbuse = Connect[sockfd].rbuse = 0;#endif Connect[sockfd].CAbufsiz = 0; Connect[sockfd].CDbufsiz = 0; CONNECT_UNLOCK_ARG2(sockfd,line); return TRUE;}SINGLETHREAD BOOL initConnect( int size ){ int i,j; ConnectLen = size; Connect = calloc( 1, sizeof( CONNECT ) * size ); if( Connect == NULL )return FALSE; for( i = 0 ; i < size ; i ++ ){ memset( &Connect[i] , 0 , sizeof( CONNECT ) ); Connect[i].charaindex = -1; Connect[i].rb = calloc( 1, RBSIZE); if( Connect[i].rb == NULL ) { fprint( "calloc err\n"); for( j = 0; j < i ; j ++ ) { free( Connect[j].rb); free( Connect[j].wb); } return FALSE; } memset( Connect[i].rb, 0, RBSIZE); Connect[i].wb = calloc( 1, WBSIZE); if( Connect[i].wb == NULL ) { fprint( "calloc err\n"); for( j = 0; j < i ; j ++ ) { free( Connect[j].rb); free( Connect[j].wb); } free( Connect[j].rb); return FALSE; } memset( Connect[i].wb, 0, WBSIZE); }#if USE_MTIO for( i = 0 ;i < size ; i ++ ){ pthread_mutex_init( & Connect[i].mutex , NULL ); }#endif SERVSTATE_initserverState( ); //ttom for the performance of gmsv MAX_item_use=getItemnum()*0.98; return TRUE;}BOOL CONNECT_acfdInitRB( int fd ){ if( fd != acfd ) return FALSE; Connect[fd].rb = realloc( Connect[acfd].rb, AC_RBSIZE); if( Connect[acfd].rb == NULL ) { fprint( "realloc err\n"); return FALSE; } memset( Connect[acfd].rb, 0, AC_RBSIZE); return TRUE;}BOOL CONNECT_acfdInitWB( int fd ){ if( fd != acfd ) return FALSE; Connect[fd].wb = realloc( Connect[acfd].wb, AC_WBSIZE); if( Connect[acfd].wb == NULL ) { fprint( "realloc err\n"); return FALSE; } memset( Connect[acfd].wb, 0, AC_WBSIZE); return TRUE;}ANYTHREAD void endConnect( void ){ int i; for(i = 0 ; i < ConnectLen ; i ++ ){ int lco; lco = close( i ); if( lco == 0 ){ CONNECT_endOne_debug(i); } free( Connect[i].rb); free( Connect[i].wb); } free(Connect);}ANYTHREAD BOOL CONNECT_appendCAbuf( int fd , char* data, int size ){ CONNECT_LOCK(fd); /* 及犯伉立正及 ',' 及坌聶仁割忡仄卅中井氏儀卞鏜啦 */ if( (Connect[fd].CAbufsiz + size) >= sizeof( Connect[fd].CAbuf ) ){ CONNECT_UNLOCK(fd); return FALSE; } memcpy( Connect[fd].CAbuf + Connect[fd].CAbufsiz , data , size ); Connect[fd].CAbuf[Connect[fd].CAbufsiz+size]=','; Connect[fd].CAbufsiz += (size + 1); CONNECT_UNLOCK(fd); return TRUE;}ANYTHREAD static int CONNECT_getCAbuf( int fd, char *out, int outmax, int *outlen ){ CONNECT_LOCK(fd); if( Connect[fd].use == TRUE ){ int cplen = MIN( outmax, Connect[fd].CAbufsiz ); memcpy( out, Connect[fd].CAbuf , cplen ); *outlen = cplen; CONNECT_UNLOCK(fd); return 0; } else { CONNECT_UNLOCK(fd); return -1; }}ANYTHREAD static int CONNECT_getCDbuf( int fd, char *out, int outmax, int *outlen ){ CONNECT_LOCK(fd); if( Connect[fd].use == TRUE ){ int cplen = MIN( outmax, Connect[fd].CDbufsiz ); memcpy( out, Connect[fd].CDbuf, cplen ); *outlen = cplen; CONNECT_UNLOCK(fd); return 0; } else { CONNECT_UNLOCK(fd); return 0; }}ANYTHREAD static int CONNECT_setCAbufsiz( int fd, int len ){ CONNECT_LOCK(fd); if( Connect[fd].use == TRUE ){ Connect[fd].CAbufsiz = len; CONNECT_UNLOCK(fd); return 0; } else { CONNECT_UNLOCK(fd); return -1; }}ANYTHREAD static int CONNECT_setCDbufsiz( int fd, int len ){ CONNECT_LOCK(fd); if( Connect[fd].use == TRUE ){ Connect[fd].CDbufsiz = len; CONNECT_UNLOCK(fd); return 0; } else { CONNECT_UNLOCK(fd); return -1; } }ANYTHREAD static void CONNECT_setLastCAsendtime( int fd, struct timeval *t)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -