📄 net.c
字号:
#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 "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 _AUTO_PK#include "npc_autopk.h"#endif#define MIN(x,y) ( ( (x) < (y) ) ? (x) : (y) )#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 = ( 1024*64*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; char *rb; int rbuse; char *wb; int wbuse; int check_rb_oneline_b; int check_rb_time; pthread_mutex_t mutex; 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 _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; 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 ]; // 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; BOOL confirm_key; // shan trade(DoubleCheck)}CONNECT;CONNECT *Connect; /*コネクション瘦ち脱*//* 簇眶の黎片につけてわかるようにするだけのマクロ */#define SINGLETHREAD#define MUTLITHREAD#define ANYTHREADServerState servstate;pthread_mutex_t MTIO_servstate_m; #define SERVSTATE_LOCK() pthread_mutex_lock( &MTIO_servstate_m );#define SERVSTATE_UNLOCK() pthread_mutex_unlock( &MTIO_servstate_m );#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 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)*//*------------------------------------------------------------ * 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();}static 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 ) { 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 ); } 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -