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
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_VOICE_ON_NO_ANNOUNCE_NOTICE = 0x24, // same as CHAT_VOICE_ON_NOTICE but no chat mode change announcement
80 CHAT_TRIAL_RESTRICTED = 0x25, //+ "[%s] Free Trial accounts cannot send messages to this channel. |cffffd000|Hstorecategory:gametime|h[Click To Upgrade]|h|r"
81 CHAT_NOT_ALLOWED_IN_CHANNEL = 0x26 //+ "That operation is not permitted in this channel."
82};
83
85{
88 // 0x02
95 // General 0x18 = 0x10 | 0x08
96 // Trade 0x3C = 0x20 | 0x10 | 0x08 | 0x04
97 // LocalDefense 0x18 = 0x10 | 0x08
98 // GuildRecruitment 0x38 = 0x20 | 0x10 | 0x08
99 // LookingForGroup 0x50 = 0x40 | 0x10
101
114
116{
118 {
119 uint8 GetFlags() const { return _flags; }
120
121 bool IsInvisible() const { return _invisible; }
122 void SetInvisible(bool on) { _invisible = on; }
123
124 inline bool HasFlag(uint8 flag) const { return (_flags & flag) != 0; }
125 inline void SetFlag(uint8 flag) { _flags |= flag; }
126 inline void RemoveFlag(uint8 flag) { _flags &= ~flag; }
127
128 bool IsOwner() const { return HasFlag(MEMBER_FLAG_OWNER); }
129 void SetOwner(bool state)
130 {
131 if (state)
132 SetFlag(MEMBER_FLAG_OWNER);
133 else
134 RemoveFlag(MEMBER_FLAG_OWNER);
135 }
136
137 bool IsModerator() const { return HasFlag(MEMBER_FLAG_MODERATOR); }
138 void SetModerator(bool state)
139 {
140 if (state)
141 SetFlag(MEMBER_FLAG_MODERATOR);
142 else
143 RemoveFlag(MEMBER_FLAG_MODERATOR);
144 }
145
146 bool IsMuted() const { return HasFlag(MEMBER_FLAG_MUTED); }
147 void SetMuted(bool state)
148 {
149 if (state)
150 SetFlag(MEMBER_FLAG_MUTED);
151 else
152 RemoveFlag(MEMBER_FLAG_MUTED);
153 }
154
155 private:
157 bool _invisible = false;
158 };
159
160 public:
161 Channel(ObjectGuid const& guid, uint32 channelId, uint32 team = 0, AreaTableEntry const* zoneEntry = nullptr); // built-in channel ctor
162 Channel(ObjectGuid const& guid, std::string const& name, uint32 team = 0, std::string const& banList = ""); // custom player channel ctor
163
164 Channel(Channel const&) = delete;
165 Channel(Channel&&) = delete;
166 Channel& operator=(Channel const&) = delete;
168
170
171 static void GetChannelName(std::string& channelName, uint32 channelId, LocaleConstant locale, AreaTableEntry const* zoneEntry);
172 std::string GetName(LocaleConstant locale = DEFAULT_LOCALE) const;
173
174 uint32 GetChannelId() const { return _channelId; }
175 bool IsConstant() const { return _channelId != 0; }
176
177 ObjectGuid GetGUID() const { return _channelGuid; }
178
179 bool IsLFG() const { return (GetFlags() & CHANNEL_FLAG_LFG) != 0; }
180
181 bool IsAnnounce() const { return _announceEnabled; }
182 void SetAnnounce(bool announce) { _announceEnabled = announce; }
183
184 // will be saved to DB on next channel save interval
185 void SetDirty() { _isDirty = true; }
186 void UpdateChannelInDB();
187
188 void SetPassword(std::string const& password) { _channelPassword = password; }
189 bool CheckPassword(std::string const& password) const { return _channelPassword.empty() || (_channelPassword == password); }
190
191 uint32 GetNumPlayers() const { return uint32(_playersStore.size()); }
192
193 uint8 GetFlags() const { return _channelFlags; }
194 bool HasFlag(uint8 flag) const { return (_channelFlags & flag) != 0; }
195
196 AreaTableEntry const* GetZoneEntry() const { return _zoneEntry; }
197
198 void JoinChannel(Player* player, std::string const& pass = "");
199 void LeaveChannel(Player* player, bool send = true, bool suspend = false);
200
201 void KickOrBan(Player const* player, std::string const& badname, bool ban);
202 void Kick(Player const* player, std::string const& badname) { KickOrBan(player, badname, false); }
203 void Ban(Player const* player, std::string const& badname) { KickOrBan(player, badname, true); }
204
205 void UnBan(Player const* player, std::string const& badname);
206 void Password(Player const* player, std::string const& pass);
207 void SetMode(Player const* player, std::string const& p2n, bool mod, bool set);
208
209 void SetInvisible(Player const* player, bool on);
210
211 void SetOwner(ObjectGuid const& guid, bool exclaim = true);
212 void SetOwner(Player const* player, std::string const& name);
213 void SendWhoOwner(Player const* player);
214
215 void SetModerator(Player const* player, std::string const& newname) { SetMode(player, newname, true, true); }
216 void UnsetModerator(Player const* player, std::string const& newname) { SetMode(player, newname, true, false); }
217 void SetMute(Player const* player, std::string const& newname) { SetMode(player, newname, false, true); }
218 void UnsetMute(Player const* player, std::string const& newname) { SetMode(player, newname, false, false); }
219 void SilenceAll(Player const* player, std::string const& name);
220 void UnsilenceAll(Player const* player, std::string const& name);
221 void List(Player const* player);
222 void Announce(Player const* player);
223 void Say(ObjectGuid const& guid, std::string const& what, uint32 lang) const;
224 void AddonSay(ObjectGuid const& guid, std::string const& prefix, std::string const& what, bool isLogged) const;
225 void DeclineInvite(Player const* player);
226 void Invite(Player const* player, std::string const& newp);
227 void JoinNotify(Player const* player);
228 void LeaveNotify(Player const* player);
229 void SetOwnership(bool ownership) { _ownershipEnabled = ownership; }
230
231 private:
232 template <class Builder>
233 void SendToAll(Builder& builder, ObjectGuid const& guid = ObjectGuid::Empty, ObjectGuid const& accountGuid = ObjectGuid::Empty) const;
234
235 template <class Builder>
236 void SendToAllButOne(Builder& builder, ObjectGuid const& who) const;
237
238 template <class Builder>
239 void SendToOne(Builder& builder, ObjectGuid const& who) const;
240
241 template <class Builder>
242 void SendToAllWithAddon(Builder& builder, std::string const& addonPrefix, ObjectGuid const& guid = ObjectGuid::Empty, ObjectGuid const& accountGuid = ObjectGuid::Empty) const;
243
244 bool IsOn(ObjectGuid who) const { return _playersStore.find(who) != _playersStore.end(); }
245 bool IsBanned(ObjectGuid guid) const { return _bannedStore.find(guid) != _bannedStore.end(); }
246
247 uint8 GetPlayerFlags(ObjectGuid const& guid) const
248 {
249 PlayerContainer::const_iterator itr = _playersStore.find(guid);
250 return itr != _playersStore.end() ? itr->second.GetFlags() : 0;
251 }
252
253 void SetModerator(ObjectGuid const& guid, bool set);
254 void SetMute(ObjectGuid const& guid, bool set);
255
256 typedef std::map<ObjectGuid, PlayerInfo> PlayerContainer;
258
259 bool _isDirty; // whether the channel needs to be saved to DB
261
262 bool _announceEnabled; //< Whether we should broadcast a packet whenever a player joins/exits the channel
263 bool _ownershipEnabled; //< Whether the channel has to maintain an owner
264 bool _isOwnerInvisible; //< Whether the channel is owned by invisible GM, ownership should change to first player that joins channel
265
271 std::string _channelName;
272 std::string _channelPassword;
275
277};
278
279#endif
ChannelFlags
Definition Channel.h:85
@ CHANNEL_FLAG_VOICE
Definition Channel.h:94
@ CHANNEL_FLAG_NONE
Definition Channel.h:86
@ CHANNEL_FLAG_TRADE
Definition Channel.h:89
@ CHANNEL_FLAG_NOT_LFG
Definition Channel.h:90
@ CHANNEL_FLAG_GENERAL
Definition Channel.h:91
@ CHANNEL_FLAG_CUSTOM
Definition Channel.h:87
@ CHANNEL_FLAG_LFG
Definition Channel.h:93
@ CHANNEL_FLAG_CITY
Definition Channel.h:92
ChannelMemberFlags
Definition Channel.h:103
@ MEMBER_FLAG_MUTED
Definition Channel.h:108
@ MEMBER_FLAG_CUSTOM
Definition Channel.h:109
@ MEMBER_FLAG_MIC_MUTED
Definition Channel.h:110
@ MEMBER_FLAG_VOICED
Definition Channel.h:107
@ MEMBER_FLAG_MODERATOR
Definition Channel.h:106
@ MEMBER_FLAG_NONE
Definition Channel.h:104
@ MEMBER_FLAG_OWNER
Definition Channel.h:105
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:81
@ CHAT_VOICE_ON_NO_ANNOUNCE_NOTICE
Definition Channel.h:79
@ 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:80
@ 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: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:175
uint32 _channelId
Definition Channel.h:267
BannedContainer _bannedStore
Definition Channel.h:274
GuidUnorderedSet BannedContainer
Definition Channel.h:257
Channel(Channel const &)=delete
bool _ownershipEnabled
Definition Channel.h:263
bool _announceEnabled
Definition Channel.h:262
bool HasFlag(uint8 flag) const
Definition Channel.h:194
uint32 _channelTeam
Definition Channel.h:268
time_t _nextActivityUpdateTime
Definition Channel.h:260
uint8 _channelFlags
Definition Channel.h:266
std::string _channelName
Definition Channel.h:271
void SetMute(Player const *player, std::string const &newname)
Definition Channel.h:217
void SetModerator(Player const *player, std::string const &newname)
Definition Channel.h:215
void Ban(Player const *player, std::string const &badname)
Definition Channel.h:203
bool IsLFG() const
Definition Channel.h:179
bool _isOwnerInvisible
Definition Channel.h:264
void UnsetMute(Player const *player, std::string const &newname)
Definition Channel.h:218
uint32 GetChannelId() const
Definition Channel.h:174
bool IsAnnounce() const
Definition Channel.h:181
ObjectGuid _channelGuid
Definition Channel.h:269
bool CheckPassword(std::string const &password) const
Definition Channel.h:189
bool IsOn(ObjectGuid who) const
Definition Channel.h:244
void SetDirty()
Definition Channel.h:185
void UnsetModerator(Player const *player, std::string const &newname)
Definition Channel.h:216
void SetPassword(std::string const &password)
Definition Channel.h:188
uint8 GetPlayerFlags(ObjectGuid const &guid) const
Definition Channel.h:247
bool _isDirty
Definition Channel.h:259
void Kick(Player const *player, std::string const &badname)
Definition Channel.h:202
Channel(Channel &&)=delete
Channel & operator=(Channel &&)=delete
void SetAnnounce(bool announce)
Definition Channel.h:182
void SetOwnership(bool ownership)
Definition Channel.h:229
uint32 GetNumPlayers() const
Definition Channel.h:191
bool IsBanned(ObjectGuid guid) const
Definition Channel.h:245
AreaTableEntry const * _zoneEntry
Definition Channel.h:276
ObjectGuid _ownerGuid
Definition Channel.h:270
ObjectGuid GetGUID() const
Definition Channel.h:177
std::string _channelPassword
Definition Channel.h:272
uint8 GetFlags() const
Definition Channel.h:193
std::map< ObjectGuid, PlayerInfo > PlayerContainer
Definition Channel.h:256
PlayerContainer _playersStore
Definition Channel.h:273
Channel & operator=(Channel const &)=delete
AreaTableEntry const * GetZoneEntry() const
Definition Channel.h:196
static ObjectGuid const Empty
Definition ObjectGuid.h:314
void SetModerator(bool state)
Definition Channel.h:138
bool HasFlag(uint8 flag) const
Definition Channel.h:124
bool IsOwner() const
Definition Channel.h:128
uint8 GetFlags() const
Definition Channel.h:119
bool IsMuted() const
Definition Channel.h:146
bool IsInvisible() const
Definition Channel.h:121
void SetInvisible(bool on)
Definition Channel.h:122
void SetFlag(uint8 flag)
Definition Channel.h:125
void SetOwner(bool state)
Definition Channel.h:129
void SetMuted(bool state)
Definition Channel.h:147
bool IsModerator() const
Definition Channel.h:137
void RemoveFlag(uint8 flag)
Definition Channel.h:126