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