Ejemplo n.º 1
0
BOOL CEDClients::OnAccept(CConnection* pConnection)
{
	if ( ! Network.IsConnected() || ( Settings.Connection.RequireForTransfers && ! Settings.eDonkey.Enabled ) )
	{
		theApp.Message( MSG_ERROR, IDS_ED2K_CLIENT_DISABLED, (LPCTSTR)pConnection->m_sAddress );
		return FALSE;
	}

	CSingleLock oTransfersLock( &Transfers.m_pSection );
	if ( ! oTransfersLock.Lock( 250 ) )
	{
		theApp.Message( MSG_DEBUG, _T("Rejecting ed2k connection from %s, network core overloaded."),
			(LPCTSTR)pConnection->m_sAddress );			// protocolNames[ PROTOCOL_ED2K ]
		return FALSE;
	}

	CSingleLock oEDClientsLock( &m_pSection );
	if ( ! oEDClientsLock.Lock( 250 ) )
	{
		theApp.Message( MSG_DEBUG, _T("Rejecting ed2k connection from %s, network core overloaded."),
			(LPCTSTR)pConnection->m_sAddress );			// protocolNames[ PROTOCOL_ED2K ]
		return FALSE;
	}

	if ( IsFull() )
	{
		// Even if we're full, we still need to accept connections from clients we have queued, etc
		if ( ( GetByIP( &pConnection->m_pHost.sin_addr ) == NULL ) || ( IsOverloaded() ) )
		{
			theApp.Message( MSG_DEBUG, _T("Rejecting ed2k connection from %s, max client connections reached."),
				(LPCTSTR)pConnection->m_sAddress );		// protocolNames[ PROTOCOL_ED2K ]
			return FALSE;
		}
		else
		{
			theApp.Message( MSG_DEBUG, _T("Accepting ed2k connection from %s despite client connection limit."),
				(LPCTSTR)pConnection->m_sAddress );		// protocolNames[ PROTOCOL_ED2K ]
		}
	}

	if ( CEDClient* pClient = new CEDClient() )
	{
		pClient->AttachTo( pConnection );
		return TRUE;
	}

	return FALSE;
}
Ejemplo n.º 2
0
BOOL CEDClients::OnAccept(CConnection* pConnection)
{
	ASSERT( pConnection != NULL );
	
	if ( Settings.Connection.RequireForTransfers && ! Settings.eDonkey.EnableToday )
	{
		theApp.Message( MSG_ERROR, IDS_ED2K_CLIENT_DISABLED,
			(LPCTSTR)pConnection->m_sAddress );
		return FALSE;
	}
	
	CSingleLock pLock( &Transfers.m_pSection );
	if ( ! pLock.Lock( 250 ) ) return FALSE;

	if ( IsFull() )
	{
		// Even if we're full, we still need to accept connections from clients we have queued, etc
		if ( ( GetByIP( &pConnection->m_pHost.sin_addr ) == NULL ) || ( IsOverloaded() ) )
		{
			theApp.Message( MSG_DEBUG, _T("Rejecting ed2k connection from %s, max client connections reached."),
				(LPCTSTR)pConnection->m_sAddress );
			return FALSE;
		}
		else 
		{
			theApp.Message( MSG_DEBUG, _T("Accepting ed2k connection from %s despite client connection limit."),
				(LPCTSTR)pConnection->m_sAddress );

		}
	}
	
	CEDClient* pClient = new CEDClient();
	pClient->AttachTo( pConnection );
	
	return TRUE;
}