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; }