Exemplo n.º 1
0
void CHostBrowser::OnDropped()
{
	if ( m_nProtocol != PROTOCOL_ED2K && m_nProtocol != PROTOCOL_DC )
	{
		if ( ! IsValid() ) return;

		if ( m_nState == hbsConnecting )
		{
			theApp.Message( MSG_ERROR, IDS_BROWSE_CANT_CONNECT_TO, (LPCTSTR)m_sAddress );

			if ( ! m_tPushed && SendPush( TRUE ) )
				return;
		}
		else
		{
			if ( m_nLength == SIZE_UNKNOWN )
			{
				m_nLength = GetInputLength();
				ReadContent();
				return;
			}

			theApp.Message( MSG_ERROR, IDS_BROWSE_DROPPED, (LPCTSTR)m_sAddress );
		}
	}

	Stop();
}
Exemplo n.º 2
0
BOOL CHostBrowser::Browse()
{
	CSingleLock pLock( &Transfers.m_pSection, TRUE );

	if ( m_hSocket != INVALID_SOCKET ) return FALSE;

	m_sAddress = inet_ntoa( m_pAddress );

	if ( m_bMustPush )
	{
		if ( SendPush( FALSE ) )
		{
			theApp.Message( MSG_SYSTEM, IDS_BROWSE_PUSHED_TO, (LPCTSTR)m_sAddress );
		}
		else
		{
			theApp.Message( MSG_ERROR, IDS_BROWSE_CANT_PUSH_TO, (LPCTSTR)m_sAddress );
			return FALSE;
		}
	}
	else
	{
		if ( ConnectTo( &m_pAddress, m_nPort ) )
		{
			theApp.Message( MSG_SYSTEM, IDS_BROWSE_CONNECTING_TO, (LPCTSTR)m_sAddress );
		}
		else
		{
			theApp.Message( MSG_ERROR, IDS_BROWSE_CANT_CONNECT_TO, (LPCTSTR)m_sAddress );
			return FALSE;
		}
	}

	m_nState	= hbsConnecting;
	m_nHits		= 0;

	if ( m_pProfile != NULL ) delete m_pProfile;
	m_pProfile = NULL;

	return TRUE;
}
Exemplo n.º 3
0
void CHostBrowser::OnDropped(BOOL bError)
{
	if ( m_hSocket == INVALID_SOCKET ) return;

	if ( m_nState == hbsConnecting )
	{
		theApp.Message( MSG_ERROR, IDS_BROWSE_CANT_CONNECT_TO, (LPCTSTR)m_sAddress );
		if ( ! m_tPushed && SendPush( TRUE ) ) return;
	}
	else
	{
		if ( m_nLength == 0xFFFFFFFF )
		{
			m_nLength = m_pInput->m_nLength;
			ReadContent();
			return;
		}

		theApp.Message( MSG_ERROR, IDS_BROWSE_DROPPED, (LPCTSTR)m_sAddress );
	}

	Stop();
}
Exemplo n.º 4
0
BOOL CHostBrowser::Browse()
{
	CQuickLock oTransfersLock( Transfers.m_pSection );

	m_sAddress = inet_ntoa( m_pAddress );
	m_sServer = protocolAbbr[ ( ( m_nProtocol == PROTOCOL_ANY ) ? PROTOCOL_NULL : m_nProtocol ) ];
	m_pVendor = VendorCache.Lookup( m_sServer );

	switch ( m_nProtocol )
	{
	case PROTOCOL_G2:
		Settings.Gnutella2.Enabled = true;
		break;
	case PROTOCOL_G1:
		Settings.Gnutella1.Enabled = true;
		break;
	case PROTOCOL_ED2K:
		Settings.eDonkey.Enabled = true;
		break;
	case PROTOCOL_DC:
		Settings.DC.Enabled = true;
		break;
	//default:
	}

	// ED2K Clients have their connection controlled by ED2KClient.
	// (One connection used for many things)
	if ( m_nProtocol == PROTOCOL_ED2K )
	{
		// Lock this object until we are finished with it
		CQuickLock oCEDClientsLock( EDClients.m_pSection );

		SOCKADDR_IN* pServer = NULL;	// ToDo: Add push connections
		CEDClient* pClient = EDClients.Connect( m_pAddress.s_addr, m_nPort,
			( pServer ? &pServer->sin_addr : NULL ),
			( pServer ? pServer->sin_port : 0 ), m_oClientID );

		if ( pClient && pClient->m_bConnected )
		{
			// Send browse request
			if ( CEDPacket* pPacket = CEDPacket::New( ED2K_C2C_ASKSHAREDDIRS ) )
				pClient->Send( pPacket );
		}
		else if ( ! pClient || ! pClient->Connect() )
		{
			theApp.Message( MSG_NOTICE, IDS_BROWSE_CANT_CONNECT_TO, (LPCTSTR)m_sAddress );
			return FALSE;
		}
	}
	else if ( m_nProtocol == PROTOCOL_DC )
	{
		CEnvyURL oURL;
		oURL.m_nProtocol		= PROTOCOL_DC;
		oURL.m_nAction			= CEnvyURL::uriDownload;
		oURL.m_pServerAddress	= m_pAddress;
		oURL.m_nServerPort		= m_nPort;
		oURL.m_sLogin			= m_sNick;
		oURL.m_sName.Format( L"Files of %s.xml.bz2", (LPCTSTR)SafeFilename( m_sNick ) );
		oURL.m_sURL.Format( L"dchub://%s@%s:%u/files.xml.bz2", (LPCTSTR)URLEncode( m_sNick ), (LPCTSTR)CString( inet_ntoa( m_pAddress ) ), m_nPort );

		return ( Downloads.Add( oURL ) != NULL );
	}
	else // G2/Gunetella
	{
		if ( IsValid() )
			return FALSE;

		if ( m_bMustPush )
		{
			if ( SendPush( FALSE ) )
			{
				theApp.Message( MSG_INFO, IDS_BROWSE_PUSHED_TO, (LPCTSTR)m_sAddress );
			}
			else
			{
				theApp.Message( MSG_NOTICE, IDS_BROWSE_CANT_PUSH_TO, (LPCTSTR)m_sAddress );
				return FALSE;
			}
		}
		else
		{
			if ( ConnectTo( &m_pAddress, m_nPort ) )
			{
				theApp.Message( MSG_INFO, IDS_BROWSE_CONNECTING_TO, (LPCTSTR)m_sAddress );
			}
			else
			{
				theApp.Message( MSG_NOTICE, IDS_BROWSE_CANT_CONNECT_TO, (LPCTSTR)m_sAddress );
				return FALSE;
			}
		}
	}

	m_nState = hbsConnecting;
	m_nHits  = 0;

	delete m_pProfile;
	m_pProfile = NULL;

	// Ensure window text is updated after state has been set to "connecting"
	m_pNotify->UpdateMessages();

	return TRUE;
}