TrinityCore
Loading...
Searching...
No Matches
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
30// EnumUtils: DESCRIBE THIS
32{
33 CHAT_JOINED_NOTICE = 0x00, //+ "%s joined channel.";
34 CHAT_LEFT_NOTICE = 0x01, //+ "%s left channel.";
35 //CHAT_SUSPENDED_NOTICE = 0x01, // "%s left channel.";
36 CHAT_YOU_JOINED_NOTICE = 0x02, //+ "Joined Channel: [%s]"; -- You joined
37 //CHAT_YOU_CHANGED_NOTICE = 0x02, // "Changed Channel: [%s]";
38 CHAT_YOU_LEFT_NOTICE = 0x03, //+ "Left Channel: [%s]"; -- You left
39 CHAT_WRONG_PASSWORD_NOTICE = 0x04, //+ "Wrong password for %s.";
40 CHAT_NOT_MEMBER_NOTICE = 0x05, //+ "Not on channel %s.";
41 CHAT_NOT_MODERATOR_NOTICE = 0x06, //+ "Not a moderator of %s.";
42 CHAT_PASSWORD_CHANGED_NOTICE = 0x07, //+ "[%s] Password changed by %s.";
43 CHAT_OWNER_CHANGED_NOTICE = 0x08, //+ "[%s] Owner changed to %s.";
44 CHAT_PLAYER_NOT_FOUND_NOTICE = 0x09, //+ "[%s] Player %s was not found.";
45 CHAT_NOT_OWNER_NOTICE = 0x0A, //+ "[%s] You are not the channel owner.";
46 CHAT_CHANNEL_OWNER_NOTICE = 0x0B, //+ "[%s] Channel owner is %s.";
48 CHAT_ANNOUNCEMENTS_ON_NOTICE = 0x0D, //+ "[%s] Channel announcements enabled by %s.";
49 CHAT_ANNOUNCEMENTS_OFF_NOTICE = 0x0E, //+ "[%s] Channel announcements disabled by %s.";
50 CHAT_MODERATION_ON_NOTICE = 0x0F, //+ "[%s] Channel moderation enabled by %s.";
51 CHAT_MODERATION_OFF_NOTICE = 0x10, //+ "[%s] Channel moderation disabled by %s.";
52 CHAT_MUTED_NOTICE = 0x11, //+ "[%s] You do not have permission to speak.";
53 CHAT_PLAYER_KICKED_NOTICE = 0x12, //? "[%s] Player %s kicked by %s.";
54 CHAT_BANNED_NOTICE = 0x13, //+ "[%s] You are banned from that channel.";
55 CHAT_PLAYER_BANNED_NOTICE = 0x14, //? "[%s] Player %s banned by %s.";
56 CHAT_PLAYER_UNBANNED_NOTICE = 0x15, //? "[%s] Player %s unbanned by %s.";
57 CHAT_PLAYER_NOT_BANNED_NOTICE = 0x16, //+ "[%s] Player %s is not banned.";
58 CHAT_PLAYER_ALREADY_MEMBER_NOTICE = 0x17, //+ "[%s] Player %s is already on the channel.";
59 CHAT_INVITE_NOTICE = 0x18, //+ "%2$s has invited you to join the channel '%1$s'.";
60 CHAT_INVITE_WRONG_FACTION_NOTICE = 0x19, //+ "Target is in the wrong alliance for %s.";
61 CHAT_WRONG_FACTION_NOTICE = 0x1A, //+ "Wrong alliance for %s.";
62 CHAT_INVALID_NAME_NOTICE = 0x1B, //+ "Invalid channel name";
63 CHAT_NOT_MODERATED_NOTICE = 0x1C, //+ "%s is not moderated";
64 CHAT_PLAYER_INVITED_NOTICE = 0x1D, //+ "[%s] You invited %s to join the channel";
65 CHAT_PLAYER_INVITE_BANNED_NOTICE = 0x1E, //+ "[%s] %s has been banned.";
66 CHAT_THROTTLED_NOTICE = 0x1F, //+ "[%s] The number of messages that can be sent to this channel is limited, please wait to send another message.";
67 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.
68 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.
69 CHAT_VOICE_ON_NOTICE = 0x22, //+ "[%s] Channel voice enabled by %s.";
70 CHAT_VOICE_OFF_NOTICE = 0x23, //+ "[%s] Channel voice disabled by %s.";
71 CHAT_VOICE_ON_NO_ANNOUNCE_NOTICE = 0x24, // same as CHAT_VOICE_ON_NOTICE but no chat mode change announcement
72 CHAT_TRIAL_RESTRICTED = 0x25, //+ "[%s] Free Trial accounts cannot send messages to this channel. |cffffd000|Hstorecategory:gametime|h[Click To Upgrade]|h|r"
73 CHAT_NOT_ALLOWED_IN_CHANNEL = 0x26 //+ "That operation is not permitted in this channel."
74};
75
77{
80 // 0x02
87 // General 0x18 = 0x10 | 0x08
88 // Trade 0x3C = 0x20 | 0x10 | 0x08 | 0x04
89 // LocalDefense 0x18 = 0x10 | 0x08
90 // GuildRecruitment 0x38 = 0x20 | 0x10 | 0x08
91 // LookingForGroup 0x50 = 0x40 | 0x10
92};
93
106
108{
110 {
111 uint8 GetFlags() const { return _flags; }
112
113 bool IsInvisible() const { return _invisible; }
114 void SetInvisible(bool on) { _invisible = on; }
115
116 inline bool HasFlag(uint8 flag) const { return (_flags & flag) != 0; }
117 inline void SetFlag(uint8 flag) { _flags |= flag; }
118 inline void RemoveFlag(uint8 flag) { _flags &= ~flag; }
119
120 bool IsOwner() const { return HasFlag(MEMBER_FLAG_OWNER); }
121 void SetOwner(bool state)
122 {
123 if (state)
124 SetFlag(MEMBER_FLAG_OWNER);
125 else
126 RemoveFlag(MEMBER_FLAG_OWNER);
127 }
128
129 bool IsModerator() const { return HasFlag(MEMBER_FLAG_MODERATOR); }
130 void SetModerator(bool state)
131 {
132 if (state)
133 SetFlag(MEMBER_FLAG_MODERATOR);
134 else
135 RemoveFlag(MEMBER_FLAG_MODERATOR);
136 }
137
138 bool IsMuted() const { return HasFlag(MEMBER_FLAG_MUTED); }
139 void SetMuted(bool state)
140 {
141 if (state)
142 SetFlag(MEMBER_FLAG_MUTED);
143 else
144 RemoveFlag(MEMBER_FLAG_MUTED);
145 }
146
147 private:
149 bool _invisible = false;
150 };
151
152 public:
153 Channel(ObjectGuid const& guid, uint32 channelId, uint32 team = 0, AreaTableEntry const* zoneEntry = nullptr); // built-in channel ctor
154 Channel(ObjectGuid const& guid, std::string const& name, uint32 team = 0, std::string const& banList = ""); // custom player channel ctor
155
156 Channel(Channel const&) = delete;
157 Channel(Channel&&) = delete;
158 Channel& operator=(Channel const&) = delete;
160
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) const;
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(ObjectGuid const& guid) const;
220 void LeaveNotify(ObjectGuid const& guid) const;
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:77
@ CHANNEL_FLAG_VOICE
Definition Channel.h:86
@ CHANNEL_FLAG_NONE
Definition Channel.h:78
@ CHANNEL_FLAG_TRADE
Definition Channel.h:81
@ CHANNEL_FLAG_NOT_LFG
Definition Channel.h:82
@ CHANNEL_FLAG_GENERAL
Definition Channel.h:83
@ CHANNEL_FLAG_CUSTOM
Definition Channel.h:79
@ CHANNEL_FLAG_LFG
Definition Channel.h:85
@ CHANNEL_FLAG_CITY
Definition Channel.h:84
ChannelMemberFlags
Definition Channel.h:95
@ MEMBER_FLAG_MUTED
Definition Channel.h:100
@ MEMBER_FLAG_CUSTOM
Definition Channel.h:101
@ MEMBER_FLAG_MIC_MUTED
Definition Channel.h:102
@ MEMBER_FLAG_VOICED
Definition Channel.h:99
@ MEMBER_FLAG_MODERATOR
Definition Channel.h:98
@ MEMBER_FLAG_NONE
Definition Channel.h:96
@ MEMBER_FLAG_OWNER
Definition Channel.h:97
ChatNotify
Definition Channel.h:32
@ CHAT_YOU_JOINED_NOTICE
Definition Channel.h:36
@ CHAT_MODERATION_OFF_NOTICE
Definition Channel.h:51
@ CHAT_WRONG_FACTION_NOTICE
Definition Channel.h:61
@ CHAT_NOT_MODERATOR_NOTICE
Definition Channel.h:41
@ CHAT_PLAYER_UNBANNED_NOTICE
Definition Channel.h:56
@ CHAT_PLAYER_NOT_FOUND_NOTICE
Definition Channel.h:44
@ CHAT_MUTED_NOTICE
Definition Channel.h:52
@ CHAT_PLAYER_NOT_BANNED_NOTICE
Definition Channel.h:57
@ CHAT_PLAYER_INVITED_NOTICE
Definition Channel.h:64
@ CHAT_PLAYER_KICKED_NOTICE
Definition Channel.h:53
@ CHAT_VOICE_OFF_NOTICE
Definition Channel.h:70
@ CHAT_NOT_ALLOWED_IN_CHANNEL
Definition Channel.h:73
@ CHAT_VOICE_ON_NO_ANNOUNCE_NOTICE
Definition Channel.h:71
@ CHAT_MODE_CHANGE_NOTICE
Definition Channel.h:47
@ CHAT_NOT_MEMBER_NOTICE
Definition Channel.h:40
@ CHAT_ANNOUNCEMENTS_ON_NOTICE
Definition Channel.h:48
@ CHAT_JOINED_NOTICE
Definition Channel.h:33
@ CHAT_LEFT_NOTICE
Definition Channel.h:34
@ CHAT_INVITE_WRONG_FACTION_NOTICE
Definition Channel.h:60
@ CHAT_BANNED_NOTICE
Definition Channel.h:54
@ CHAT_PLAYER_BANNED_NOTICE
Definition Channel.h:55
@ CHAT_PLAYER_ALREADY_MEMBER_NOTICE
Definition Channel.h:58
@ CHAT_OWNER_CHANGED_NOTICE
Definition Channel.h:43
@ CHAT_ANNOUNCEMENTS_OFF_NOTICE
Definition Channel.h:49
@ CHAT_VOICE_ON_NOTICE
Definition Channel.h:69
@ CHAT_NOT_IN_LFG_NOTICE
Definition Channel.h:68
@ CHAT_NOT_IN_AREA_NOTICE
Definition Channel.h:67
@ CHAT_NOT_MODERATED_NOTICE
Definition Channel.h:63
@ CHAT_YOU_LEFT_NOTICE
Definition Channel.h:38
@ CHAT_CHANNEL_OWNER_NOTICE
Definition Channel.h:46
@ CHAT_WRONG_PASSWORD_NOTICE
Definition Channel.h:39
@ CHAT_THROTTLED_NOTICE
Definition Channel.h:66
@ CHAT_TRIAL_RESTRICTED
Definition Channel.h:72
@ CHAT_PLAYER_INVITE_BANNED_NOTICE
Definition Channel.h:65
@ CHAT_INVITE_NOTICE
Definition Channel.h:59
@ CHAT_NOT_OWNER_NOTICE
Definition Channel.h:45
@ CHAT_PASSWORD_CHANGED_NOTICE
Definition Channel.h:42
@ CHAT_INVALID_NAME_NOTICE
Definition Channel.h:62
@ CHAT_MODERATION_ON_NOTICE
Definition Channel.h:50
LocaleConstant
Definition Common.h:51
#define DEFAULT_LOCALE
Definition Common.h:69
#define TC_GAME_API
Definition Define.h:129
uint8_t uint8
Definition Define.h:156
uint32_t uint32
Definition Define.h:154
std::unordered_set< ObjectGuid > GuidUnorderedSet
Definition ObjectGuid.h:435
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
Channel(Channel const &)=delete
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
Channel(Channel &&)=delete
Channel & operator=(Channel &&)=delete
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
Channel & operator=(Channel const &)=delete
AreaTableEntry const * GetZoneEntry() const
Definition Channel.h:188
static ObjectGuid const Empty
Definition ObjectGuid.h:314
void SetModerator(bool state)
Definition Channel.h:130
bool HasFlag(uint8 flag) const
Definition Channel.h:116
bool IsOwner() const
Definition Channel.h:120
uint8 GetFlags() const
Definition Channel.h:111
bool IsMuted() const
Definition Channel.h:138
bool IsInvisible() const
Definition Channel.h:113
void SetInvisible(bool on)
Definition Channel.h:114
void SetFlag(uint8 flag)
Definition Channel.h:117
void SetOwner(bool state)
Definition Channel.h:121
void SetMuted(bool state)
Definition Channel.h:139
bool IsModerator() const
Definition Channel.h:129
void RemoveFlag(uint8 flag)
Definition Channel.h:118