예제 #1
0
void CLocalSearch::AddHitDC(CDCPacket* pPacket, CSchemaMap& /*pSchemas*/, CLibraryFile* pFile, int /*nIndex*/)
{
	// Active user:
	// $SR Nick FileName<0x05>FileSize FreeSlots/TotalSlots<0x05>HubName (HubIP:HubPort)|
	// Passive user:
	// $SR Nick FileName<0x05>FileSize FreeSlots/TotalSlots<0x05>HubName (HubIP:HubPort)<0x05>User|
	
	if ( ! m_pSearch )
		return;

	CUploadQueue* pQueue = UploadQueues.SelectQueue(
		PROTOCOL_DC, NULL, 0, CUploadQueue::ulqBoth, NULL );
	int nTotalSlots = pQueue ? pQueue->m_nMaxTransfers : 0;
	int nActiveSlots = pQueue ? pQueue->GetActiveCount() : 0;
	int nFreeSlots = nTotalSlots > nActiveSlots ? ( nTotalSlots - nActiveSlots ) : 0;

	CString sHubName;
	if ( pFile->m_oTiger )
		// It's TTH search
		sHubName = _T("TTH:") + pFile->m_oTiger.toString();
	else
		sHubName = m_pSearch->m_sMyHub;

	CBuffer pAnswer;
	pAnswer.Add( _P("$SR ") );
	pAnswer.Print( m_pSearch->m_sMyNick );
	pAnswer.Add( _P(" ") );
	pAnswer.Print( pFile->m_sName );
	pAnswer.Add( _P("\x05") );
	CString strSize;
	strSize.Format( _T("%I64u %d/%d"), pFile->m_nSize, nFreeSlots, nTotalSlots );
	pAnswer.Print( strSize );
	pAnswer.Add( _P("\x05") );
	pAnswer.Print( sHubName );
	pAnswer.Add( _P(" (") );
	pAnswer.Print( HostToString( &m_pSearch->m_pMyHub ) );
	pAnswer.Add( _P(")") );
	if ( ! m_pSearch->m_bUDP )
	{
		pAnswer.Add( _P("\x05") );
		pAnswer.Print( m_pSearch->m_sUserNick );
	}
	pAnswer.Add( _P("|") );

	pPacket->Write( pAnswer.m_pBuffer, pAnswer.m_nLength );
}