OscarPrivacyEngine::OscarPrivacyEngine( OscarAccount* account, Type type )
: QObject(), m_type( type )
{
	m_client = account->engine();
	
	ContactMap contactMap;
	
	QList<OContact> contactList = m_client->ssiManager()->contactList();
	QList<OContact>::const_iterator it, cEnd;
	
	cEnd = contactList.constEnd();
	for ( it = contactList.constBegin(); it != cEnd; ++it )
	{
		QString contactId = ( *it ).name();
		
		OscarContact* oc = dynamic_cast<OscarContact*>( account->contacts().value( ( *it ).name() ) );
		if ( oc )
		{	//for better orientation in lists use displayName and id
			QString screenName( "%1 (%2)" );
			screenName = screenName.arg( oc->displayName(), contactId );
			contactMap.insert( contactId, screenName );
		}
		else
		{
			contactMap.insert( contactId, contactId );
		}
	}
	addAllContacts( contactMap );
	
	switch( type )
	{
	case Visible:
		contactList = m_client->ssiManager()->visibleList();
		break;
	case Invisible:
		contactList = m_client->ssiManager()->invisibleList();
		break;
	case Ignore:
		contactList = m_client->ssiManager()->ignoreList();
		break;
	}
	
	QSet<QString> tmpSet;
	
	cEnd = contactList.constEnd();
	for ( it = contactList.constBegin(); it != cEnd; ++it )
		tmpSet.insert( ( *it ).name() );
	
	addContacts( contactMap, tmpSet );
}
Example #2
0
void CRoutingZone::DbgWriteBootstrapFile()
{
	DebugLogWarning(_T("Writing special bootstrap nodes.dat - not intended for normal use"));
	try
	{
		// Write a saved contact list.
		CUInt128 uID;
		CSafeBufferedFile file;
		CFileException fexp;
		if (file.Open(m_sFilename, CFile::modeWrite | CFile::modeCreate | CFile::typeBinary|CFile::shareDenyWrite, &fexp))
		{
			setvbuf(file.m_pStream, NULL, _IOFBF, 32768);

			// The bootstrap method gets a very nice sample of contacts to save.
			ContactMap mapContacts;
			CUInt128 uRandom(CUInt128((ULONG)0), 0);
			CUInt128 uDistance = uRandom;
			uDistance.Xor(uMe);
			GetClosestTo(2, uRandom, uDistance, 1200, &mapContacts, false, false);
			// filter out Kad1 nodes
			for (ContactMap::iterator itContactMap = mapContacts.begin(); itContactMap != mapContacts.end(); )
			{
				ContactMap::iterator itCurContactMap = itContactMap;
				++itContactMap;
				CContact* pContact = itCurContactMap->second;
				if (pContact->GetVersion() <= 1)
					mapContacts.erase(itCurContactMap);
			}
			// Start file with 0 to prevent older clients from reading it.
			file.WriteUInt32(0);
			// Now tag it with a version which happens to be 2 (1 till 0.48a).
			file.WriteUInt32(3);
			file.WriteUInt32(1); // if we would use version >=3, this would mean that this is not a normal nodes.dat
			file.WriteUInt32((uint32_t)mapContacts.size());
			for (ContactMap::const_iterator itContactMap = mapContacts.begin(); itContactMap != mapContacts.end(); ++itContactMap)
			{
				CContact* pContact = itContactMap->second;
				pContact->GetClientID(&uID);
				file.WriteUInt128(&uID);
				file.WriteUInt32(pContact->GetIPAddress());
				file.WriteUInt16(pContact->GetUDPPort());
				file.WriteUInt16(pContact->GetTCPPort());
				file.WriteUInt8(pContact->GetVersion());
			}
			file.Close();
			AddDebugLogLine( false, _T("Wrote %ld contact to bootstrap file."), mapContacts.size());
		}
		else
			DebugLogError(_T("Unable to store Kad file: %s"), m_sFilename);
	}
	catch (CFileException* e)
	{
		e->Delete();
		AddDebugLogLine(false, _T("CFileException in CRoutingZone::writeFile"));
	}

}
Example #3
0
bool MessageLib::sendFriendListPlay9(PlayerObject* playerObject)
{
    if(!(playerObject->isConnected()))
        return(false);

    ContactMap*				friendList	= playerObject->getFriendsList();
    ContactMap::iterator	nameIt		= friendList->begin();

    uint32 friendListByteCount = 0;

    while(nameIt != friendList->end())
    {
        friendListByteCount += ((*nameIt).second.getLength() + 2);
        ++nameIt;
    }

    mMessageFactory->StartMessage();
    mMessageFactory->addUint32(opDeltasMessage);
    mMessageFactory->addUint64(playerObject->getId());
    mMessageFactory->addUint32(opPLAY);
    mMessageFactory->addUint8(9);

    mMessageFactory->addUint32(15 + friendListByteCount);
    mMessageFactory->addUint16(1);
    mMessageFactory->addUint16(7);


    playerObject->advanceFriendsListUpdateCounter(friendList->size() + 1);

    mMessageFactory->addUint32(friendList->size() + 1);
    mMessageFactory->addUint32(playerObject->getFriendsListUpdateCounter());

    mMessageFactory->addUint8(3);
    mMessageFactory->addUint16(friendList->size());

    nameIt = friendList->begin();

    while(nameIt != friendList->end())
    {
        mMessageFactory->addString((*nameIt).second);
        ++nameIt;
    }

    (playerObject->getClient())->SendChannelA(mMessageFactory->EndMessage(),playerObject->getAccountId(),CR_Client,5);

    return(true);
}
void OscarPrivacyEngine::addContacts( const ContactMap& contacts, const QSet<QString>& idSet )
{
	m_idSet = idSet;
	m_contactsModel.clear();
	m_contactsModel.insertColumns( 0, 1 );
	m_contactsModel.insertRows( 0, idSet.size() );
	
	int i = 0;
	foreach ( const QString& id, idSet )
	{
		QModelIndex index = m_contactsModel.index( i++, 0 );
		
		m_contactsModel.setData( index, id, Qt::UserRole );
		m_contactsModel.setData( index, contacts.value( id, id ), Qt::DisplayRole );
	}