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