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};
72
74{
77 // 0x02
84 // General 0x18 = 0x10 | 0x08
85 // Trade 0x3C = 0x20 | 0x10 | 0x08 | 0x04
86 // LocalDefense 0x18 = 0x10 | 0x08
87 // GuildRecruitment 0x38 = 0x20 | 0x10 | 0x08
88 // LookingForGroup 0x50 = 0x40 | 0x10
89};
90
92{
94 CHANNEL_DBC_FLAG_INITIAL = 0x00001, // General, Trade, LocalDefense, LFG
95 CHANNEL_DBC_FLAG_ZONE_DEP = 0x00002, // General, Trade, LocalDefense, GuildRecruitment
96 CHANNEL_DBC_FLAG_GLOBAL = 0x00004, // WorldDefense
97 CHANNEL_DBC_FLAG_TRADE = 0x00008, // Trade, LFG
98 CHANNEL_DBC_FLAG_CITY_ONLY = 0x00010, // Trade, GuildRecruitment, LFG
99 CHANNEL_DBC_FLAG_CITY_ONLY2 = 0x00020, // Trade, GuildRecruitment, LFG
100 CHANNEL_DBC_FLAG_DEFENSE = 0x10000, // LocalDefense, WorldDefense
101 CHANNEL_DBC_FLAG_GUILD_REQ = 0x20000, // GuildRecruitment
102 CHANNEL_DBC_FLAG_LFG = 0x40000, // LFG
103 CHANNEL_DBC_FLAG_UNK1 = 0x80000 // General
105
118
120{
122 {
123 uint8 GetFlags() const { return _flags; }
124
125 bool IsInvisible() const { return _invisible; }
126 void SetInvisible(bool on) { _invisible = on; }
127
128 inline bool HasFlag(uint8 flag) const { return (_flags & flag) != 0; }
129 inline void SetFlag(uint8 flag) { _flags |= flag; }
130 inline void RemoveFlag(uint8 flag) { _flags &= ~flag; }
131
132 bool IsOwner() const { return HasFlag(MEMBER_FLAG_OWNER); }
133 void SetOwner(bool state)
134 {
135 if (state)
136 SetFlag(MEMBER_FLAG_OWNER);
137 else
138 RemoveFlag(MEMBER_FLAG_OWNER);
139 }
140
141 bool IsModerator() const { return HasFlag(MEMBER_FLAG_MODERATOR); }
142 void SetModerator(bool state)
143 {
144 if (state)
145 SetFlag(MEMBER_FLAG_MODERATOR);
146 else
147 RemoveFlag(MEMBER_FLAG_MODERATOR);
148 }
149
150 bool IsMuted() const { return HasFlag(MEMBER_FLAG_MUTED); }
151 void SetMuted(bool state)
152 {
153 if (state)
154 SetFlag(MEMBER_FLAG_MUTED);
155 else
156 RemoveFlag(MEMBER_FLAG_MUTED);
157 }
158
159 private:
161 bool _invisible = false;
162 };
163
164 public:
165 Channel(uint32 channelId, uint32 team = 0, AreaTableEntry const* zoneEntry = nullptr); // built-in channel ctor
166 Channel(std::string const& name, uint32 team, std::string const& banList = ""); // custom player channel ctor
167
168 Channel(Channel const&) = delete;
169 Channel(Channel&&) = delete;
170 Channel& operator=(Channel const&) = delete;
172
174
175 static void GetChannelName(std::string& channelName, uint32 channelId, LocaleConstant locale, AreaTableEntry const* zoneEntry);
176 std::string GetName(LocaleConstant locale = DEFAULT_LOCALE) const;
177
178 uint32 GetChannelId() const { return _channelId; }
179 bool IsConstant() const { return _channelId != 0; }
180 bool IsLFG() const { return (GetFlags() & CHANNEL_FLAG_LFG) != 0; }
181
182 bool IsAnnounce() const { return _announceEnabled; }
183 void SetAnnounce(bool announce) { _announceEnabled = announce; }
184
185 // will be saved to DB on next channel save interval
186 void SetDirty() { _isDirty = true; }
187 void UpdateChannelInDB();
188
189 void SetPassword(std::string const& password) { _channelPassword = password; }
190 bool CheckPassword(std::string const& password) const { return _channelPassword.empty() || (_channelPassword == password); }
191
192 uint32 GetNumPlayers() const { return uint32(_playersStore.size()); }
193
194 uint8 GetFlags() const { return _channelFlags; }
195 bool HasFlag(uint8 flag) const { return (_channelFlags & flag) != 0; }
196
197 AreaTableEntry const* GetZoneEntry() const { return _zoneEntry; }
198
199 void JoinChannel(Player* player, std::string const& pass = "");
200 void LeaveChannel(Player* player, bool send = true, bool suspend = false);
201
202 void KickOrBan(Player const* player, std::string const& badname, bool ban);
203 void Kick(Player const* player, std::string const& badname) { KickOrBan(player, badname, false); }
204 void Ban(Player const* player, std::string const& badname) { KickOrBan(player, badname, true); }
205
206 void UnBan(Player const* player, std::string const& badname);
207 void Password(Player const* player, std::string const& pass);
208 void SetMode(Player const* player, std::string const& p2n, bool mod, bool set);
209
210 void SetInvisible(Player const* player, bool on);
211
212 void SetOwner(ObjectGuid const& guid, bool exclaim = true);
213 void SetOwner(Player const* player, std::string const& name);
214 void SendWhoOwner(Player const* player);
215
216 void SetModerator(Player const* player, std::string const& newname) { SetMode(player, newname, true, true); }
217 void UnsetModerator(Player const* player, std::string const& newname) { SetMode(player, newname, true, false); }
218 void SetMute(Player const* player, std::string const& newname) { SetMode(player, newname, false, true); }
219 void UnsetMute(Player const* player, std::string const& newname) { SetMode(player, newname, false, false); }
220 void SilenceAll(Player const* player, std::string const& name);
221 void SilenceVoice(Player const* player, std::string const& name);
222 void UnsilenceAll(Player const* player, std::string const& name);
223 void UnsilenceVoice(Player const* player, std::string const& name);
224 void List(Player const* player) const;
225 void Announce(Player const* player);
226 void Say(ObjectGuid const& guid, std::string const& what, uint32 lang) const;
227 void DeclineInvite(Player const* player);
228 void Invite(Player const* player, std::string const& newp);
229 void JoinNotify(ObjectGuid const& guid) const;
230 void LeaveNotify(ObjectGuid const& guid) const;
231 void SetOwnership(bool ownership) { _ownershipEnabled = ownership; }
232 void SendMemberCount(Player const* player) const;
233 void VoiceOn(Player const* player);
234 void VoiceOff(Player const* player);
235
236 private:
237 template <class Builder>
238 void SendToAll(Builder& builder, ObjectGuid const& guid = ObjectGuid::Empty) const;
239
240 template <class Builder>
241 void SendToAllButOne(Builder& builder, ObjectGuid const& who) const;
242
243 template <class Builder>
244 void SendToOne(Builder& builder, ObjectGuid const& who) const;
245
246 bool IsOn(ObjectGuid who) const { return _playersStore.find(who) != _playersStore.end(); }
247 bool IsBanned(ObjectGuid guid) const { return _bannedStore.find(guid) != _bannedStore.end(); }
248
249 uint8 GetPlayerFlags(ObjectGuid const& guid) const
250 {
251 PlayerContainer::const_iterator itr = _playersStore.find(guid);
252 return itr != _playersStore.end() ? itr->second.GetFlags() : 0;
253 }
254
255 void SetModerator(ObjectGuid const& guid, bool set);
256 void SetMute(ObjectGuid const& guid, bool set);
257
258 typedef std::map<ObjectGuid, PlayerInfo> PlayerContainer;
260
261 bool _isDirty; // whether the channel needs to be saved to DB
263
264 bool _announceEnabled; //< Whether we should broadcast a packet whenever a player joins/exits the channel
265 bool _ownershipEnabled; //< Whether the channel has to maintain an owner
266 bool _isOwnerInvisible; //< Whether the channel is owned by invisible GM, ownership should change to first player that joins channel
267
272 std::string _channelName;
273 std::string _channelPassword;
276
278};
279
280#endif
ChannelFlags
Definition Channel.h:74
@ CHANNEL_FLAG_VOICE
Definition Channel.h:83
@ CHANNEL_FLAG_NONE
Definition Channel.h:75
@ CHANNEL_FLAG_TRADE
Definition Channel.h:78
@ CHANNEL_FLAG_NOT_LFG
Definition Channel.h:79
@ CHANNEL_FLAG_GENERAL
Definition Channel.h:80
@ CHANNEL_FLAG_CUSTOM
Definition Channel.h:76
@ CHANNEL_FLAG_LFG
Definition Channel.h:82
@ CHANNEL_FLAG_CITY
Definition Channel.h:81
ChannelMemberFlags
Definition Channel.h:107
@ MEMBER_FLAG_MUTED
Definition Channel.h:112
@ MEMBER_FLAG_CUSTOM
Definition Channel.h:113
@ MEMBER_FLAG_MIC_MUTED
Definition Channel.h:114
@ MEMBER_FLAG_VOICED
Definition Channel.h:111
@ MEMBER_FLAG_MODERATOR
Definition Channel.h:110
@ MEMBER_FLAG_NONE
Definition Channel.h:108
@ MEMBER_FLAG_OWNER
Definition Channel.h:109
ChannelDBCFlags
Definition Channel.h:92
@ CHANNEL_DBC_FLAG_NONE
Definition Channel.h:93
@ CHANNEL_DBC_FLAG_TRADE
Definition Channel.h:97
@ CHANNEL_DBC_FLAG_CITY_ONLY
Definition Channel.h:98
@ CHANNEL_DBC_FLAG_GUILD_REQ
Definition Channel.h:101
@ CHANNEL_DBC_FLAG_ZONE_DEP
Definition Channel.h:95
@ CHANNEL_DBC_FLAG_GLOBAL
Definition Channel.h:96
@ CHANNEL_DBC_FLAG_UNK1
Definition Channel.h:103
@ CHANNEL_DBC_FLAG_CITY_ONLY2
Definition Channel.h:99
@ CHANNEL_DBC_FLAG_LFG
Definition Channel.h:102
@ CHANNEL_DBC_FLAG_DEFENSE
Definition Channel.h:100
@ CHANNEL_DBC_FLAG_INITIAL
Definition Channel.h:94
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_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_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:48
#define DEFAULT_LOCALE
Definition Common.h:62
#define TC_GAME_API
Definition Define.h:114
uint8_t uint8
Definition Define.h:135
uint32_t uint32
Definition Define.h:133
std::unordered_set< ObjectGuid > GuidUnorderedSet
Definition ObjectGuid.h:263
bool IsConstant() const
Definition Channel.h:179
uint32 _channelId
Definition Channel.h:269
BannedContainer _bannedStore
Definition Channel.h:275
GuidUnorderedSet BannedContainer
Definition Channel.h:259
Channel(Channel const &)=delete
bool _ownershipEnabled
Definition Channel.h:265
bool _announceEnabled
Definition Channel.h:264
bool HasFlag(uint8 flag) const
Definition Channel.h:195
uint32 _channelTeam
Definition Channel.h:270
time_t _nextActivityUpdateTime
Definition Channel.h:262
uint8 _channelFlags
Definition Channel.h:268
std::string _channelName
Definition Channel.h:272
void SetMute(Player const *player, std::string const &newname)
Definition Channel.h:218
void SetModerator(Player const *player, std::string const &newname)
Definition Channel.h:216
void Ban(Player const *player, std::string const &badname)
Definition Channel.h:204
bool IsLFG() const
Definition Channel.h:180
bool _isOwnerInvisible
Definition Channel.h:266
void UnsetMute(Player const *player, std::string const &newname)
Definition Channel.h:219
uint32 GetChannelId() const
Definition Channel.h:178
bool IsAnnounce() const
Definition Channel.h:182
bool CheckPassword(std::string const &password) const
Definition Channel.h:190
bool IsOn(ObjectGuid who) const
Definition Channel.h:246
void SetDirty()
Definition Channel.h:186
void UnsetModerator(Player const *player, std::string const &newname)
Definition Channel.h:217
void SetPassword(std::string const &password)
Definition Channel.h:189
uint8 GetPlayerFlags(ObjectGuid const &guid) const
Definition Channel.h:249
bool _isDirty
Definition Channel.h:261
void Kick(Player const *player, std::string const &badname)
Definition Channel.h:203
Channel(Channel &&)=delete
Channel & operator=(Channel &&)=delete
void SetAnnounce(bool announce)
Definition Channel.h:183
void SetOwnership(bool ownership)
Definition Channel.h:231
uint32 GetNumPlayers() const
Definition Channel.h:192
bool IsBanned(ObjectGuid guid) const
Definition Channel.h:247
AreaTableEntry const * _zoneEntry
Definition Channel.h:277
ObjectGuid _ownerGuid
Definition Channel.h:271
std::string _channelPassword
Definition Channel.h:273
uint8 GetFlags() const
Definition Channel.h:194
std::map< ObjectGuid, PlayerInfo > PlayerContainer
Definition Channel.h:258
PlayerContainer _playersStore
Definition Channel.h:274
Channel & operator=(Channel const &)=delete
AreaTableEntry const * GetZoneEntry() const
Definition Channel.h:197
static ObjectGuid const Empty
Definition ObjectGuid.h:140
void SetModerator(bool state)
Definition Channel.h:142
bool HasFlag(uint8 flag) const
Definition Channel.h:128
bool IsOwner() const
Definition Channel.h:132
uint8 GetFlags() const
Definition Channel.h:123
bool IsMuted() const
Definition Channel.h:150
bool IsInvisible() const
Definition Channel.h:125
void SetInvisible(bool on)
Definition Channel.h:126
void SetFlag(uint8 flag)
Definition Channel.h:129
void SetOwner(bool state)
Definition Channel.h:133
void SetMuted(bool state)
Definition Channel.h:151
bool IsModerator() const
Definition Channel.h:141
void RemoveFlag(uint8 flag)
Definition Channel.h:130