[6982] Implemented gmlevel-based command security
[getmangos.git] / src / game / SocialMgr.h
blob0a7f822a798b1de3cec6e605cd02fa1059766a49
1 /*
2 * Copyright (C) 2005-2008 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 "Common.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
47 struct FriendInfo
49 FriendStatus Status;
50 uint32 Flags;
51 uint32 Area;
52 uint32 Level;
53 uint32 Class;
54 std::string Note;
56 FriendInfo()
58 Status = FRIEND_STATUS_OFFLINE;
59 Flags = 0;
60 Area = 0;
61 Level = 0;
62 Class = 0;
63 Note = "";
66 FriendInfo(uint32 flags, const std::string& note)
68 Status = FRIEND_STATUS_OFFLINE;
69 Flags = flags;
70 Area = 0;
71 Level = 0;
72 Class = 0;
73 Note = note;
77 typedef std::map<uint32, FriendInfo> PlayerSocialMap;
78 typedef std::map<uint32, PlayerSocial> SocialMap;
80 /// Results of friend related commands
81 enum FriendsResult
83 FRIEND_DB_ERROR = 0x00,
84 FRIEND_LIST_FULL = 0x01,
85 FRIEND_ONLINE = 0x02,
86 FRIEND_OFFLINE = 0x03,
87 FRIEND_NOT_FOUND = 0x04,
88 FRIEND_REMOVED = 0x05,
89 FRIEND_ADDED_ONLINE = 0x06,
90 FRIEND_ADDED_OFFLINE = 0x07,
91 FRIEND_ALREADY = 0x08,
92 FRIEND_SELF = 0x09,
93 FRIEND_ENEMY = 0x0A,
94 FRIEND_IGNORE_FULL = 0x0B,
95 FRIEND_IGNORE_SELF = 0x0C,
96 FRIEND_IGNORE_NOT_FOUND = 0x0D,
97 FRIEND_IGNORE_ALREADY = 0x0E,
98 FRIEND_IGNORE_ADDED = 0x0F,
99 FRIEND_IGNORE_REMOVED = 0x10,
100 FRIEND_IGNORE_AMBIGUOUS = 0x11, // That name is ambiguous, type more of the player's server name
101 FRIEND_MUTE_FULL = 0x12,
102 FRIEND_MUTE_SELF = 0x13,
103 FRIEND_MUTE_NOT_FOUND = 0x14,
104 FRIEND_MUTE_ALREADY = 0x15,
105 FRIEND_MUTE_ADDED = 0x16,
106 FRIEND_MUTE_REMOVED = 0x17,
107 FRIEND_MUTE_AMBIGUOUS = 0x18, // That name is ambiguous, type more of the player's server name
108 FRIEND_UNK7 = 0x19, // no message at client
109 FRIEND_UNKNOWN = 0x1A // Unknown friend response from server
112 #define SOCIALMGR_FRIEND_LIMIT 50
113 #define SOCIALMGR_IGNORE_LIMIT 25
115 class PlayerSocial
117 friend class SocialMgr;
118 public:
119 PlayerSocial();
120 ~PlayerSocial();
121 // adding/removing
122 bool AddToSocialList(uint32 friend_guid, bool ignore);
123 void RemoveFromSocialList(uint32 friend_guid, bool ignore);
124 void SetFriendNote(uint32 friend_guid, std::string note);
125 // Packet send's
126 void SendSocialList();
127 // Misc
128 bool HasFriend(uint32 friend_guid);
129 bool HasIgnore(uint32 ignore_guid);
130 uint32 GetPlayerGUID() { return m_playerGUID; }
131 void SetPlayerGUID(uint32 guid) { m_playerGUID = guid; }
132 uint32 GetNumberOfSocialsWithFlag(SocialFlag flag);
133 private:
134 PlayerSocialMap m_playerSocialMap;
135 uint32 m_playerGUID;
138 class SocialMgr
140 public:
141 SocialMgr();
142 ~SocialMgr();
143 // Misc
144 void RemovePlayerSocial(uint32 guid);
145 void GetFriendInfo(Player *player, uint32 friendGUID, FriendInfo &friendInfo);
146 // Packet management
147 void MakeFriendStatusPacket(FriendsResult result, uint32 friend_guid, WorldPacket *data);
148 void SendFriendStatus(Player *player, FriendsResult result, uint32 friend_guid, bool broadcast);
149 void BroadcastToFriendListers(Player *player, WorldPacket *packet);
150 // Loading
151 PlayerSocial *LoadFromDB(QueryResult *result, uint32 guid);
152 private:
153 SocialMap m_socialMap;
156 #define sSocialMgr MaNGOS::Singleton<SocialMgr>::Instance()
157 #endif