OregonCore  revision fb2a440-git
Your Favourite TBC server
PlayerSocial Class Reference

#include <SocialMgr.h>

Public Member Functions

 PlayerSocial ()
 
 ~PlayerSocial ()
 
bool AddToSocialList (uint32 friend_guid, bool ignore)
 
void RemoveFromSocialList (uint32 friend_guid, bool ignore)
 
void SetFriendNote (uint32 friend_guid, std::string note)
 
void SendSocialList ()
 
bool HasFriend (uint32 friend_guid)
 
bool HasIgnore (uint32 ignore_guid)
 
uint32 GetPlayerGUID ()
 
void SetPlayerGUID (uint32 guid)
 
uint32 GetNumberOfSocialsWithFlag (SocialFlag flag)
 

Private Attributes

PlayerSocialMap m_playerSocialMap
 
uint32 m_playerGUID
 

Friends

class SocialMgr
 

Detailed Description

Definition at line 115 of file SocialMgr.h.

Constructor & Destructor Documentation

PlayerSocial::PlayerSocial ( )

Definition at line 31 of file SocialMgr.cpp.

References m_playerGUID.

32 {
33  m_playerGUID = 0;
34 }
uint32 m_playerGUID
Definition: SocialMgr.h:141
PlayerSocial::~PlayerSocial ( )

Definition at line 36 of file SocialMgr.cpp.

References m_playerSocialMap.

37 {
38  m_playerSocialMap.clear();
39 }
PlayerSocialMap m_playerSocialMap
Definition: SocialMgr.h:140

Member Function Documentation

bool PlayerSocial::AddToSocialList ( uint32  friend_guid,
bool  ignore 
)

Definition at line 52 of file SocialMgr.cpp.

References CharacterDatabase, FriendInfo::Flags, GetNumberOfSocialsWithFlag(), GetPlayerGUID(), m_playerSocialMap, Database::PExecute(), SOCIAL_FLAG_FRIEND, SOCIAL_FLAG_IGNORED, SOCIALMGR_FRIEND_LIMIT, and SOCIALMGR_IGNORE_LIMIT.

Referenced by WorldSession::HandleAddFriendOpcodeCallBack(), and WorldSession::HandleAddIgnoreOpcodeCallBack().

53 {
54  // check client limits
55  if (ignore)
56  {
58  return false;
59  }
60  else
61  {
63  return false;
64  }
65 
67  if (ignore)
68  flag = SOCIAL_FLAG_IGNORED;
69 
70  PlayerSocialMap::iterator itr = m_playerSocialMap.find(friend_guid);
71  if (itr != m_playerSocialMap.end())
72  {
73  CharacterDatabase.PExecute("UPDATE character_social SET flags = (flags | %u) WHERE guid = '%u' AND friend = '%u'", flag, GetPlayerGUID(), friend_guid);
74  m_playerSocialMap[friend_guid].Flags |= flag;
75  }
76  else
77  {
78  CharacterDatabase.PExecute("INSERT INTO character_social (guid, friend, flags) VALUES ('%u', '%u', '%u')", GetPlayerGUID(), friend_guid, flag);
79  FriendInfo fi;
80  fi.Flags |= flag;
81  m_playerSocialMap[friend_guid] = fi;
82  }
83  return true;
84 }
#define SOCIALMGR_FRIEND_LIMIT
Definition: SocialMgr.h:112
bool PExecute(const char *format,...) ATTR_PRINTF(2
Definition: Database.cpp:441
uint32 Flags
Definition: SocialMgr.h:50
PlayerSocialMap m_playerSocialMap
Definition: SocialMgr.h:140
uint32 GetPlayerGUID()
Definition: SocialMgr.h:130
#define SOCIALMGR_IGNORE_LIMIT
Definition: SocialMgr.h:113
DatabaseType CharacterDatabase
Accessor to the character database.
Definition: Main.cpp:54
ACE_UINT32 uint32
Definition: Define.h:71
uint32 GetNumberOfSocialsWithFlag(SocialFlag flag)
Definition: SocialMgr.cpp:41
uint32 PlayerSocial::GetNumberOfSocialsWithFlag ( SocialFlag  flag)

Definition at line 41 of file SocialMgr.cpp.

References m_playerSocialMap.

Referenced by AddToSocialList().

42 {
43  uint32 counter = 0;
44  for (PlayerSocialMap::iterator itr = m_playerSocialMap.begin(); itr != m_playerSocialMap.end(); ++itr)
45  {
46  if (itr->second.Flags & flag)
47  counter++;
48  }
49  return counter;
50 }
PlayerSocialMap m_playerSocialMap
Definition: SocialMgr.h:140
ACE_UINT32 uint32
Definition: Define.h:71
uint32 PlayerSocial::GetPlayerGUID ( )
inline

Definition at line 130 of file SocialMgr.h.

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

131  {
132  return m_playerGUID;
133  }
uint32 m_playerGUID
Definition: SocialMgr.h:141
bool PlayerSocial::HasFriend ( uint32  friend_guid)

Definition at line 154 of file SocialMgr.cpp.

References m_playerSocialMap, and SOCIAL_FLAG_FRIEND.

Referenced by WorldSession::HandleAddFriendOpcodeCallBack().

155 {
156  PlayerSocialMap::iterator itr = m_playerSocialMap.find(friend_guid);
157  if (itr != m_playerSocialMap.end())
158  return itr->second.Flags & SOCIAL_FLAG_FRIEND;
159  return false;
160 }
PlayerSocialMap m_playerSocialMap
Definition: SocialMgr.h:140
bool PlayerSocial::HasIgnore ( uint32  ignore_guid)
void PlayerSocial::RemoveFromSocialList ( uint32  friend_guid,
bool  ignore 
)

Definition at line 86 of file SocialMgr.cpp.

References CharacterDatabase, GetPlayerGUID(), m_playerSocialMap, Database::PExecute(), SOCIAL_FLAG_FRIEND, and SOCIAL_FLAG_IGNORED.

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

87 {
88  PlayerSocialMap::iterator itr = m_playerSocialMap.find(friend_guid);
89  if (itr == m_playerSocialMap.end()) // not exist
90  return;
91 
93  if (ignore)
94  flag = SOCIAL_FLAG_IGNORED;
95 
96  itr->second.Flags &= ~flag;
97  if (itr->second.Flags == 0)
98  {
99  CharacterDatabase.PExecute("DELETE FROM character_social WHERE guid = '%u' AND friend = '%u'", GetPlayerGUID(), friend_guid);
100  m_playerSocialMap.erase(itr);
101  }
102  else
103  CharacterDatabase.PExecute("UPDATE character_social SET flags = (flags & ~%u) WHERE guid = '%u' AND friend = '%u'", flag, GetPlayerGUID(), friend_guid);
104 }
bool PExecute(const char *format,...) ATTR_PRINTF(2
Definition: Database.cpp:441
PlayerSocialMap m_playerSocialMap
Definition: SocialMgr.h:140
uint32 GetPlayerGUID()
Definition: SocialMgr.h:130
DatabaseType CharacterDatabase
Accessor to the character database.
Definition: Main.cpp:54
ACE_UINT32 uint32
Definition: Define.h:71
void PlayerSocial::SendSocialList ( )

Definition at line 119 of file SocialMgr.cpp.

References GetPlayerGUID(), Player::GetSession(), m_playerSocialMap, WorldSession::SendPacket(), sLog, SMSG_CONTACT_LIST, sObjectMgr, SOCIAL_FLAG_FRIEND, and sSocialMgr.

Referenced by WorldSession::HandleFriendListOpcode(), and WorldSession::HandlePlayerLogin().

120 {
121  Player* plr = sObjectMgr.GetPlayer(GetPlayerGUID());
122  if (!plr)
123  return;
124 
125  uint32 size = m_playerSocialMap.size();
126 
127  WorldPacket data(SMSG_CONTACT_LIST, (4 + 4 + size * 25)); // just can guess size
128  data << uint32(7); // unk flag (0x1, 0x2, 0x4), 0x7 if it include ignore list
129  data << uint32(size); // friends count
130 
131  for (PlayerSocialMap::iterator itr = m_playerSocialMap.begin(); itr != m_playerSocialMap.end(); ++itr)
132  {
133  sSocialMgr.GetFriendInfo(plr, itr->first, itr->second);
134 
135  data << uint64(itr->first); // player guid
136  data << uint32(itr->second.Flags); // player flag (0x1-friend?, 0x2-ignored?, 0x4-muted?)
137  data << itr->second.Note; // string note
138  if (itr->second.Flags & SOCIAL_FLAG_FRIEND) // if IsFriend()
139  {
140  data << uint8(itr->second.Status); // online/offline/etc?
141  if (itr->second.Status) // if online
142  {
143  data << uint32(itr->second.Area); // player area
144  data << uint32(itr->second.Level); // player level
145  data << uint32(itr->second.Class); // player class
146  }
147  }
148  }
149 
150  plr->GetSession()->SendPacket(&data);
151  sLog.outDebug("WORLD: Sent SMSG_CONTACT_LIST");
152 }
#define sLog
Log class singleton.
Definition: Log.h:187
#define sObjectMgr
Definition: ObjectMgr.h:1285
void SendPacket(WorldPacket const *packet)
ACE_UINT8 uint8
Definition: Define.h:73
#define sSocialMgr
Definition: SocialMgr.h:166
PlayerSocialMap m_playerSocialMap
Definition: SocialMgr.h:140
ACE_UINT64 uint64
Definition: Define.h:70
uint32 GetPlayerGUID()
Definition: SocialMgr.h:130
WorldSession * GetSession() const
Definition: Player.h:1944
ACE_UINT32 uint32
Definition: Define.h:71
Definition: Player.h:922
void PlayerSocial::SetFriendNote ( uint32  friend_guid,
std::string  note 
)

Definition at line 106 of file SocialMgr.cpp.

References CharacterDatabase, Database::escape_string(), GetPlayerGUID(), m_playerSocialMap, Database::PExecute(), and utf8truncate().

Referenced by WorldSession::HandleAddFriendOpcodeCallBack(), and WorldSession::HandleSetFriendNoteOpcode().

107 {
108  PlayerSocialMap::iterator itr = m_playerSocialMap.find(friend_guid);
109  if (itr == m_playerSocialMap.end()) // not exist
110  return;
111 
112  utf8truncate(note, 48); // DB and client size limitation
113 
115  CharacterDatabase.PExecute("UPDATE character_social SET note = '%s' WHERE guid = '%u' AND friend = '%u'", note.c_str(), GetPlayerGUID(), friend_guid);
116  m_playerSocialMap[friend_guid].Note = note;
117 }
void utf8truncate(std::string &utf8str, size_t len)
Definition: Util.cpp:234
unsigned long escape_string(char *to, const char *from, unsigned long length)
Definition: Database.cpp:212
bool PExecute(const char *format,...) ATTR_PRINTF(2
Definition: Database.cpp:441
PlayerSocialMap m_playerSocialMap
Definition: SocialMgr.h:140
uint32 GetPlayerGUID()
Definition: SocialMgr.h:130
DatabaseType CharacterDatabase
Accessor to the character database.
Definition: Main.cpp:54
void PlayerSocial::SetPlayerGUID ( uint32  guid)
inline

Definition at line 134 of file SocialMgr.h.

Referenced by SocialMgr::LoadFromDB().

135  {
136  m_playerGUID = guid;
137  }
uint32 m_playerGUID
Definition: SocialMgr.h:141

Friends And Related Function Documentation

friend class SocialMgr
friend

Definition at line 117 of file SocialMgr.h.

Member Data Documentation

uint32 PlayerSocial::m_playerGUID
private

Definition at line 141 of file SocialMgr.h.

Referenced by PlayerSocial().


The documentation for this class was generated from the following files: