Updated Copyright year to 2013
[getmangos.git] / src / game / SocialMgr.h
blob9c713b19470081c145ed3cc338a9461c7cd5aeed
1 /*
2 * Copyright (C) 2005-2013 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef __MANGOS_SOCIALMGR_H
20 #define __MANGOS_SOCIALMGR_H
22 #include "Policies/Singleton.h"
23 #include "Database/DatabaseEnv.h"
24 #include "ObjectGuid.h"
26 class SocialMgr;
27 class PlayerSocial;
28 class Player;
29 class WorldPacket;
31 enum FriendStatus
33 FRIEND_STATUS_OFFLINE = 0,
34 FRIEND_STATUS_ONLINE = 1,
35 FRIEND_STATUS_AFK = 2,
36 FRIEND_STATUS_UNK3 = 3,
37 FRIEND_STATUS_DND = 4
40 enum SocialFlag
42 SOCIAL_FLAG_FRIEND = 0x01,
43 SOCIAL_FLAG_IGNORED = 0x02,
44 SOCIAL_FLAG_MUTED = 0x04, // guessed
45 SOCIAL_FLAG_RAF = 0x08 // Recruit-A-Friend
48 struct FriendInfo
50 FriendStatus Status;
51 uint32 Flags;
52 uint32 Area;
53 uint32 Level;
54 uint32 Class;
55 std::string Note;
57 FriendInfo()
59 Status = FRIEND_STATUS_OFFLINE;
60 Flags = 0;
61 Area = 0;
62 Level = 0;
63 Class = 0;
64 Note = "";
67 FriendInfo(uint32 flags, const std::string& note)
69 Status = FRIEND_STATUS_OFFLINE;
70 Flags = flags;
71 Area = 0;
72 Level = 0;
73 Class = 0;
74 Note = note;
78 typedef std::map<uint32, FriendInfo> PlayerSocialMap;
79 typedef std::map<uint32, PlayerSocial> SocialMap;
81 /// Results of friend related commands
82 enum FriendsResult
84 FRIEND_DB_ERROR = 0x00, // ERR_FRIEND_NOT_FOUND
85 FRIEND_LIST_FULL = 0x01,
86 FRIEND_ONLINE = 0x02,
87 FRIEND_OFFLINE = 0x03,
88 FRIEND_NOT_FOUND = 0x04, // ERR_FRIEND_NOT_FOUND
89 FRIEND_REMOVED = 0x05,
90 FRIEND_ADDED_ONLINE = 0x06, // ERR_FRIEND_ADDED_S
91 FRIEND_ADDED_OFFLINE = 0x07,
92 FRIEND_ALREADY = 0x08,
93 FRIEND_SELF = 0x09,
94 FRIEND_ENEMY = 0x0A,
95 FRIEND_IGNORE_FULL = 0x0B,
96 FRIEND_IGNORE_SELF = 0x0C,
97 FRIEND_IGNORE_NOT_FOUND = 0x0D,
98 FRIEND_IGNORE_ALREADY = 0x0E,
99 FRIEND_IGNORE_ADDED = 0x0F,
100 FRIEND_IGNORE_REMOVED = 0x10,
101 FRIEND_IGNORE_AMBIGUOUS = 0x11, // That name is ambiguous, type more of the player's server name
102 FRIEND_MUTE_FULL = 0x12,
103 FRIEND_MUTE_SELF = 0x13,
104 FRIEND_MUTE_NOT_FOUND = 0x14,
105 FRIEND_MUTE_ALREADY = 0x15,
106 FRIEND_MUTE_ADDED = 0x16,
107 FRIEND_MUTE_REMOVED = 0x17,
108 FRIEND_MUTE_AMBIGUOUS = 0x18, // ERR_VOICE_IGNORE_AMBIGUOUS
109 FRIEND_UNK7 = 0x19, // ERR_MAX_VALUE (nothing is showed)
110 FRIEND_UNKNOWN = 0x1A // Unknown friend response from server
113 #define SOCIALMGR_FRIEND_LIMIT 50
114 #define SOCIALMGR_IGNORE_LIMIT 50
116 class PlayerSocial
118 friend class SocialMgr;
119 public:
120 PlayerSocial();
121 ~PlayerSocial();
122 // adding/removing
123 bool AddToSocialList(ObjectGuid friend_guid, bool ignore);
124 void RemoveFromSocialList(ObjectGuid friend_guid, bool ignore);
125 void SetFriendNote(ObjectGuid friend_guid, std::string note);
126 // Packet send's
127 void SendSocialList();
128 // Misc
129 bool HasFriend(ObjectGuid friend_guid);
130 bool HasIgnore(ObjectGuid ignore_guid);
131 void SetPlayerGuid(ObjectGuid guid) { m_playerLowGuid = guid.GetCounter(); }
132 uint32 GetNumberOfSocialsWithFlag(SocialFlag flag);
133 private:
134 PlayerSocialMap m_playerSocialMap;
135 uint32 m_playerLowGuid;
138 class SocialMgr
140 public:
141 SocialMgr();
142 ~SocialMgr();
143 // Misc
144 void RemovePlayerSocial(uint32 guid) { m_socialMap.erase(guid); }
146 void GetFriendInfo(Player* player, uint32 friendGUID, FriendInfo& friendInfo);
147 // Packet management
148 void MakeFriendStatusPacket(FriendsResult result, uint32 friend_guid, WorldPacket* data);
149 void SendFriendStatus(Player* player, FriendsResult result, ObjectGuid friend_guid, bool broadcast);
150 void BroadcastToFriendListers(Player* player, WorldPacket* packet);
151 // Loading
152 PlayerSocial* LoadFromDB(QueryResult* result, ObjectGuid guid);
153 private:
154 SocialMap m_socialMap;
157 #define sSocialMgr MaNGOS::Singleton<SocialMgr>::Instance()
158 #endif