Beispiel #1
0
bool ServerManager::ProcessInputs( )
{
	bool ret = false;

	if(m_MinFD == INVALID_SOCKET && m_MaxFD == INVALID_SOCKET)
	{
		return true;
	}

	for(int i=SCENE_PLAYER_ID; i<=BILLING_PLAYER_ID; i++)
	{
		ServerPlayer*	pPlayer = GetServerPlayer(i);
		if(!pPlayer) continue;

		if(pPlayer->IsValid())
		{
			SOCKET s = pPlayer->GetSocket()->getSOCKET();
			if(FD_ISSET( s, &m_ReadFDs[SELECT_USE]) )
			{
				if(pPlayer->GetSocket()->isSockError() )
				{
					RemoveServer(i);
				}
				else
				{
					ret = pPlayer->ProcessInput( );
					if(!ret)
					{
						RemoveServer( i );
					}
				}
			}
		}
	}

	return true;
}
Beispiel #2
0
BOOL ServerManager::ProcessInputs( )
{
__ENTER_FUNCTION

    BOOL ret = FALSE ;

    if (m_MinFD == INVALID_SOCKET && m_MaxFD == INVALID_SOCKET) // no player exist
    { 
        return TRUE ;
    }

    //新连接接入:
    if( FD_ISSET(m_SocketID,&m_ReadFDs[SELECT_USE]) )
    {
        for( int i=0; i<ACCEPT_ONESTEP; i++ )
        {
            if( !AcceptNewConnection() )
                break;
        }
    }

    //数据读取
    UINT nPlayerCount = GetPlayerNumber() ;
    for( UINT i=0; i<nPlayerCount; i++ )
    {
        if( m_pPlayers[i]==INVALID_ID )
            continue ;

        ServerPlayer* pPlayer = g_pPlayerPool->GetPlayer(m_pPlayers[i]) ;
        Assert( pPlayer ) ;

        SOCKET s = pPlayer->GetSocket()->getSOCKET() ;
        if( s == m_SocketID )
            continue ;

        if( FD_ISSET( s, &m_ReadFDs[SELECT_USE] ) )
        {
            if( pPlayer->GetSocket()->isSockError() )
            {//连接出现错误
                RemovePlayer( pPlayer ) ;
            }
            else
            {//连接正常
                _MY_TRY
                {
                    ret = pPlayer->ProcessInput( ) ;
                    if( !ret )
                    {
                        RemovePlayer( pPlayer ) ;
                    }
                }
                _MY_CATCH
                {
                    RemovePlayer( pPlayer ) ;
                }
            }
        }
    }


    return TRUE ;

__LEAVE_FUNCTION

    return FALSE ;
}