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

📄 net.c

📁 石器时代2.0完整版源代码.已经加入新功能. 在REDHAT9下GCC3.4编译成功.
💻 C
📖 第 1 页 / 共 5 页
字号:
                && 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 {        ;    }}/*------------------------------------------------------------ * 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);            // 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;    for ( i = 0;i < ConnectLen; i++ ) {      if ( ( Connect[ i ].use ) && ( i != acfd )) {        if ( chikulatime % 6 == 0 ) { // 每60秒          // shan 2001/12/27 Begin          if ( CHAR_getWorkInt( Connect[ i ].charaindex, CHAR_WORKBATTLEMODE )               != BATTLE_CHARMODE_NONE ) {            struct timeval recvtime;            CONNECT_GetBattleRecvTime( i, &recvtime );            if ( time_diff( NowTime, recvtime ) > 360 ) {              CONNECT_endOne_debug( i );            }          }          // End        } //%30        if ( chikulatime % 30 == 0 ) { // 每300秒#ifdef _ITEM_ADDEXP	//vincent 经验提升          if ( CHAR_getWorkInt( Connect[ i ].charaindex, CHAR_WORKITEM_ADDEXP ) > 0 &&               CHAR_getInt( Connect[ i ].charaindex, CHAR_WHICHTYPE ) == CHAR_TYPEPLAYER ) {#if 1            int charaindex, exptime;            charaindex = Connect[ i ].charaindex;            exptime = CHAR_getWorkInt( charaindex, CHAR_WORKITEM_ADDEXPTIME ) - 300;            if ( exptime <= 0 ) {              CHAR_setWorkInt( charaindex, CHAR_WORKITEM_ADDEXP, 0 );              CHAR_setWorkInt( charaindex, CHAR_WORKITEM_ADDEXPTIME, 0 );			  CHAR_talkToCli( charaindex,-1,"提升学习经验的能力消失了!",CHAR_COLORYELLOW);            }            else {              CHAR_setWorkInt( charaindex, CHAR_WORKITEM_ADDEXPTIME, exptime );              //print("\n 检查ADDEXPTIME %d ", exptime);							              if ( ( exptime % ( 60 * 60 ) ) < 300 && exptime >= ( 60 * 60 ) ) {                char msg[ 1024 ];				sprintf( msg, "提升学习经验的能力剩大约 %d 小时。", (int)(exptime/(60*60)) );				//sprintf( msg, "提升学习经验的能力剩大约 %d 分。", (int)(exptime/(60)) );                CHAR_talkToCli( charaindex, -1, msg, CHAR_COLORYELLOW );              }            }#else            if ( Connect[ i ].EDTime < CHAR_getWorkInt( Connect[ i ].charaindex, CHAR_WORKITEM_ADDEXPTIME ) ) { //功能作用有效期限              Connect[ i ].EDTime = Connect[ i ].EDTime + 300;						}else{              Connect[ i ].EDTime = 0;              CHAR_setWorkInt( Connect[ i ].charaindex, CHAR_WORKITEM_ADDEXP, 0 );              CHAR_setWorkInt( Connect[ i ].charaindex, CHAR_WORKITEM_ADDEXPTIME, 0 );              CHAR_talkToCli( Connect[ i ].charaindex, -1, "提昇学习经验的能力消失了!", CHAR_COLORYELLOW );            }#endif          }#endif#ifdef _ITEM_METAMO          if ( CHAR_getWorkInt( Connect[ i ].charaindex, CHAR_WORKITEMMETAMO ) < NowTime.tv_sec               && CHAR_getWorkInt( Connect[ i ].charaindex, CHAR_WORKITEMMETAMO ) != 0 ) {            CHAR_setWorkInt( Connect[ i ].charaindex, CHAR_WORKITEMMETAMO, 0 );            CHAR_setWorkInt( Connect[ i ].charaindex, CHAR_WORKNPCMETAMO, 0 ); //与npc对话後的变身也要变回来            CHAR_complianceParameter( Connect[ i ].charaindex );            CHAR_sendCToArroundCharacter( CHAR_getWorkInt( Connect[ i ].charaindex , CHAR_WORKOBJINDEX ) );            CHAR_send_P_StatusString( Connect[ i ].charaindex , CHAR_P_STRING_BASEBASEIMAGENUMBER );            CHAR_talkToCli( Connect[ i ].charaindex, -1, "变身失效了。", CHAR_COLORWHITE );          }#endif#ifdef _ITEM_TIME_LIMIT          ITEM_TimeLimit( Connect[ i ].charaindex ); // (可开放) shan time limit of item. code:shan#endif        } //%30#ifndef _USER_CHARLOOPS        //here 原地遇敌        if ( Connect[ i ].stayencount ) {          if ( Connect[ i ].BDTime < time( NULL ) ) {            if ( CHAR_getWorkInt( Connect[ i ].charaindex, CHAR_WORKBATTLEMODE ) == BATTLE_CHARMODE_NONE ) {              lssproto_EN_recv( i, CHAR_getInt( Connect[ i ].charaindex, CHAR_X ),                                CHAR_getInt( Connect[ i ].charaindex, CHAR_Y ) );              Connect[ i ].BDTime = time( NULL );            }          }        }#endif#ifdef _CHIKULA_STONE        if ( chikulatime % 3 == 0 && getChiStone( i ) > 0 ) { //自动补血          CHAR_AutoChikulaStone( Connect[ i ].charaindex, getChiStone( i ) );        }#endif        if ( chikulatime % 6 == 0 ) { //水世界状态          // Nuke 0626: No enemy          if ( Connect[ i ].noenemy > 0 ) {            Connect[ i ].noenemy--;            if ( Connect[ i ].noenemy == 0 ) {              CHAR_talkToCli( CONNECT_getCharaindex( i ), -1, "守护消失了。", CHAR_COLORWHITE );            }          }        }        //每10秒#ifdef _TYPE_TOXICATION //中毒        if ( Connect[ i ].toxication > 0 ) {          CHAR_ComToxicationHp( Connect[ i ].charaindex );        }#endif        // Nuke 0624 Avoid Useless Connection        if ( Connect[ i ].state == NOTLOGIN ) {          Connect[ i ].cotime++;          if ( Connect[ i ].cotime > 30 ) {            print( "LATE" );            CONNECT_endOne_debug( i );          }				}else{          Connect[ i ].cotime = 0;        }/*        if ( ( Connect[ i ].nu <= 22 ) ) {          int r;

⌨️ 快捷键说明

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