fix(Core/Social): cleanup + fix crash in friend system (#3832)

fix crash when a friend or ignore get GUID 0 and also double friend list
This commit is contained in:
Viste
2020-12-04 00:20:35 +00:00
committed by GitHub
parent 9befc2c904
commit 755e30f916
5 changed files with 283 additions and 310 deletions

View File

@@ -566,148 +566,6 @@ void WorldSession::HandleStandStateChangeOpcode(WorldPacket& recv_data)
_player->SetStandState(animstate);
}
void WorldSession::HandleContactListOpcode(WorldPacket& recv_data)
{
uint32 unk;
recv_data >> unk;
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Received CMSG_CONTACT_LIST - Unk: %d", unk);
#endif
_player->GetSocial()->SendSocialList(_player);
}
void WorldSession::HandleAddFriendOpcode(WorldPacket& recv_data)
{
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Received CMSG_ADD_FRIEND");
#endif
std::string friendName = GetAcoreString(LANG_FRIEND_IGNORE_UNKNOWN);
std::string friendNote;
recv_data >> friendName;
recv_data >> friendNote;
if (!normalizePlayerName(friendName))
return;
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: %s asked to add friend : '%s'", GetPlayer()->GetName().c_str(), friendName.c_str());
#endif
// xinef: Get Data From global storage
uint32 guidLow = sWorld->GetGlobalPlayerGUID(friendName);
if (!guidLow)
return;
GlobalPlayerData const* playerData = sWorld->GetGlobalPlayerData(guidLow);
if (!playerData)
return;
uint64 friendGuid = MAKE_NEW_GUID(guidLow, 0, HIGHGUID_PLAYER);
uint32 friendAccountId = playerData->accountId;
TeamId teamId = Player::TeamIdForRace(playerData->race);
FriendsResult friendResult = FRIEND_NOT_FOUND;
if (!AccountMgr::IsPlayerAccount(GetSecurity()) || sWorld->getBoolConfig(CONFIG_ALLOW_GM_FRIEND) || AccountMgr::IsPlayerAccount(AccountMgr::GetSecurity(friendAccountId, realmID)))
{
if (friendGuid)
{
if (friendGuid == GetPlayer()->GetGUID())
friendResult = FRIEND_SELF;
else if (GetPlayer()->GetTeamId() != teamId && !sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_ADD_FRIEND) && AccountMgr::IsPlayerAccount(GetSecurity()))
friendResult = FRIEND_ENEMY;
else if (GetPlayer()->GetSocial()->HasFriend(guidLow))
friendResult = FRIEND_ALREADY;
else
{
Player* pFriend = ObjectAccessor::FindPlayerInOrOutOfWorld(friendGuid);
if (pFriend && pFriend->IsVisibleGloballyFor(GetPlayer()) && !AccountMgr::IsGMAccount(pFriend->GetSession()->GetSecurity()))
friendResult = FRIEND_ADDED_ONLINE;
else
friendResult = FRIEND_ADDED_OFFLINE;
if (!GetPlayer()->GetSocial()->AddToSocialList(guidLow, false))
{
friendResult = FRIEND_LIST_FULL;
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: %s's friend list is full.", GetPlayer()->GetName().c_str());
#endif
}
}
GetPlayer()->GetSocial()->SetFriendNote(guidLow, friendNote);
}
}
sSocialMgr->SendFriendStatus(GetPlayer(), friendResult, guidLow, false);
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Sent (SMSG_FRIEND_STATUS)");
#endif
}
void WorldSession::HandleDelFriendOpcode(WorldPacket& recv_data)
{
uint64 FriendGUID;
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Received CMSG_DEL_FRIEND");
#endif
recv_data >> FriendGUID;
_player->GetSocial()->RemoveFromSocialList(GUID_LOPART(FriendGUID), false);
sSocialMgr->SendFriendStatus(GetPlayer(), FRIEND_REMOVED, GUID_LOPART(FriendGUID), false);
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Sent motd (SMSG_FRIEND_STATUS)");
#endif
}
void WorldSession::HandleAddIgnoreOpcode(WorldPacket& recv_data)
{
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Received CMSG_ADD_IGNORE");
#endif
std::string ignoreName = GetAcoreString(LANG_FRIEND_IGNORE_UNKNOWN);
recv_data >> ignoreName;
if (!normalizePlayerName(ignoreName))
return;
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: %s asked to Ignore: '%s'", GetPlayer()->GetName().c_str(), ignoreName.c_str());
#endif
uint32 lowGuid = sWorld->GetGlobalPlayerGUID(ignoreName);
if (!lowGuid)
return;
uint64 IgnoreGuid = MAKE_NEW_GUID(lowGuid, 0, HIGHGUID_PLAYER);
FriendsResult ignoreResult = FRIEND_IGNORE_NOT_FOUND;
if (IgnoreGuid == GetPlayer()->GetGUID()) //not add yourself
ignoreResult = FRIEND_IGNORE_SELF;
else if (GetPlayer()->GetSocial()->HasIgnore(lowGuid))
ignoreResult = FRIEND_IGNORE_ALREADY;
else
{
ignoreResult = FRIEND_IGNORE_ADDED;
// ignore list full
if (!GetPlayer()->GetSocial()->AddToSocialList(lowGuid, true))
ignoreResult = FRIEND_IGNORE_FULL;
}
sSocialMgr->SendFriendStatus(GetPlayer(), ignoreResult, lowGuid, false);
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Sent (SMSG_FRIEND_STATUS)");
#endif
}
void WorldSession::HandleLoadActionsSwitchSpec(PreparedQueryResult result)
{
if (!GetPlayer())
@@ -745,36 +603,6 @@ void WorldSession::HandleCharacterAuraFrozen(PreparedQueryResult result)
} while (result->NextRow());
}
void WorldSession::HandleDelIgnoreOpcode(WorldPacket& recv_data)
{
uint64 IgnoreGUID;
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Received CMSG_DEL_IGNORE");
#endif
recv_data >> IgnoreGUID;
_player->GetSocial()->RemoveFromSocialList(GUID_LOPART(IgnoreGUID), true);
sSocialMgr->SendFriendStatus(GetPlayer(), FRIEND_IGNORE_REMOVED, GUID_LOPART(IgnoreGUID), false);
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Sent motd (SMSG_FRIEND_STATUS)");
#endif
}
void WorldSession::HandleSetContactNotesOpcode(WorldPacket& recv_data)
{
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_SET_CONTACT_NOTES");
#endif
uint64 guid;
std::string note;
recv_data >> guid >> note;
_player->GetSocial()->SetFriendNote(GUID_LOPART(guid), note);
}
void WorldSession::HandleBugOpcode(WorldPacket& recv_data)
{
uint32 suggestion, contentlen, typelen;