📄 net.c
字号:
CONNECT_LOCK( fd ); *t = Connect[ fd ].lastCDsendtime; CONNECT_UNLOCK( fd );}ANYTHREAD int CONNECT_getUse_debug( int fd, int i ){ int a; CONNECT_LOCK_ARG2( fd, i ); a = Connect[ fd ].use; CONNECT_UNLOCK_ARG2( fd, i ); return a;}ANYTHREAD int CONNECT_getUse( int fd ){ int a; CONNECT_LOCK( fd ); a = Connect[ fd ].use; CONNECT_UNLOCK( fd ); return a;}void CONNECT_setUse( int fd , int a)//ANYTHREAD static void CONNECT_setUse( int fd , int a){ CONNECT_LOCK( fd ); Connect[ fd ].use = a; CONNECT_UNLOCK( fd );}ANYTHREAD void CONNECT_checkStatecount( int a ){ int i; int count = 0; for ( i = 0; i < ConnectLen; i++ ) { if ( Connect[ i ].use == FALSE || Connect[ i ].state != a ) continue; if ( Connect[ i ].nstatecount <= 0 ) { Connect[ i ].nstatecount = ( int ) time( NULL ) + 60; }else{ if ( Connect[ i ].nstatecount < ( int ) time( NULL ) ) { CONNECT_endOne_debug( i ); count++; } } } { memset( StateTable, 0, sizeof( StateTable ) ); for ( i = 0; i < ConnectLen; i++ ) if ( Connect[ i ].use == TRUE ) StateTable[ Connect[ i ].state ] ++; }}ANYTHREAD int CONNECT_checkStateSomeOne( int a, int maxcount){ char temp[ 80 ], buffer[ 1024 ]; int i, ret = 1; if ( StateTable[ a ] >= maxcount ) ret = -1; buffer[ 0 ] = 0; for ( i = 0; i <= WHILESAVEWAIT; i++ ) { sprintf( temp, "%4d", StateTable[ i ] ); strcat( buffer, temp ); } print( "\nNOW{{%s}}", buffer ); return ret;}ANYTHREAD void CONNECT_setState( int fd , int a){ CONNECT_LOCK( fd ); Connect[ fd ].state = a; Connect[ fd ].nstatecount = 0; // Nuke start 0829: For debugging { char temp[80],buffer[128]; int i; memset( StateTable, 0, sizeof( StateTable ) ); for ( i = 0; i < ConnectLen; i++ ) if ( Connect[ i ].use == TRUE ) StateTable[ Connect[ i ].state ] ++; buffer[ 0 ] = 0; for ( i = 0; i <= WHILESAVEWAIT; i++ ) { sprintf( temp, "%4d", StateTable[ i ] ); strcat( buffer, temp ); }// print( "\nFILE:%s,LINE:%d", file,fromline ); print( "\n{{%s}}", buffer ); } // Nuke end CONNECT_UNLOCK( fd );}ANYTHREAD int CONNECT_getState( int fd ){ int a; CONNECT_LOCK( fd ); a = Connect[ fd ].state; CONNECT_UNLOCK( fd ); return a;}ANYTHREAD void CONNECT_incrementErrornum(int fd ){ CONNECT_LOCK( fd ); Connect[ fd ].errornum ++; CONNECT_UNLOCK( fd );}ANYTHREAD void CONNECT_setCharaindex( int fd, int a ){ CONNECT_LOCK( fd ); Connect[ fd ].charaindex = a; CONNECT_UNLOCK( fd );}ANYTHREAD int CONNECT_getCharaindex( int fd ){ int a; CONNECT_LOCK( fd ); a = Connect[ fd ].charaindex; CONNECT_UNLOCK( fd ); return a;}ANYTHREAD void CONNECT_getCdkey( int fd , char *out, int outlen ){ CONNECT_LOCK( fd ); strcpysafe( out, outlen, Connect[ fd ].cdkey ); CONNECT_UNLOCK( fd );}ANYTHREAD void CONNECT_setCdkey( int sockfd, char *cd ){ CONNECT_LOCK( sockfd ); snprintf( Connect[ sockfd ].cdkey, sizeof( Connect[ sockfd ].cdkey ), "%s", cd ); CONNECT_UNLOCK( sockfd );}ANYTHREAD void CONNECT_getPasswd( int fd , char *out, int outlen ){ CONNECT_LOCK( fd ); strcpysafe( out, outlen, Connect[ fd ].passwd ); CONNECT_UNLOCK( fd );}ANYTHREAD void CONNECT_setPasswd( int fd, char *in ){ CONNECT_LOCK( fd ); strcpysafe( Connect[ fd ].passwd, sizeof( Connect[ fd ].passwd ), in ); CONNECT_UNLOCK( fd );}ANYTHREAD int CONNECT_getCtype( int fd ){ int a; CONNECT_LOCK( fd ); a = Connect[ fd ].ctype; CONNECT_UNLOCK( fd ); return a;}ANYTHREAD void CONNECT_setCtype( int fd , int a ){ CONNECT_LOCK( fd ); Connect[ fd ].ctype = a; CONNECT_UNLOCK( fd );}ANYTHREAD void CONNECT_getCharname( int fd , char *out, int outlen ){ CONNECT_LOCK( fd ); strcpysafe( out, outlen, Connect[ fd ].charname ); CONNECT_UNLOCK( fd );}ANYTHREAD void CONNECT_setCharname( int fd, char *in ){ CONNECT_LOCK( fd ); strcpysafe( Connect[ fd ].charname, sizeof( Connect[ fd ].charname ), in ); CONNECT_UNLOCK( fd );}ANYTHREAD int CONNECT_getFdid( int fd ){ int a; CONNECT_LOCK( fd ); a = Connect[ fd ].fdid; CONNECT_UNLOCK( fd ); return a;}ANYTHREAD void CONNECT_setDuelcharaindex( int fd, int i , int a ){ CONNECT_LOCK( fd ); Connect[ fd ].duelcharaindex[ i ] = a; CONNECT_UNLOCK( fd );}ANYTHREAD int CONNECT_getDuelcharaindex( int fd, int i ){ int a; CONNECT_LOCK( fd ); a = Connect[ fd ].duelcharaindex[ i ]; CONNECT_UNLOCK( fd ); return a;}ANYTHREAD void CONNECT_setBattlecharaindex( int fd, int i , int a ){ CONNECT_LOCK( fd ); Connect[ fd ].battlecharaindex[ i ] = a; CONNECT_UNLOCK( fd );}ANYTHREAD int CONNECT_getBattlecharaindex( int fd, int i ){ int a; CONNECT_LOCK( fd ); a = Connect[ fd ].battlecharaindex[ i ]; CONNECT_UNLOCK( fd ); return a;}ANYTHREAD void CONNECT_setJoinpartycharaindex( int fd, int i , int a){ CONNECT_LOCK( fd ); Connect[ fd ].joinpartycharaindex[ i ] = a; CONNECT_UNLOCK( fd );}ANYTHREAD int CONNECT_getJoinpartycharaindex( int fd, int i ){ int a; CONNECT_LOCK( fd ); a = Connect[ fd ].joinpartycharaindex[ i ]; CONNECT_UNLOCK( fd ); return a;}// CoolFish: Trade 2001/4/18ANYTHREAD void CONNECT_setTradecharaindex( int fd, int i , int a ){ CONNECT_LOCK( fd ); Connect[ fd ].tradecharaindex[ i ] = a; CONNECT_UNLOCK( fd );}// Shan BeginANYTHREAD void CONNECT_setLastrecvtime( int fd, struct timeval *a ){ CONNECT_LOCK(fd); Connect[fd].lastrecvtime = *a; CONNECT_UNLOCK(fd);}ANYTHREAD void CONNECT_getLastrecvtime( int fd, struct timeval *a ){ CONNECT_LOCK(fd); *a = Connect[fd].lastrecvtime; CONNECT_UNLOCK(fd);}ANYTHREAD void CONNECT_setLastrecvtime_D( int fd, struct timeval *a ){ CONNECT_LOCK(fd); Connect[fd].lastrecvtime_d = *a; CONNECT_UNLOCK(fd);}ANYTHREAD void CONNECT_getLastrecvtime_D( int fd, struct timeval *a ){ CONNECT_LOCK(fd); *a = Connect[fd].lastrecvtime_d; CONNECT_UNLOCK(fd);}// 2001/12/26ANYTHREAD void CONNECT_SetBattleRecvTime( int fd, struct timeval *a ){ CONNECT_LOCK(fd); Connect[fd].battle_recvtime = *a; CONNECT_UNLOCK(fd);}ANYTHREAD void CONNECT_GetBattleRecvTime( int fd, struct timeval *a ){ CONNECT_LOCK(fd); *a = Connect[fd].battle_recvtime; CONNECT_UNLOCK(fd);}// Shan EndANYTHREAD void CONNECT_setTradeTmp(int fd, char* a){ CONNECT_LOCK(fd); strcpysafe( Connect[fd].TradeTmp, sizeof(Connect[fd].TradeTmp), a); CONNECT_UNLOCK(fd);}ANYTHREAD void CONNECT_getTradeTmp(int fd, char *trademsg, int trademsglen){ CONNECT_LOCK(fd); strcpysafe(trademsg, trademsglen, Connect[fd].TradeTmp); CONNECT_UNLOCK(fd);} ANYTHREAD void CONNECT_setTradecardcharaindex( int fd, int i , int a ){ CONNECT_LOCK(fd); Connect[fd].joinpartycharaindex[i] = a; CONNECT_UNLOCK(fd);}ANYTHREAD int CONNECT_getTradecardcharaindex( int fd, int i ){ int a; CONNECT_LOCK(fd); a = Connect[fd].joinpartycharaindex[i]; CONNECT_UNLOCK(fd); return a;}ANYTHREAD void CONNECT_setCloseRequest( int fd, int count){// print("\n关闭请求设置为 FILE:%s,LINE:%d ", file, line); CONNECT_LOCK(fd); Connect[fd].close_request = count; // Nuke// print("\n关闭请求设置为 %d ",fd); CONNECT_UNLOCK(fd);} /*------------------------------------------------------------ * CAcheck などに蝗われる簇眶。悸狠に流る。 * 苞眶 * fd int ファイルディスクリプタ * 手り猛 * なし ------------------------------------------------------------*/ANYTHREAD void CAsend( int fd ){ char buf[sizeof(Connect[0].CAbuf)]; int bufuse=0; if( CONNECT_getCAbuf( fd, buf, sizeof(buf), &bufuse ) < 0 )return; if( bufuse == 0 )return; //print("\nshan--->(CAsend)->%s fd->%d", buf, fd); /*呵稿のデリミタ ',' を'\0' とかえる*/ buf[bufuse-1] = '\0'; lssproto_CA_send( fd , buf ); CONNECT_setCAbufsiz( fd, 0 ); }/*------------------------------------------------------------ * CAを流る。 * 苞眶 * 手り猛 * なし ------------------------------------------------------------*/ANYTHREAD void CAcheck( void ){ int i; unsigned int interval_us = getCAsendinterval_ms()*1000; /* Connect及蜊醒坌分仃支月井日褐中氏分卅[ */ for( i = 0; i < ConnectLen; i ++) { struct timeval t; if( !CONNECT_getUse_debug(i,1008) )continue; CONNECT_getLastCAsendtime( i, &t ); if( time_diff_us( NowTime, t ) > interval_us ){ CAsend( i); CONNECT_setLastCAsendtime( i, &NowTime ); } }}ANYTHREAD void CAflush( int charaindex ){ int i; i = getfdFromCharaIndex( charaindex); if( i == -1 )return; CAsend(i);}/*------------------------------------------------------------ * CDbuf に纳裁する。 * 苞眶 * fd int ファイルディスクリプタ * data char* デ〖タ * size int デ〖タのサイズ * 手り猛 * 喇根 TRUE(1) * 己窃 FALSE(0) ------------------------------------------------------------*/ANYTHREAD BOOL CONNECT_appendCDbuf( int fd , char* data, int size ){ CONNECT_LOCK(fd); if( ( Connect[fd].CDbufsiz + size ) >= sizeof( Connect[fd].CDbuf )){ CONNECT_UNLOCK(fd); return FALSE; } memcpy( Connect[fd].CDbuf + Connect[fd].CDbufsiz , data, size ); Connect[fd].CDbuf[Connect[fd].CDbufsiz+size] = ','; Connect[fd].CDbufsiz += ( size + 1 ); CONNECT_UNLOCK(fd); return TRUE;}/*------------------------------------------------------------ * CDcheck などに蝗われる簇眶。悸狠に流る。 * 苞眶 * fd int ファイルディスクリプタ * 手り猛 * なし ------------------------------------------------------------*/ANYTHREAD void CDsend( int fd ){ char buf[sizeof(Connect[0].CAbuf )]; int bufuse=0; if( CONNECT_getCDbuf( fd, buf, sizeof(buf), &bufuse ) < 0 ) return; if( bufuse == 0 ) return; 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -