AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
SocialMgr Class Reference

#include "SocialMgr.h"

Public Member Functions

void RemovePlayerSocial (ObjectGuid guid)
 
void MakeFriendStatusPacket (FriendsResult result, ObjectGuid friend_guid, WorldPacket *data)
 
void SendFriendStatus (Player *player, FriendsResult result, ObjectGuid friend_guid, bool broadcast)
 
void BroadcastToFriendListers (Player *player, WorldPacket *packet)
 
PlayerSocialLoadFromDB (PreparedQueryResult result, ObjectGuid guid)
 

Static Public Member Functions

static SocialMgrinstance ()
 
static void GetFriendInfo (Player *player, ObjectGuid friendGUID, FriendInfo &friendInfo)
 

Private Types

typedef std::map< ObjectGuid, PlayerSocialSocialMap
 

Private Member Functions

 SocialMgr ()
 
 ~SocialMgr ()
 

Private Attributes

SocialMap m_socialMap
 

Detailed Description

Member Typedef Documentation

◆ SocialMap

typedef std::map<ObjectGuid, PlayerSocial> SocialMgr::SocialMap
private

Constructor & Destructor Documentation

◆ SocialMgr()

SocialMgr::SocialMgr ( )
private
199{
200}

◆ ~SocialMgr()

SocialMgr::~SocialMgr ( )
private
203{
204}

Member Function Documentation

◆ BroadcastToFriendListers()

void SocialMgr::BroadcastToFriendListers ( Player player,
WorldPacket packet 
)
295{
296 if (!player)
297 return;
298
299 TeamId teamId = player->GetTeamId();
300 AccountTypes security = player->GetSession()->GetSecurity();
301 bool allowTwoSideWhoList = sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_WHO_LIST);
302 AccountTypes gmLevelInWhoList = AccountTypes(sWorld->getIntConfig(CONFIG_GM_LEVEL_IN_WHO_LIST));
303
304 for (auto const& itr : m_socialMap)
305 {
306 auto const& itr2 = itr.second.m_playerSocialMap.find(player->GetGUID());
307 if (itr2 != itr.second.m_playerSocialMap.end() && (itr2->second.Flags & SOCIAL_FLAG_FRIEND))
308 {
309 Player* pFriend = ObjectAccessor::FindPlayer(itr.first);
310
311 // PLAYER see his team only and PLAYER can't see MODERATOR, GAME MASTER, ADMINISTRATOR characters
312 // MODERATOR, GAME MASTER, ADMINISTRATOR can see all
313 if (pFriend && (!AccountMgr::IsPlayerAccount(pFriend->GetSession()->GetSecurity()) || ((pFriend->GetTeamId() == teamId || allowTwoSideWhoList) && security <= gmLevelInWhoList)) && player->IsVisibleGloballyFor(pFriend))
314 pFriend->GetSession()->SendPacket(packet);
315 }
316 }
317}
AccountTypes
Definition: Common.h:56
TeamId
Definition: SharedDefines.h:759
@ CONFIG_GM_LEVEL_IN_WHO_LIST
Definition: IWorld.h:260
@ CONFIG_ALLOW_TWO_SIDE_WHO_LIST
Definition: IWorld.h:80
@ SOCIAL_FLAG_FRIEND
Definition: SocialMgr.h:39
#define sWorld
Definition: World.h:443
bool IsPlayerAccount(uint32 gmlevel)
Definition: AccountMgr.cpp:305
Player * FindPlayer(ObjectGuid const guid)
Definition: ObjectAccessor.cpp:245
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:112
Definition: Player.h:1081
TeamId GetTeamId(bool original=false) const
Definition: Player.h:2108
WorldSession * GetSession() const
Definition: Player.h:1998
bool IsVisibleGloballyFor(Player const *player) const
Definition: Player.cpp:11518
SocialMap m_socialMap
Definition: SocialMgr.h:144
void SendPacket(WorldPacket const *packet)
Send a packet to the client.
Definition: WorldSession.cpp:214
AccountTypes GetSecurity() const
Definition: WorldSession.h:359

References CONFIG_ALLOW_TWO_SIDE_WHO_LIST, CONFIG_GM_LEVEL_IN_WHO_LIST, ObjectAccessor::FindPlayer(), Object::GetGUID(), WorldSession::GetSecurity(), Player::GetSession(), Player::GetTeamId(), AccountMgr::IsPlayerAccount(), Player::IsVisibleGloballyFor(), m_socialMap, WorldSession::SendPacket(), SOCIAL_FLAG_FRIEND, and sWorld.

Referenced by SendFriendStatus().

◆ GetFriendInfo()

void SocialMgr::GetFriendInfo ( Player player,
ObjectGuid  friendGUID,
FriendInfo friendInfo 
)
static
213{
214 if (!player)
215 return;
216
217 friendInfo.Status = FRIEND_STATUS_OFFLINE;
218 friendInfo.Area = 0;
219 friendInfo.Level = 0;
220 friendInfo.Class = 0;
221
222 Player* pFriend = ObjectAccessor::FindConnectedPlayer(friendGUID);
223 if (!pFriend || pFriend->GetSession()->IsGMAccount())
224 return;
225
226 TeamId teamId = player->GetTeamId();
227 AccountTypes security = player->GetSession()->GetSecurity();
228 bool allowTwoSideWhoList = sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_WHO_LIST);
229 AccountTypes gmLevelInWhoList = AccountTypes(sWorld->getIntConfig(CONFIG_GM_LEVEL_IN_WHO_LIST));
230
231 auto const& itr = player->GetSocial()->m_playerSocialMap.find(friendGUID);
232 if (itr != player->GetSocial()->m_playerSocialMap.end())
233 friendInfo.Note = itr->second.Note;
234
235 // PLAYER see his team only and PLAYER can't see MODERATOR, GAME MASTER, ADMINISTRATOR characters
236 // MODERATOR, GAME MASTER, ADMINISTRATOR can see all
237 if ((!AccountMgr::IsPlayerAccount(security) || ((pFriend->GetTeamId() == teamId || allowTwoSideWhoList) && pFriend->GetSession()->GetSecurity() <= gmLevelInWhoList)) && pFriend->IsVisibleGloballyFor(player))
238 {
239 friendInfo.Status = FRIEND_STATUS_ONLINE;
240 if (pFriend->isAFK())
241 friendInfo.Status = FRIEND_STATUS_AFK;
242 if (pFriend->isDND())
243 friendInfo.Status = FRIEND_STATUS_DND;
244 friendInfo.Area = pFriend->GetZoneId();
245 friendInfo.Level = pFriend->GetLevel();
246 friendInfo.Class = pFriend->getClass();
247 }
248}
@ FRIEND_STATUS_AFK
Definition: SocialMgr.h:32
@ FRIEND_STATUS_DND
Definition: SocialMgr.h:33
@ FRIEND_STATUS_OFFLINE
Definition: SocialMgr.h:30
@ FRIEND_STATUS_ONLINE
Definition: SocialMgr.h:31
Player * FindConnectedPlayer(ObjectGuid const guid)
Definition: ObjectAccessor.cpp:257
uint32 GetZoneId() const
Definition: Object.cpp:3157
bool isDND() const
Definition: Player.h:1152
PlayerSocial * GetSocial()
Definition: Player.h:1158
bool isAFK() const
Definition: Player.h:1151
FriendStatus Status
Definition: SocialMgr.h:49
uint8 Level
Definition: SocialMgr.h:52
uint8 Class
Definition: SocialMgr.h:53
std::string Note
Definition: SocialMgr.h:54
uint32 Area
Definition: SocialMgr.h:51
PlayerSocialMap m_playerSocialMap
Definition: SocialMgr.h:121
uint8 getClass() const
Definition: Unit.h:800
uint8 GetLevel() const
Definition: Unit.h:1024
bool IsGMAccount() const
Definition: WorldSession.cpp:181

References FriendInfo::Area, FriendInfo::Class, CONFIG_ALLOW_TWO_SIDE_WHO_LIST, CONFIG_GM_LEVEL_IN_WHO_LIST, ObjectAccessor::FindConnectedPlayer(), FRIEND_STATUS_AFK, FRIEND_STATUS_DND, FRIEND_STATUS_OFFLINE, FRIEND_STATUS_ONLINE, Unit::getClass(), Unit::GetLevel(), WorldSession::GetSecurity(), Player::GetSession(), Player::GetSocial(), Player::GetTeamId(), WorldObject::GetZoneId(), Player::isAFK(), Player::isDND(), WorldSession::IsGMAccount(), AccountMgr::IsPlayerAccount(), Player::IsVisibleGloballyFor(), FriendInfo::Level, PlayerSocial::m_playerSocialMap, FriendInfo::Note, FriendInfo::Status, and sWorld.

Referenced by SendFriendStatus().

◆ instance()

SocialMgr * SocialMgr::instance ( )
static
207{
208 static SocialMgr instance;
209 return &instance;
210}
Definition: SocialMgr.h:126
static SocialMgr * instance()
Definition: SocialMgr.cpp:206

References instance().

Referenced by instance().

◆ LoadFromDB()

PlayerSocial * SocialMgr::LoadFromDB ( PreparedQueryResult  result,
ObjectGuid  guid 
)
320{
321 PlayerSocial* social = &m_socialMap[guid];
322 social->SetPlayerGUID(guid);
323
324 if (!result)
325 return social;
326
327 do
328 {
329 Field* fields = result->Fetch();
330
331 auto friendGuid = ObjectGuid::Create<HighGuid::Player>(fields[0].Get<uint32>());
332 auto flags = fields[1].Get<uint8>();
333 auto note = fields[2].Get<std::string>();
334
335 social->m_playerSocialMap[friendGuid] = FriendInfo(flags, note);
336 } while (result->NextRow());
337
338 return social;
339}
std::uint8_t uint8
Definition: Define.h:109
Class used to access individual fields of database query result.
Definition: Field.h:98
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:112
Definition: SocialMgr.h:48
Definition: SocialMgr.h:101
void SetPlayerGUID(ObjectGuid guid)
Definition: SocialMgr.h:116

References Field::Get(), PlayerSocial::m_playerSocialMap, m_socialMap, and PlayerSocial::SetPlayerGUID().

◆ MakeFriendStatusPacket()

void SocialMgr::MakeFriendStatusPacket ( FriendsResult  result,
ObjectGuid  friend_guid,
WorldPacket data 
)
251{
253 *data << uint8(result);
254 *data << guid;
255}
@ SMSG_FRIEND_STATUS
Definition: Opcodes.h:134
void Initialize(uint16 opcode, std::size_t newres=200)
Definition: WorldPacket.h:68

References WorldPacket::Initialize(), and SMSG_FRIEND_STATUS.

◆ RemovePlayerSocial()

void SocialMgr::RemovePlayerSocial ( ObjectGuid  guid)
inline
134{ m_socialMap.erase(guid); }

References m_socialMap.

◆ SendFriendStatus()

void SocialMgr::SendFriendStatus ( Player player,
FriendsResult  result,
ObjectGuid  friend_guid,
bool  broadcast 
)
258{
259 FriendInfo fi;
260 GetFriendInfo(player, friendGuid, fi);
261
263 data << uint8(result);
264 data << friendGuid;
265 switch (result)
266 {
269 data << fi.Note;
270 break;
271 default:
272 break;
273 }
274
275 switch (result)
276 {
278 case FRIEND_ONLINE:
279 data << uint8(fi.Status);
280 data << uint32(fi.Area);
281 data << uint32(fi.Level);
282 data << uint32(fi.Class);
283 break;
284 default:
285 break;
286 }
287
288 if (broadcast)
289 BroadcastToFriendListers(player, &data);
290 else
291 player->GetSession()->SendPacket(&data);
292}
std::uint32_t uint32
Definition: Define.h:107
@ FRIEND_ONLINE
Definition: SocialMgr.h:68
@ FRIEND_ADDED_OFFLINE
Definition: SocialMgr.h:73
@ FRIEND_ADDED_ONLINE
Definition: SocialMgr.h:72
static void GetFriendInfo(Player *player, ObjectGuid friendGUID, FriendInfo &friendInfo)
Definition: SocialMgr.cpp:212
void BroadcastToFriendListers(Player *player, WorldPacket *packet)
Definition: SocialMgr.cpp:294
Definition: WorldPacket.h:26

References FriendInfo::Area, BroadcastToFriendListers(), FriendInfo::Class, FRIEND_ADDED_OFFLINE, FRIEND_ADDED_ONLINE, FRIEND_ONLINE, GetFriendInfo(), Player::GetSession(), FriendInfo::Level, FriendInfo::Note, WorldSession::SendPacket(), SMSG_FRIEND_STATUS, and FriendInfo::Status.

Member Data Documentation

◆ m_socialMap

SocialMap SocialMgr::m_socialMap
private