diff options
| author | joschiwald <joschiwald.trinity@gmail.com> | 2015-02-08 02:51:49 +0100 | 
|---|---|---|
| committer | ariel- <ariel-@users.noreply.github.com> | 2017-01-25 23:36:24 -0300 | 
| commit | 62b62ddd63942090b23f8881f2c6ad93d0a251dc (patch) | |
| tree | 7daffa0192e15a7a87e6a3a71e11a5171a357f22 /src/server/game/Handlers/SocialHandler.cpp | |
| parent | f57132b795a097a2c4c863a8153b0c1be5e008c0 (diff) | |
Core/Packets: updated some contactlist packets
(cherry picked from commit e01bb918875f88ede211fc13ff3908e30249de33)
Conflicts:
	src/server/game/Entities/Player/Player.cpp
	src/server/game/Entities/Player/Player.h
	src/server/game/Entities/Player/SocialMgr.cpp
	src/server/game/Entities/Player/SocialMgr.h
	src/server/game/Handlers/MiscHandler.cpp
	src/server/game/Server/Packets/MiscPackets.cpp
	src/server/game/Server/Protocol/Opcodes.cpp
	src/server/game/Server/Protocol/Opcodes.h
	src/server/game/Server/WorldSession.cpp
	src/server/game/Server/WorldSession.h
	src/server/shared/Database/Implementation/CharacterDatabase.cpp
	src/server/shared/Database/Implementation/CharacterDatabase.h
Diffstat (limited to 'src/server/game/Handlers/SocialHandler.cpp')
| -rw-r--r-- | src/server/game/Handlers/SocialHandler.cpp | 177 | 
1 files changed, 177 insertions, 0 deletions
diff --git a/src/server/game/Handlers/SocialHandler.cpp b/src/server/game/Handlers/SocialHandler.cpp new file mode 100644 index 00000000000..cd9968bf84e --- /dev/null +++ b/src/server/game/Handlers/SocialHandler.cpp @@ -0,0 +1,177 @@ +/* + * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "WorldSession.h" +#include "Player.h" +#include "SocialMgr.h" +#include "ObjectMgr.h" + +void WorldSession::HandleContactListOpcode(WorldPacket& recvData) +{ +    uint32 flags; +    recvData >> flags; +    _player->GetSocial()->SendSocialList(_player, flags); +} + +void WorldSession::HandleAddFriendOpcode(WorldPacket& recvData) +{ +    std::string friendName, friendNote; +    recvData >> friendName >> friendNote; + +    if (!normalizePlayerName(friendName)) +        return; + +    TC_LOG_DEBUG("network", "WorldSession::HandleAddFriendOpcode: %s asked to add friend: %s", +        GetPlayer()->GetName().c_str(), friendName.c_str()); + +    PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GUID_RACE_ACC_BY_NAME); +    stmt->setString(0, friendName); + +    _addFriendCallback.SetParam(friendNote); +    _addFriendCallback.SetFutureResult(CharacterDatabase.AsyncQuery(stmt)); +} + +void WorldSession::HandleAddFriendOpcodeCallback(PreparedQueryResult result, std::string const& friendNote) +{ +    if (!GetPlayer()) +        return; + +    ObjectGuid friendGuid; +    FriendsResult friendResult = FRIEND_NOT_FOUND; + +    if (result) +    { +        Field* fields = result->Fetch(); + +        friendGuid = ObjectGuid(HighGuid::Player, 0, fields[0].GetUInt32()); +        uint32 team = Player::TeamForRace(fields[1].GetUInt8()); +        uint32 friendAccountId = fields[2].GetUInt32(); + +        if (HasPermission(rbac::RBAC_PERM_ALLOW_GM_FRIEND) || AccountMgr::IsPlayerAccount(AccountMgr::GetSecurity(friendAccountId, realm.Id.Realm))) +        { +            if (friendGuid) +            { +                if (friendGuid == GetPlayer()->GetGUID()) +                    friendResult = FRIEND_SELF; +                else if (GetPlayer()->GetTeam() != team && !HasPermission(rbac::RBAC_PERM_TWO_SIDE_ADD_FRIEND)) +                    friendResult = FRIEND_ENEMY; +                else if (GetPlayer()->GetSocial()->HasFriend(friendGuid)) +                    friendResult = FRIEND_ALREADY; +                else +                { +                    Player* pFriend = ObjectAccessor::FindPlayer(friendGuid); +                    if (pFriend && pFriend->IsVisibleGloballyFor(GetPlayer())) +                        friendResult = FRIEND_ADDED_ONLINE; +                    else +                        friendResult = FRIEND_ADDED_OFFLINE; +                    if (GetPlayer()->GetSocial()->AddToSocialList(friendGuid, SOCIAL_FLAG_FRIEND)) +                        GetPlayer()->GetSocial()->SetFriendNote(friendGuid, friendNote); +                    else +                        friendResult = FRIEND_LIST_FULL; +                } +            } +        } +    } + +    sSocialMgr->SendFriendStatus(GetPlayer(), friendResult, friendGuid); +} + +void WorldSession::HandleDelFriendOpcode(WorldPacket& recvData) +{ +    ObjectGuid friendGuid; +    recvData >> friendGuid; +    TC_LOG_DEBUG("network", "WorldSession::HandleDelFriendOpcode: %s", friendGuid.ToString().c_str()); + +    _player->GetSocial()->RemoveFromSocialList(friendGuid, SOCIAL_FLAG_FRIEND); + +    sSocialMgr->SendFriendStatus(GetPlayer(), FRIEND_REMOVED, friendGuid); +} + +void WorldSession::HandleAddIgnoreOpcode(WorldPacket& recvData) +{ +    std::string ignoreName; +    recvData >> ignoreName; + +    if (!normalizePlayerName(ignoreName)) +        return; + +    TC_LOG_DEBUG("network", "WorldSession::HandleAddIgnoreOpcode: %s asked to Ignore: %s", +        GetPlayer()->GetName().c_str(), ignoreName.c_str()); + +    PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GUID_BY_NAME); +    stmt->setString(0, ignoreName); + +    _addIgnoreCallback = CharacterDatabase.AsyncQuery(stmt); +} + +void WorldSession::HandleAddIgnoreOpcodeCallback(PreparedQueryResult result) +{ +    if (!GetPlayer()) +        return; + +    ObjectGuid ignoreGuid; +    FriendsResult ignoreResult = FRIEND_IGNORE_NOT_FOUND; + +    if (result) +    { +        Field* fields = result->Fetch(); + +        if (ObjectGuid::LowType lowGuid = fields[0].GetUInt32()) +        { +            ignoreGuid = ObjectGuid::Create<HighGuid::Player>(lowGuid); + +            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; +            } +        } +    } + +    sSocialMgr->SendFriendStatus(GetPlayer(), ignoreResult, ignoreGuid); +} + +void WorldSession::HandleDelIgnoreOpcode(WorldPacket& recvData) +{ +    ObjectGuid ignoreGuid; +    recvData >> ignoreGuid; + +    TC_LOG_DEBUG("network", "WorldSession::HandleDelIgnoreOpcode: %s", ignoreGuid.ToString().c_str()); + +    _player->GetSocial()->RemoveFromSocialList(ignoreGuid, SOCIAL_FLAG_IGNORED); + +    sSocialMgr->SendFriendStatus(GetPlayer(), FRIEND_IGNORE_REMOVED, ignoreGuid); +} + +void WorldSession::HandleSetContactNotesOpcode(WorldPacket& recvData) +{ +    ObjectGuid guid; +    std::string note; +    recvData >> guid >> note; + +    TC_LOG_DEBUG("network", "WorldSession::HandleSetContactNotesOpcode: Contact: %s, Notes: %s", guid.ToString().c_str(), note.c_str()); + +    _player->GetSocial()->SetFriendNote(guid, note); +}  | 
