Beispiel #1
0
void SocialMgr::AddFriend(Player* plr, std::string friendName)
{
	if(!plr)
		return;

	WorldPacket data( SMSG_FRIEND_STATUS, 22 );

	PlayerInfo* playerInfo = objmgr.GetPlayerInfo(plr->GetGUID());
	PlayerInfo* friendInfo = objmgr.GetPlayerInfoByName(friendName);

	if(playerInfo == NULL)
	{ // We shouldn't get here
		data << (uint8)FRIEND_DB_ERROR;
		plr->GetSession()->SendPacket( &data );
		return;
	}
	if( friendInfo == NULL)
	{
		sLog.outDetail("WORLD: Guid of %s not found ", friendName.c_str() );
		data << (uint8)FRIEND_NOT_FOUND;
		plr->GetSession()->SendPacket( &data );
		return;
	}
	if( friendInfo->team != playerInfo->team )
	{
		sLog.outDebug("SocialMgr: %s tried to add an ennemy to his friendlist", plr->GetName());
		data << (uint8)FRIEND_ENEMY << (uint64)friendInfo->guid;
		plr->GetSession()->SendPacket( &data );
		return;
	}

	uint64 pGuid = playerInfo->guid;
	uint64 fGuid = friendInfo->guid;
	Player *pFriend = objmgr.GetPlayer(fGuid);

	if ( pGuid == fGuid )
	{
		sLog.outDebug("SocialMgr: %s tried to add himself to his friendlist", plr->GetName());
		data << (uint8)FRIEND_SELF << (uint64)fGuid;
		plr->GetSession()->SendPacket(&data);
		return;
	}
	if( HasFriend(pGuid, fGuid) )
	{
		sLog.outDebug("SocialMgr: %s tried to add someone who is already in his friendlist", plr->GetName());
		data << (uint8)FRIEND_ALREADY << (uint64)fGuid;
		plr->GetSession()->SendPacket(&data);
		return;
	}

	sLog.outDebug("SocialMgr: %s added %s to his friendlist", playerInfo->name.c_str(), friendInfo->name.c_str());

	if ( pFriend )
	{
		data << (uint8)FRIEND_ADDED_ONLINE << (uint64)fGuid << (uint8)1;
		data << (uint32)pFriend->GetZoneId() << (uint32)pFriend->getLevel() << (uint32)pFriend->getClass();
	}
	else
		data << (uint8)FRIEND_ADDED_OFFLINE << (uint64)friendInfo->guid;

	if( m_isInFriendList.find(fGuid) == m_isInFriendList.end() )
		m_isInFriendList[fGuid] = new std::set<uint64>;

	if( m_hasInFriendList.find(pGuid) == m_hasInFriendList.end() )
		m_hasInFriendList[pGuid] = new std::set<uint64>;

	m_hasInFriendList[pGuid]->insert(fGuid);
	m_isInFriendList[fGuid]->insert(pGuid);

	plr->GetSession()->SendPacket( &data );
	CharacterDatabase.Execute("INSERT INTO social(guid,socialguid,flags) VALUES (%I64u,%I64u,'FRIEND')",pGuid,fGuid);
}
Beispiel #2
0
DLL_API const HasFriend operator-(const HasFriend& f1, const HasFriend& f2)
{
    return HasFriend(f1.m - f2.m);
}