TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SocialMgr.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef __TRINITY_SOCIALMGR_H
20 #define __TRINITY_SOCIALMGR_H
21 
22 #include "DatabaseEnv.h"
23 #include "Common.h"
24 #include "ObjectGuid.h"
25 
26 class Player;
27 class WorldPacket;
28 
30 {
36 };
37 
39 {
42  SOCIAL_FLAG_MUTED = 0x04, // guessed
43  SOCIAL_FLAG_UNK = 0x08, // Unknown - does not appear to be RaF
44 
46 };
47 
48 struct FriendInfo
49 {
56  std::string Note;
57 
58  FriendInfo() : Status(FRIEND_STATUS_OFFLINE), Flags(0), Area(0), Level(0), Class(0), Note()
59  { }
60 
61  FriendInfo(ObjectGuid const& accountGuid, uint8 flags, std::string const& note) : WowAccountGuid(accountGuid), Status(FRIEND_STATUS_OFFLINE),
62  Flags(flags), Area(0), Level(0), Class(0), Note(note)
63  { }
64 };
65 
68 {
71  FRIEND_ONLINE = 0x02,
78  FRIEND_SELF = 0x09,
79  FRIEND_ENEMY = 0x0A,
86  FRIEND_IGNORE_AMBIGUOUS = 0x11, // That name is ambiguous, type more of the player's server name
93  FRIEND_MUTE_AMBIGUOUS = 0x18, // That name is ambiguous, type more of the player's server name
94  FRIEND_UNK1 = 0x19, // no message at client
95  FRIEND_UNK2 = 0x1A,
96  FRIEND_UNK3 = 0x1B,
97  FRIEND_UNKNOWN = 0x1C // Unknown friend response from server
98 };
99 
100 #define SOCIALMGR_FRIEND_LIMIT 50u
101 #define SOCIALMGR_IGNORE_LIMIT 50u
102 
104 {
105  friend class SocialMgr;
106 
107  public:
108  // adding/removing
109  bool AddToSocialList(ObjectGuid const& guid, SocialFlag flag);
110  void RemoveFromSocialList(ObjectGuid const& guid, SocialFlag flag);
111  void SetFriendNote(ObjectGuid const& guid, std::string const& note);
112 
113  // Packet send's
114  void SendSocialList(Player* player, uint32 flags);
115 
116  // Misc
117  bool HasFriend(ObjectGuid const& friendGuid);
118  bool HasIgnore(ObjectGuid const& ignoreGuid);
119 
120  ObjectGuid const& GetPlayerGUID() const { return _playerGUID; }
121  void SetPlayerGUID(ObjectGuid const& guid) { _playerGUID = guid; }
122 
123  uint32 GetNumberOfSocialsWithFlag(SocialFlag flag);
124 
125  private:
126  bool _HasContact(ObjectGuid const& guid, SocialFlag flags);
127 
128  typedef std::map<ObjectGuid, FriendInfo> PlayerSocialMap;
129  PlayerSocialMap _playerSocialMap;
130 
132 };
133 
135 {
136  private:
137  SocialMgr() { }
139 
140  public:
141  static SocialMgr* instance();
142 
143  // Misc
144  void RemovePlayerSocial(ObjectGuid const& guid) { _socialMap.erase(guid); }
145 
146  void GetFriendInfo(Player* player, ObjectGuid const& friendGUID, FriendInfo& friendInfo);
147 
148  // Packet send's
149  void SendFriendStatus(Player* player, FriendsResult result, ObjectGuid const& friendGuid, bool broadcast = false);
150  void BroadcastToFriendListers(Player* player, WorldPacket const* packet);
151 
152  // Loading
154 
155  private:
156  typedef std::map<ObjectGuid, PlayerSocial> SocialMap;
157  SocialMap _socialMap;
158 };
159 
160 #define sSocialMgr SocialMgr::instance()
161 
162 #endif
ObjectGuid const & GetPlayerGUID() const
Definition: SocialMgr.h:120
Definition: SocialMgr.h:97
FriendsResult
Results of friend related commands.
Definition: SocialMgr.h:67
Definition: SocialMgr.h:93
Definition: SocialMgr.h:42
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
Definition: SocialMgr.h:94
Definition: SocialMgr.h:82
Definition: SocialMgr.h:77
SocialFlag
Definition: SocialMgr.h:38
std::string Note
Definition: SocialMgr.h:56
Definition: SocialMgr.h:48
SocialMap _socialMap
Definition: SocialMgr.h:157
void SendFriendStatus(Player *player, FriendsResult result, ObjectGuid const &friendGuid, bool broadcast=false)
Definition: SocialMgr.cpp:214
Definition: SocialMgr.h:35
Definition: SocialMgr.h:81
Definition: SocialMgr.h:34
Definition: SocialMgr.h:41
Definition: SocialMgr.h:134
void BroadcastToFriendListers(Player *player, WorldPacket const *packet)
Definition: SocialMgr.cpp:228
Definition: SocialMgr.h:71
Definition: SocialMgr.h:78
FriendStatus Status
Definition: SocialMgr.h:51
Definition: SocialMgr.h:83
std::map< ObjectGuid, PlayerSocial > SocialMap
Definition: SocialMgr.h:156
FriendInfo(ObjectGuid const &accountGuid, uint8 flags, std::string const &note)
Definition: SocialMgr.h:61
Definition: SocialMgr.h:75
void RemovePlayerSocial(ObjectGuid const &guid)
Definition: SocialMgr.h:144
SocialMgr()
Definition: SocialMgr.h:137
Definition: SocialMgr.h:87
Definition: SocialMgr.h:96
Definition: SocialMgr.h:95
~SocialMgr()
Definition: SocialMgr.h:138
Definition: SocialMgr.h:103
uint8 Level
Definition: SocialMgr.h:54
Definition: SocialMgr.h:74
Definition: SocialMgr.h:45
Definition: SocialMgr.h:73
Definition: SocialMgr.h:90
uint32_t uint32
Definition: Define.h:150
static SocialMgr * instance()
Definition: SocialMgr.cpp:164
Definition: SocialMgr.h:31
uint8 Flags
Definition: SocialMgr.h:52
void SetPlayerGUID(ObjectGuid const &guid)
Definition: SocialMgr.h:121
Definition: SocialMgr.h:84
ObjectGuid WowAccountGuid
Definition: SocialMgr.h:50
Definition: SocialMgr.h:89
Definition: SocialMgr.h:72
Definition: SocialMgr.h:80
uint8 Class
Definition: SocialMgr.h:55
uint32 Area
Definition: SocialMgr.h:53
void GetFriendInfo(Player *player, ObjectGuid const &friendGUID, FriendInfo &friendInfo)
Definition: SocialMgr.cpp:170
#define TC_GAME_API
Definition: Define.h:134
Definition: SocialMgr.h:92
PlayerSocialMap _playerSocialMap
Definition: SocialMgr.h:129
Definition: SocialMgr.h:33
ObjectGuid _playerGUID
Definition: SocialMgr.h:131
PlayerSocial * LoadFromDB(PreparedQueryResult result, ObjectGuid const &guid)
Definition: SocialMgr.cpp:255
Definition: SocialMgr.h:32
uint8_t uint8
Definition: Define.h:152
Definition: SocialMgr.h:69
Definition: SocialMgr.h:76
Definition: SocialMgr.h:88
Definition: SocialMgr.h:91
Definition: SocialMgr.h:70
Definition: ObjectGuid.h:189
uint8 flags
Definition: DisableMgr.cpp:44
FriendStatus
Definition: SocialMgr.h:29
FriendInfo()
Definition: SocialMgr.h:58
Definition: SocialMgr.h:43
Definition: SocialMgr.h:40
Definition: WorldPacket.h:26
Definition: SocialMgr.h:79
Definition: SocialMgr.h:85
Definition: SocialMgr.h:86
std::map< ObjectGuid, FriendInfo > PlayerSocialMap
Definition: SocialMgr.h:128