?? net.c
字號:
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 + -