TrinityCore
Channel.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef _CHANNEL_H
19#define _CHANNEL_H
20
21#include "Common.h"
22#include "ObjectGuid.h"
23#include <ctime>
24#include <map>
25#include <unordered_set>
26
27class Player;
28struct AreaTableEntry;
29
30namespace WorldPackets
31{
32 namespace Channel
33 {
34 class ChannelNotify;
35 }
36}
37
38// EnumUtils: DESCRIBE THIS
40{
41 CHAT_JOINED_NOTICE = 0x00, //+ "%s joined channel.";
42 CHAT_LEFT_NOTICE = 0x01, //+ "%s left channel.";
43 //CHAT_SUSPENDED_NOTICE = 0x01, // "%s left channel.";
44 CHAT_YOU_JOINED_NOTICE = 0x02, //+ "Joined Channel: [%s]"; -- You joined
45 //CHAT_YOU_CHANGED_NOTICE = 0x02, // "Changed Channel: [%s]";
46 CHAT_YOU_LEFT_NOTICE = 0x03, //+ "Left Channel: [%s]"; -- You left
47 CHAT_WRONG_PASSWORD_NOTICE = 0x04, //+ "Wrong password for %s.";
48 CHAT_NOT_MEMBER_NOTICE = 0x05, //+ "Not on channel %s.";
49 CHAT_NOT_MODERATOR_NOTICE = 0x06, //+ "Not a moderator of %s.";
50 CHAT_PASSWORD_CHANGED_NOTICE = 0x07, //+ "[%s] Password changed by %s.";
51 CHAT_OWNER_CHANGED_NOTICE = 0x08, //+ "[%s] Owner changed to %s.";
52 CHAT_PLAYER_NOT_FOUND_NOTICE = 0x09, //+ "[%s] Player %s was not found.";
53 CHAT_NOT_OWNER_NOTICE = 0x0A, //+ "[%s] You are not the channel owner.";
54 CHAT_CHANNEL_OWNER_NOTICE = 0x0B, //+ "[%s] Channel owner is %s.";
56 CHAT_ANNOUNCEMENTS_ON_NOTICE = 0x0D, //+ "[%s] Channel announcements enabled by %s.";
57 CHAT_ANNOUNCEMENTS_OFF_NOTICE = 0x0E, //+ "[%s] Channel announcements disabled by %s.";
58 CHAT_MODERATION_ON_NOTICE = 0x0F, //+ "[%s] Channel moderation enabled by %s.";
59 CHAT_MODERATION_OFF_NOTICE = 0x10, //+ "[%s] Channel moderation disabled by %s.";
60 CHAT_MUTED_NOTICE = 0x11, //+ "[%s] You do not have permission to speak.";
61 CHAT_PLAYER_KICKED_NOTICE = 0x12, //? "[%s] Player %s kicked by %s.";
62 CHAT_BANNED_NOTICE = 0x13, //+ "[%s] You are banned from that channel.";
63 CHAT_PLAYER_BANNED_NOTICE = 0x14, //? "[%s] Player %s banned by %s.";
64 CHAT_PLAYER_UNBANNED_NOTICE = 0x15, //? "[%s] Player %s unbanned by %s.";
65 CHAT_PLAYER_NOT_BANNED_NOTICE = 0x16, //+ "[%s] Player %s is not banned.";
66 CHAT_PLAYER_ALREADY_MEMBER_NOTICE = 0x17, //+ "[%s] Player %s is already on the channel.";
67 CHAT_INVITE_NOTICE = 0x18, //+ "%2$s has invited you to join the channel '%1$s'.";
68 CHAT_INVITE_WRONG_FACTION_NOTICE = 0x19, //+ "Target is in the wrong alliance for %s.";
69 CHAT_WRONG_FACTION_NOTICE = 0x1A, //+ "Wrong alliance for %s.";
70 CHAT_INVALID_NAME_NOTICE = 0x1B, //+ "Invalid channel name";
71 CHAT_NOT_MODERATED_NOTICE = 0x1C, //+ "%s is not moderated";
72 CHAT_PLAYER_INVITED_NOTICE = 0x1D, //+ "[%s] You invited %s to join the channel";
73 CHAT_PLAYER_INVITE_BANNED_NOTICE = 0x1E, //+ "[%s] %s has been banned.";
74 CHAT_THROTTLED_NOTICE = 0x1F, //+ "[%s] The number of messages that can be sent to this channel is limited, please wait to send another message.";
75 CHAT_NOT_IN_AREA_NOTICE = 0x20, //+ "[%s] You are not in the correct area for this channel."; -- The user is trying to send a chat to a zone specific channel, and they're not physically in that zone.
76 CHAT_NOT_IN_LFG_NOTICE = 0x21, //+ "[%s] You must be queued in looking for group before joining this channel."; -- The user must be in the looking for group system to join LFG chat channels.
77 CHAT_VOICE_ON_NOTICE = 0x22, //+ "[%s] Channel voice enabled by %s.";
78 CHAT_VOICE_OFF_NOTICE = 0x23, //+ "[%s] Channel voice disabled by %s.";
79 CHAT_TRIAL_RESTRICTED = 0x24, //+ "[%s] Free Trial accounts cannot send messages to this channel. |cffffd000|Hstorecategory:gametime|h[Click To Upgrade]|h|r"
80 CHAT_NOT_ALLOWED_IN_CHANNEL = 0x25 //+ "That operation is not permitted in this channel."
81};
82
84{
87 // 0x02
94 // General 0x18 = 0x10 | 0x08
95 // Trade 0x3C = 0x20 | 0x10 | 0x08 | 0x04
96 // LocalDefense 0x18 = 0x10 | 0x08
97 // GuildRecruitment 0x38 = 0x20 | 0x10 | 0x08
98 // LookingForGroup 0x50 = 0x40 | 0x10
99};
100
102{
110 // 0x40
111 // 0x80
113
115{
117 {
118 uint8 GetFlags() const { return _flags; }
119
120 bool IsInvisible() const { return _invisible; }
121 void SetInvisible(bool on) { _invisible = on; }
122
123 inline bool HasFlag(uint8 flag) const { return (_flags & flag) != 0; }
124 inline void SetFlag(uint8 flag) { _flags |= flag; }
125 inline void RemoveFlag(uint8 flag) { _flags &= ~flag; }
126
127 bool IsOwner() const { return HasFlag(MEMBER_FLAG_OWNER); }
128 void SetOwner(bool state)
129 {
130 if (state)
131 SetFlag(MEMBER_FLAG_OWNER);
132 else
133 RemoveFlag(MEMBER_FLAG_OWNER);
134 }
135
136 bool IsModerator() const { return HasFlag(MEMBER_FLAG_MODERATOR); }
137 void SetModerator(bool state)
138 {
139 if (state)
140 SetFlag(MEMBER_FLAG_MODERATOR);
141 else
142 RemoveFlag(MEMBER_FLAG_MODERATOR);
143 }
144
145 bool IsMuted() const { return HasFlag(MEMBER_FLAG_MUTED); }
146 void SetMuted(bool state)
147 {
148 if (state)
149 SetFlag(MEMBER_FLAG_MUTED);
150 else
151 RemoveFlag(MEMBER_FLAG_MUTED);
152 }
153
154 private:
156 bool _invisible = false;
157 };
158
159 public:
160 Channel(ObjectGuid const& guid, uint32 channelId, uint32 team = 0, AreaTableEntry const* zoneEntry = nullptr); // built-in channel ctor
161 Channel(ObjectGuid const& guid, std::string const& name, uint32 team = 0, std::string const& banList = ""); // custom player channel ctor
162
163 static void GetChannelName(std::string& channelName, uint32 channelId, LocaleConstant locale, AreaTableEntry const* zoneEntry);
164 std::string GetName(LocaleConstant locale = DEFAULT_LOCALE) const;
165
166 uint32 GetChannelId() const { return _channelId; }
167 bool IsConstant() const { return _channelId != 0; }
168
169 ObjectGuid GetGUID() const { return _channelGuid; }
170
171 bool IsLFG() const { return (GetFlags() & CHANNEL_FLAG_LFG) != 0; }
172
173 bool IsAnnounce() const { return _announceEnabled; }
174 void SetAnnounce(bool announce) { _announceEnabled = announce; }
175
176 // will be saved to DB on next channel save interval
177 void SetDirty() { _isDirty = true; }
178 void UpdateChannelInDB();
179
180 void SetPassword(std::string const& password) { _channelPassword = password; }
181 bool CheckPassword(std::string const& password) const { return _channelPassword.empty() || (_channelPassword == password); }
182
183 uint32 GetNumPlayers() const { return uint32(_playersStore.size()); }
184
185 uint8 GetFlags() const { return _channelFlags; }
186 bool HasFlag(uint8 flag) const { return (_channelFlags & flag) != 0; }
187
188 AreaTableEntry const* GetZoneEntry() const { return _zoneEntry; }
189
190 void JoinChannel(Player* player, std::string const& pass = "");
191 void LeaveChannel(Player* player, bool send = true, bool suspend = false);
192
193 void KickOrBan(Player const* player, std::string const& badname, bool ban);
194 void Kick(Player const* player, std::string const& badname) { KickOrBan(player, badname, false); }
195 void Ban(Player const* player, std::string const& badname) { KickOrBan(player, badname, true); }
196
197 void UnBan(Player const* player, std::string const& badname);
198 void Password(Player const* player, std::string const& pass);
199 void SetMode(Player const* player, std::string const& p2n, bool mod, bool set);
200
201 void SetInvisible(Player const* player, bool on);
202
203 void SetOwner(ObjectGuid const& guid, bool exclaim = true);
204 void SetOwner(Player const* player, std::string const& name);
205 void SendWhoOwner(Player const* player);
206
207 void SetModerator(Player const* player, std::string const& newname) { SetMode(player, newname, true, true); }
208 void UnsetModerator(Player const* player, std::string const& newname) { SetMode(player, newname, true, false); }
209 void SetMute(Player const* player, std::string const& newname) { SetMode(player, newname, false, true); }
210 void UnsetMute(Player const* player, std::string const& newname) { SetMode(player, newname, false, false); }
211 void SilenceAll(Player const* player, std::string const& name);
212 void UnsilenceAll(Player const* player, std::string const& name);
213 void List(Player const* player);
214 void Announce(Player const* player);
215 void Say(ObjectGuid const& guid, std::string const& what, uint32 lang) const;
216 void AddonSay(ObjectGuid const& guid, std::string const& prefix, std::string const& what, bool isLogged) const;
217 void DeclineInvite(Player const* player);
218 void Invite(Player const* player, std::string const& newp);
219 void JoinNotify(Player const* player);
220 void LeaveNotify(Player const* player);
221 void SetOwnership(bool ownership) { _ownershipEnabled = ownership; }
222
223 private:
224 template <class Builder>
225 void SendToAll(Builder& builder, ObjectGuid const& guid = ObjectGuid::Empty, ObjectGuid const& accountGuid = ObjectGuid::Empty) const;
226
227 template <class Builder>
228 void SendToAllButOne(Builder& builder, ObjectGuid const& who) const;
229
230 template <class Builder>
231 void SendToOne(Builder& builder, ObjectGuid const& who) const;
232
233 template <class Builder>
234 void SendToAllWithAddon(Builder& builder, std::string const& addonPrefix, ObjectGuid const& guid = ObjectGuid::Empty, ObjectGuid const& accountGuid = ObjectGuid::Empty) const;
235
236 bool IsOn(ObjectGuid who) const { return _playersStore.find(who) != _playersStore.end(); }
237 bool IsBanned(ObjectGuid guid) const { return _bannedStore.find(guid) != _bannedStore.end(); }
238
239 uint8 GetPlayerFlags(ObjectGuid const& guid) const
240 {
241 PlayerContainer::const_iterator itr = _playersStore.find(guid);
242 return itr != _playersStore.end() ? itr->second.GetFlags() : 0;
243 }
244
245 void SetModerator(ObjectGuid const& guid, bool set);
246 void SetMute(ObjectGuid const& guid, bool set);
247
248 typedef std::map<ObjectGuid, PlayerInfo> PlayerContainer;
250
251 bool _isDirty; // whether the channel needs to be saved to DB
253
254 bool _announceEnabled; //< Whether we should broadcast a packet whenever a player joins/exits the channel
255 bool _ownershipEnabled; //< Whether the channel has to maintain an owner
256 bool _isOwnerInvisible; //< Whether the channel is owned by invisible GM, ownership should change to first player that joins channel
257
263 std::string _channelName;
264 std::string _channelPassword;
267
269};
270
271#endif
ChannelFlags
Definition: Channel.h:84
@ CHANNEL_FLAG_VOICE
Definition: Channel.h:93
@ CHANNEL_FLAG_NONE
Definition: Channel.h:85
@ CHANNEL_FLAG_TRADE
Definition: Channel.h:88
@ CHANNEL_FLAG_NOT_LFG
Definition: Channel.h:89
@ CHANNEL_FLAG_GENERAL
Definition: Channel.h:90
@ CHANNEL_FLAG_CUSTOM
Definition: Channel.h:86
@ CHANNEL_FLAG_LFG
Definition: Channel.h:92
@ CHANNEL_FLAG_CITY
Definition: Channel.h:91
ChannelMemberFlags
Definition: Channel.h:102
@ MEMBER_FLAG_MUTED
Definition: Channel.h:107
@ MEMBER_FLAG_CUSTOM
Definition: Channel.h:108
@ MEMBER_FLAG_MIC_MUTED
Definition: Channel.h:109
@ MEMBER_FLAG_VOICED
Definition: Channel.h:106
@ MEMBER_FLAG_MODERATOR
Definition: Channel.h:105
@ MEMBER_FLAG_NONE
Definition: Channel.h:103
@ MEMBER_FLAG_OWNER
Definition: Channel.h:104
ChatNotify
Definition: Channel.h:40
@ CHAT_YOU_JOINED_NOTICE
Definition: Channel.h:44
@ CHAT_MODERATION_OFF_NOTICE
Definition: Channel.h:59
@ CHAT_WRONG_FACTION_NOTICE
Definition: Channel.h:69
@ CHAT_NOT_MODERATOR_NOTICE
Definition: Channel.h:49
@ CHAT_PLAYER_UNBANNED_NOTICE
Definition: Channel.h:64
@ CHAT_PLAYER_NOT_FOUND_NOTICE
Definition: Channel.h:52
@ CHAT_MUTED_NOTICE
Definition: Channel.h:60
@ CHAT_PLAYER_NOT_BANNED_NOTICE
Definition: Channel.h:65
@ CHAT_PLAYER_INVITED_NOTICE
Definition: Channel.h:72
@ CHAT_PLAYER_KICKED_NOTICE
Definition: Channel.h:61
@ CHAT_VOICE_OFF_NOTICE
Definition: Channel.h:78
@ CHAT_NOT_ALLOWED_IN_CHANNEL
Definition: Channel.h:80
@ CHAT_MODE_CHANGE_NOTICE
Definition: Channel.h:55
@ CHAT_NOT_MEMBER_NOTICE
Definition: Channel.h:48
@ CHAT_ANNOUNCEMENTS_ON_NOTICE
Definition: Channel.h:56
@ CHAT_JOINED_NOTICE
Definition: Channel.h:41
@ CHAT_LEFT_NOTICE
Definition: Channel.h:42
@ CHAT_INVITE_WRONG_FACTION_NOTICE
Definition: Channel.h:68
@ CHAT_BANNED_NOTICE
Definition: Channel.h:62
@ CHAT_PLAYER_BANNED_NOTICE
Definition: Channel.h:63
@ CHAT_PLAYER_ALREADY_MEMBER_NOTICE
Definition: Channel.h:66
@ CHAT_OWNER_CHANGED_NOTICE
Definition: Channel.h:51
@ CHAT_ANNOUNCEMENTS_OFF_NOTICE
Definition: Channel.h:57
@ CHAT_VOICE_ON_NOTICE
Definition: Channel.h:77
@ CHAT_NOT_IN_LFG_NOTICE
Definition: Channel.h:76
@ CHAT_NOT_IN_AREA_NOTICE
Definition: Channel.h:75
@ CHAT_NOT_MODERATED_NOTICE
Definition: Channel.h:71
@ CHAT_YOU_LEFT_NOTICE
Definition: Channel.h:46
@ CHAT_CHANNEL_OWNER_NOTICE
Definition: Channel.h:54
@ CHAT_WRONG_PASSWORD_NOTICE
Definition: Channel.h:47
@ CHAT_THROTTLED_NOTICE
Definition: Channel.h:74
@ CHAT_TRIAL_RESTRICTED
Definition: Channel.h:79
@ CHAT_PLAYER_INVITE_BANNED_NOTICE
Definition: Channel.h:73
@ CHAT_INVITE_NOTICE
Definition: Channel.h:67
@ CHAT_NOT_OWNER_NOTICE
Definition: Channel.h:53
@ CHAT_PASSWORD_CHANGED_NOTICE
Definition: Channel.h:50
@ CHAT_INVALID_NAME_NOTICE
Definition: Channel.h:70
@ CHAT_MODERATION_ON_NOTICE
Definition: Channel.h:58
LocaleConstant
Definition: Common.h:48
#define DEFAULT_LOCALE
Definition: Common.h:66
#define TC_GAME_API
Definition: Define.h:123
uint8_t uint8
Definition: Define.h:144
uint32_t uint32
Definition: Define.h:142
std::unordered_set< ObjectGuid > GuidUnorderedSet
Definition: ObjectGuid.h:396
bool IsConstant() const
Definition: Channel.h:167
uint32 _channelId
Definition: Channel.h:259
BannedContainer _bannedStore
Definition: Channel.h:266
GuidUnorderedSet BannedContainer
Definition: Channel.h:249
bool _ownershipEnabled
Definition: Channel.h:255
bool _announceEnabled
Definition: Channel.h:254
bool HasFlag(uint8 flag) const
Definition: Channel.h:186
uint32 _channelTeam
Definition: Channel.h:260
time_t _nextActivityUpdateTime
Definition: Channel.h:252
uint8 _channelFlags
Definition: Channel.h:258
std::string _channelName
Definition: Channel.h:263
void SetMute(Player const *player, std::string const &newname)
Definition: Channel.h:209
void SetModerator(Player const *player, std::string const &newname)
Definition: Channel.h:207
void Ban(Player const *player, std::string const &badname)
Definition: Channel.h:195
bool IsLFG() const
Definition: Channel.h:171
bool _isOwnerInvisible
Definition: Channel.h:256
void UnsetMute(Player const *player, std::string const &newname)
Definition: Channel.h:210
uint32 GetChannelId() const
Definition: Channel.h:166
bool IsAnnounce() const
Definition: Channel.h:173
ObjectGuid _channelGuid
Definition: Channel.h:261
bool CheckPassword(std::string const &password) const
Definition: Channel.h:181
bool IsOn(ObjectGuid who) const
Definition: Channel.h:236
void SetDirty()
Definition: Channel.h:177
void UnsetModerator(Player const *player, std::string const &newname)
Definition: Channel.h:208
void SetPassword(std::string const &password)
Definition: Channel.h:180
uint8 GetPlayerFlags(ObjectGuid const &guid) const
Definition: Channel.h:239
bool _isDirty
Definition: Channel.h:251
void Kick(Player const *player, std::string const &badname)
Definition: Channel.h:194
void SetAnnounce(bool announce)
Definition: Channel.h:174
void SetOwnership(bool ownership)
Definition: Channel.h:221
uint32 GetNumPlayers() const
Definition: Channel.h:183
bool IsBanned(ObjectGuid guid) const
Definition: Channel.h:237
AreaTableEntry const * _zoneEntry
Definition: Channel.h:268
ObjectGuid _ownerGuid
Definition: Channel.h:262
ObjectGuid GetGUID() const
Definition: Channel.h:169
std::string _channelPassword
Definition: Channel.h:264
uint8 GetFlags() const
Definition: Channel.h:185
std::map< ObjectGuid, PlayerInfo > PlayerContainer
Definition: Channel.h:248
PlayerContainer _playersStore
Definition: Channel.h:265
AreaTableEntry const * GetZoneEntry() const
Definition: Channel.h:188
static ObjectGuid const Empty
Definition: ObjectGuid.h:274
TC_GAME_API bool GetName(uint32 accountId, std::string &name)
void SetModerator(bool state)
Definition: Channel.h:137
bool HasFlag(uint8 flag) const
Definition: Channel.h:123
bool IsOwner() const
Definition: Channel.h:127
uint8 GetFlags() const
Definition: Channel.h:118
bool IsMuted() const
Definition: Channel.h:145
bool IsInvisible() const
Definition: Channel.h:120
void SetInvisible(bool on)
Definition: Channel.h:121
void SetFlag(uint8 flag)
Definition: Channel.h:124
void SetOwner(bool state)
Definition: Channel.h:128
void SetMuted(bool state)
Definition: Channel.h:146
bool IsModerator() const
Definition: Channel.h:136
void RemoveFlag(uint8 flag)
Definition: Channel.h:125