AzeorthCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
PlayerSocial Class Reference

#include "SocialMgr.h"

Public Member Functions

 PlayerSocial ()
 
bool AddToSocialList (ObjectGuid friend_guid, SocialFlag flag)
 
void RemoveFromSocialList (ObjectGuid friend_guid, SocialFlag flag)
 
void SetFriendNote (ObjectGuid friendGuid, std::string note)
 
void SendSocialList (Player *player, uint32 flags)
 
bool HasFriend (ObjectGuid friend_guid) const
 
bool HasIgnore (ObjectGuid ignore_guid) const
 
ObjectGuid GetPlayerGUID () const
 
void SetPlayerGUID (ObjectGuid guid)
 
uint32 GetNumberOfSocialsWithFlag (SocialFlag flag) const
 

Private Types

typedef std::map< ObjectGuid, FriendInfoPlayerSocialMap
 

Private Member Functions

bool _checkContact (ObjectGuid guid, SocialFlag flags) const
 

Private Attributes

PlayerSocialMap m_playerSocialMap
 
ObjectGuid m_playerGUID
 

Friends

class SocialMgr
 

Detailed Description

Member Typedef Documentation

◆ PlayerSocialMap

Constructor & Destructor Documentation

◆ PlayerSocial()

PlayerSocial::PlayerSocial ( )
27: m_playerGUID() { }
ObjectGuid m_playerGUID
Definition: SocialMgr.h:123

Member Function Documentation

◆ _checkContact()

bool PlayerSocial::_checkContact ( ObjectGuid  guid,
SocialFlag  flags 
) const
private
180{
181 const auto& itr = m_playerSocialMap.find(guid);
182 if (itr != m_playerSocialMap.end())
183 return (itr->second.Flags & flags) != 0;
184
185 return false;
186}
PlayerSocialMap m_playerSocialMap
Definition: SocialMgr.h:122

References m_playerSocialMap.

Referenced by HasFriend(), and HasIgnore().

◆ AddToSocialList()

bool PlayerSocial::AddToSocialList ( ObjectGuid  friend_guid,
SocialFlag  flag 
)
41{
42 // check client limits
44 return false;
45
46 auto itr = m_playerSocialMap.find(friendGuid);
47 if (itr != m_playerSocialMap.end())
48 {
49 itr->second.Flags |= flag;
50
52
53 stmt->SetData(0, itr->second.Flags);
54 stmt->SetData(1, GetPlayerGUID().GetCounter());
55 stmt->SetData(2, friendGuid.GetCounter());
56
57 CharacterDatabase.Execute(stmt);
58 }
59 else
60 {
61 m_playerSocialMap[friendGuid].Flags |= flag;
62
64
65 stmt->SetData(0, GetPlayerGUID().GetCounter());
66 stmt->SetData(1, friendGuid.GetCounter());
67 stmt->SetData(2, flag);
68
69 CharacterDatabase.Execute(stmt);
70 }
71 return true;
72}
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
@ CHAR_INS_CHARACTER_SOCIAL
Definition: CharacterDatabase.h:319
@ CHAR_UPD_ADD_CHARACTER_SOCIAL_FLAGS
Definition: CharacterDatabase.h:317
@ SOCIAL_FLAG_FRIEND
Definition: SocialMgr.h:40
#define SOCIALMGR_IGNORE_LIMIT
Definition: SocialMgr.h:99
#define SOCIALMGR_FRIEND_LIMIT
Definition: SocialMgr.h:98
Definition: PreparedStatement.h:158
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition: PreparedStatement.h:78
ObjectGuid GetPlayerGUID() const
Definition: SocialMgr.h:116
uint32 GetNumberOfSocialsWithFlag(SocialFlag flag) const
Definition: SocialMgr.cpp:29

References CHAR_INS_CHARACTER_SOCIAL, CHAR_UPD_ADD_CHARACTER_SOCIAL_FLAGS, CharacterDatabase, ObjectGuid::GetCounter(), GetNumberOfSocialsWithFlag(), GetPlayerGUID(), m_playerSocialMap, PreparedStatementBase::SetData(), SOCIAL_FLAG_FRIEND, SOCIALMGR_FRIEND_LIMIT, and SOCIALMGR_IGNORE_LIMIT.

◆ GetNumberOfSocialsWithFlag()

uint32 PlayerSocial::GetNumberOfSocialsWithFlag ( SocialFlag  flag) const
30{
31 uint32 counter = 0;
32 for (const auto& itr : m_playerSocialMap)
33 {
34 if ((itr.second.Flags & flag) != 0)
35 ++counter;
36 }
37 return counter;
38}
std::uint32_t uint32
Definition: Define.h:108

References m_playerSocialMap.

Referenced by AddToSocialList().

◆ GetPlayerGUID()

ObjectGuid PlayerSocial::GetPlayerGUID ( ) const
inline
116{ return m_playerGUID; }

References m_playerGUID.

Referenced by AddToSocialList(), RemoveFromSocialList(), and SetFriendNote().

◆ HasFriend()

bool PlayerSocial::HasFriend ( ObjectGuid  friend_guid) const
189{
190 return _checkContact(friend_guid, SOCIAL_FLAG_FRIEND);
191}
bool _checkContact(ObjectGuid guid, SocialFlag flags) const
Definition: SocialMgr.cpp:179

References _checkContact(), and SOCIAL_FLAG_FRIEND.

Referenced by WorldSession::HandleGroupInviteOpcode().

◆ HasIgnore()

◆ RemoveFromSocialList()

void PlayerSocial::RemoveFromSocialList ( ObjectGuid  friend_guid,
SocialFlag  flag 
)
75{
76 auto itr = m_playerSocialMap.find(friendGuid);
77 if (itr == m_playerSocialMap.end()) // not exist
78 return;
79
80 itr->second.Flags &= ~flag;
81
82 if (itr->second.Flags == 0)
83 {
85
86 stmt->SetData(0, GetPlayerGUID().GetCounter());
87 stmt->SetData(1, friendGuid.GetCounter());
88
89 CharacterDatabase.Execute(stmt);
90
91 m_playerSocialMap.erase(itr);
92 }
93 else
94 {
96
97 stmt->SetData(0, flag);
98 stmt->SetData(1, GetPlayerGUID().GetCounter());
99 stmt->SetData(2, friendGuid.GetCounter());
100
101 CharacterDatabase.Execute(stmt);
102 }
103}
@ CHAR_UPD_REM_CHARACTER_SOCIAL_FLAGS
Definition: CharacterDatabase.h:318
@ CHAR_DEL_CHARACTER_SOCIAL
Definition: CharacterDatabase.h:320

References CHAR_DEL_CHARACTER_SOCIAL, CHAR_UPD_REM_CHARACTER_SOCIAL_FLAGS, CharacterDatabase, ObjectGuid::GetCounter(), GetPlayerGUID(), m_playerSocialMap, and PreparedStatementBase::SetData().

Referenced by WorldSession::HandleDelFriendOpcode(), and WorldSession::HandleDelIgnoreOpcode().

◆ SendSocialList()

void PlayerSocial::SendSocialList ( Player player,
uint32  flags 
)
125{
126 if (!player)
127 return;
128
129 uint32 friendsCount = 0;
130 uint32 ignoredCount = 0;
131 uint32 totalCount = 0;
132
133 WorldPacket data(SMSG_CONTACT_LIST, (4 + 4 + m_playerSocialMap.size() * 25)); // just can guess size
134 data << uint32(flags); // 0x1 = Friendlist update. 0x2 = Ignorelist update. 0x4 = Mutelist update.
135 size_t countPos = data.wpos();
136 data << uint32(0); // contacts count placeholder
137
138 for (auto& itr : m_playerSocialMap)
139 {
140 FriendInfo& friendInfo = itr.second;
141 uint8 contactFlags = friendInfo.Flags;
142 if (!(contactFlags & flags))
143 continue;
144
145 // Check client limit for friends list
146 if (contactFlags & SOCIAL_FLAG_FRIEND)
147 if (++friendsCount > SOCIALMGR_FRIEND_LIMIT)
148 continue;
149
150 // Check client limit for ignore list
151 if (contactFlags & SOCIAL_FLAG_IGNORED)
152 if (++ignoredCount > SOCIALMGR_IGNORE_LIMIT)
153 continue;
154
155 ++totalCount;
156
157 sSocialMgr->GetFriendInfo(player, itr.first, friendInfo);
158
159 data << itr.first; // player guid
160 data << uint32(contactFlags); // player flag (0x1 = Friend, 0x2 = Ignored, 0x4 = Muted)
161 data << friendInfo.Note; // string note
162 if (contactFlags & SOCIAL_FLAG_FRIEND) // if IsFriend()
163 {
164 data << uint8(friendInfo.Status); // online/offline/etc?
165 if (friendInfo.Status) // if online
166 {
167 data << uint32(friendInfo.Area); // player area
168 data << uint32(friendInfo.Level); // player level
169 data << uint32(friendInfo.Class); // player class
170 }
171 }
172 }
173
174 data.put<uint32>(countPos, totalCount);
175 player->GetSession()->SendPacket(&data);
176 LOG_DEBUG("network", "WORLD: Sent SMSG_CONTACT_LIST");
177}
std::uint8_t uint8
Definition: Define.h:110
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:171
#define sSocialMgr
Definition: SocialMgr.h:148
@ SMSG_CONTACT_LIST
Definition: Opcodes.h:133
WorldSession * GetSession() const
Definition: Player.h:1947
Definition: SocialMgr.h:49
FriendStatus Status
Definition: SocialMgr.h:50
uint8 Level
Definition: SocialMgr.h:53
uint8 Class
Definition: SocialMgr.h:54
std::string Note
Definition: SocialMgr.h:55
uint8 Flags
Definition: SocialMgr.h:51
uint32 Area
Definition: SocialMgr.h:52
Definition: WorldPacket.h:27
void SendPacket(WorldPacket const *packet)
Send a packet to the client.
Definition: WorldSession.cpp:208

References FriendInfo::Area, FriendInfo::Class, FriendInfo::Flags, Player::GetSession(), FriendInfo::Level, LOG_DEBUG, m_playerSocialMap, FriendInfo::Note, ByteBuffer::put(), WorldSession::SendPacket(), SMSG_CONTACT_LIST, SOCIAL_FLAG_FRIEND, SOCIAL_FLAG_IGNORED, SOCIALMGR_FRIEND_LIMIT, SOCIALMGR_IGNORE_LIMIT, sSocialMgr, FriendInfo::Status, and ByteBuffer::wpos().

Referenced by WorldSession::HandleContactListOpcode(), and Player::SendInitialPacketsBeforeAddToMap().

◆ SetFriendNote()

void PlayerSocial::SetFriendNote ( ObjectGuid  friendGuid,
std::string  note 
)
106{
107 auto itr = m_playerSocialMap.find(friendGuid);
108 if (itr == m_playerSocialMap.end()) // not exist
109 return;
110
111 utf8truncate(note, 48); // DB and client size limitation
112
114
115 stmt->SetData(0, note);
116 stmt->SetData(1, GetPlayerGUID().GetCounter());
117 stmt->SetData(2, friendGuid.GetCounter());
118
119 CharacterDatabase.Execute(stmt);
120
121 m_playerSocialMap[friendGuid].Note = note;
122}
void utf8truncate(std::string &utf8str, size_t len)
Definition: Util.cpp:259
@ CHAR_UPD_CHARACTER_SOCIAL_NOTE
Definition: CharacterDatabase.h:321
LowType GetCounter() const
Definition: ObjectGuid.h:147

References CHAR_UPD_CHARACTER_SOCIAL_NOTE, CharacterDatabase, ObjectGuid::GetCounter(), GetPlayerGUID(), m_playerSocialMap, PreparedStatementBase::SetData(), and utf8truncate().

Referenced by WorldSession::HandleAddFriendOpcode(), and WorldSession::HandleSetContactNotesOpcode().

◆ SetPlayerGUID()

void PlayerSocial::SetPlayerGUID ( ObjectGuid  guid)
inline
117{ m_playerGUID = guid; }

References m_playerGUID.

Referenced by SocialMgr::LoadFromDB().

Friends And Related Function Documentation

◆ SocialMgr

friend class SocialMgr
friend

Member Data Documentation

◆ m_playerGUID

ObjectGuid PlayerSocial::m_playerGUID
private

Referenced by GetPlayerGUID(), and SetPlayerGUID().

◆ m_playerSocialMap