diff options
author | xinef1 <w.szyszko2@gmail.com> | 2017-01-28 05:00:28 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2019-07-21 21:06:54 +0200 |
commit | b485f3e6733950920cc1b9afe2a81a30eeeeaa95 (patch) | |
tree | d1a4171eb3a5d9f3b4f8a6a011addeb32a2f76eb /src/server/game/Handlers/SocialHandler.cpp | |
parent | e6885d50c688437ea21855eb0161373de02bcf9f (diff) |
Few small optimizations here and there (#18684)
Changes list:
- Added CharacterGuidByNameContainer which contains name -> guid unordered map (updated along CharacterInfo)
- Extended CharacterInfo structure with GuildId
- Extended CharacterInfo structure with ArenaTeamId[3], for all possible teams (2v2, 3v3, 5v5)
- Removed CHAR_SEL_GUID_BY_NAME and CHAR_SEL_CHAR_GUID_BY_NAME synchronous queries, name -> guid can be now retrieved in World::GetCharacterGuidByName
- Removed CHAR_SEL_GUID_RACE_ACC_BY_NAME synchronous query, guid can be retrieved by name and rest of the data can be retrieved by guid
- Removed CHAR_SEL_CHAR_LEVEL synchronous query, level can be retrieved by guid
- Changed CHAR_SEL_CHARACTER_ACTIONS_SPEC to asynchronous query, action bars are now loaded asynchronously
- Removed CHAR_SEL_CHARACTER_NAME_CLASS synchronous query, guid can be retrieved by name and rest of the data can be retrieved by guid
- Removed CHAR_SEL_PLAYER_ARENA_TEAMS and CHAR_SEL_ARENA_TEAM_ID_BY_PLAYER_GUID synchronous queries, arena teams are now stored in CharacterInfo
- Replaced synchronous db calls with CharacterInfo lookups
- Removed ObjectMgr::GetPlayerGUIDByName, as it used db query
- Replaced some unnecessary UpdateObjectVisibility() calls because they were either duplicated (called few lines above in other function) or it is enough to call DestroyForNearbyPlayers because object is being removed or should be invisible and DestroyForNearbyPlayers is faster
- Corrected typo in Player::DestroyForPlayer, only items in slots 0 to EQUIPMENT_SLOT_END are sent to other players
- Renamed Player::GetGuildIdFromDB to Player::GetGuildIdFromCharacterInfo and changed the function to use CharacterInfo structure
- Renamed Player::GetArenaTeamIdFromDB to Player::GetArenaTeamIdFromCharacterInfo and changed the function to use CharacterInfo structure
- Renamed Player::GetLevelFromDB to Player::GetLevelFromCharacterInfo and changed the function to use CharacterInfo structure
- Removed GameEventMgr::_questToEventLinks and associated functions, eventId is now stored in Quest class under _eventIdForQuest variable
- Changed some functions checking quest status to use other functions for quest status check instead of duplicating code
- Removed callback from add friend, because we can get the guid from appropriate storage, no need to make db query
- Removed callback from add ignore, because we can get the guid from appropriate storage, no need to make db query
- Added callback to unwrap wrapped items asynchronously
- Removed synchronous select in tutorials to check if we have any entries in db, if any entry exists in db, m_TutorialsChanged variable will have TUTORIALS_FLAG_LOADED_FROM_DB flag added and it is no longer necessary to query database
(cherrypicked from b955456008191e60b6bda1f22e3486a3792b08db)
Diffstat (limited to 'src/server/game/Handlers/SocialHandler.cpp')
-rw-r--r-- | src/server/game/Handlers/SocialHandler.cpp | 71 |
1 files changed, 18 insertions, 53 deletions
diff --git a/src/server/game/Handlers/SocialHandler.cpp b/src/server/game/Handlers/SocialHandler.cpp index a6cff8c2417..dcafebe93e1 100644 --- a/src/server/game/Handlers/SocialHandler.cpp +++ b/src/server/game/Handlers/SocialHandler.cpp @@ -43,30 +43,14 @@ void WorldSession::HandleAddFriendOpcode(WorldPackets::Social::AddFriend& packet TC_LOG_DEBUG("network", "WorldSession::HandleAddFriendOpcode: %s asked to add friend: %s", GetPlayerInfo().c_str(), packet.Name.c_str()); - PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GUID_RACE_ACC_BY_NAME); - stmt->setString(0, packet.Name); - - _queryProcessor.AddQuery(CharacterDatabase.AsyncQuery(stmt) - .WithPreparedCallback(std::bind(&WorldSession::HandleAddFriendOpcodeCallBack, this, std::move(packet.Notes), std::placeholders::_1))); -} - -void WorldSession::HandleAddFriendOpcodeCallBack(std::string const& friendNote, PreparedQueryResult result) -{ - if (!GetPlayer()) - return; - - ObjectGuid friendGuid; FriendsResult friendResult = FRIEND_NOT_FOUND; - - if (result) + ObjectGuid friendGuid = sWorld->GetCharacterGuidByName(packet.Name); + if (!friendGuid.IsEmpty()) { - Field* fields = result->Fetch(); - - if (ObjectGuid::LowType lowGuid = fields[0].GetUInt64()) + if (CharacterInfo const* characterInfo = sWorld->GetCharacterInfo(friendGuid)) { - friendGuid = ObjectGuid::Create<HighGuid::Player>(lowGuid); - uint32 team = Player::TeamForRace(fields[1].GetUInt8()); - uint32 friendAccountId = fields[2].GetUInt32(); + uint32 team = Player::TeamForRace(characterInfo->Race); + uint32 friendAccountId = characterInfo->AccountId; if (HasPermission(rbac::RBAC_PERM_ALLOW_GM_FRIEND) || AccountMgr::IsPlayerAccount(AccountMgr::GetSecurity(friendAccountId, realm.Id.Realm))) { @@ -85,7 +69,7 @@ void WorldSession::HandleAddFriendOpcodeCallBack(std::string const& friendNote, friendResult = FRIEND_ADDED_OFFLINE; if (GetPlayer()->GetSocial()->AddToSocialList(friendGuid, SOCIAL_FLAG_FRIEND)) - GetPlayer()->GetSocial()->SetFriendNote(friendGuid, friendNote); + GetPlayer()->GetSocial()->SetFriendNote(friendGuid, packet.Notes); else friendResult = FRIEND_LIST_FULL; } @@ -112,42 +96,23 @@ void WorldSession::HandleAddIgnoreOpcode(WorldPackets::Social::AddIgnore& packet return; TC_LOG_DEBUG("network", "WorldSession::HandleAddIgnoreOpcode: %s asked to Ignore: %s", - GetPlayerInfo().c_str(), packet.Name.c_str()); - - PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GUID_BY_NAME); - stmt->setString(0, packet.Name); + GetPlayer()->GetName().c_str(), packet.Name.c_str()); - _queryProcessor.AddQuery(CharacterDatabase.AsyncQuery(stmt).WithPreparedCallback(std::bind(&WorldSession::HandleAddIgnoreOpcodeCallBack, this, std::placeholders::_1))); -} - -void WorldSession::HandleAddIgnoreOpcodeCallBack(PreparedQueryResult result) -{ - if (!GetPlayer()) - return; - - ObjectGuid ignoreGuid; + ObjectGuid ignoreGuid = sWorld->GetCharacterGuidByName(packet.Name); FriendsResult ignoreResult = FRIEND_IGNORE_NOT_FOUND; - - if (result) + if (!ignoreGuid.IsEmpty()) { - Field* fields = result->Fetch(); - - if (ObjectGuid::LowType lowGuid = fields[0].GetUInt64()) + if (ignoreGuid == GetPlayer()->GetGUID()) //not add yourself + ignoreResult = FRIEND_IGNORE_SELF; + else if (GetPlayer()->GetSocial()->HasIgnore(ignoreGuid)) + ignoreResult = FRIEND_IGNORE_ALREADY; + else { - ignoreGuid = ObjectGuid::Create<HighGuid::Player>(lowGuid); + ignoreResult = FRIEND_IGNORE_ADDED; - if (ignoreGuid == GetPlayer()->GetGUID()) //not add yourself - ignoreResult = FRIEND_IGNORE_SELF; - else if (GetPlayer()->GetSocial()->HasIgnore(ignoreGuid)) - ignoreResult = FRIEND_IGNORE_ALREADY; - else - { - ignoreResult = FRIEND_IGNORE_ADDED; - - // ignore list full - if (!GetPlayer()->GetSocial()->AddToSocialList(ignoreGuid, SOCIAL_FLAG_IGNORED)) - ignoreResult = FRIEND_IGNORE_FULL; - } + // ignore list full + if (!GetPlayer()->GetSocial()->AddToSocialList(ignoreGuid, SOCIAL_FLAG_IGNORED)) + ignoreResult = FRIEND_IGNORE_FULL; } } |