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 {
125
126 bool IsInvisible() const { return invisible; }
127 void SetInvisible(bool on) { invisible = on; }
128
129 bool HasFlag(uint8 flag) const { return (flags & flag) != 0; }
130 void SetFlag(uint8 flag) { flags |= flag; }
131
132 bool IsOwner() const { return (flags & MEMBER_FLAG_OWNER) != 0; }
133 void SetOwner(bool state)
134 {
135 if (state) flags |= MEMBER_FLAG_OWNER;
136 else flags &= ~MEMBER_FLAG_OWNER;
137 }
138
139 bool IsModerator() const { return (flags & MEMBER_FLAG_MODERATOR) != 0; }
140 void SetModerator(bool state)
141 {
142 if (state) flags |= MEMBER_FLAG_MODERATOR;
143 else flags &= ~MEMBER_FLAG_MODERATOR;
144 }
145
146 bool IsMuted() const { return (flags & MEMBER_FLAG_MUTED) != 0; }
147 void SetMuted(bool state)
148 {
149 if (state) flags |= MEMBER_FLAG_MUTED;
150 else flags &= ~MEMBER_FLAG_MUTED;
151 }
152 };
153
154 public:
155 Channel(uint32 channelId, uint32 team = 0, AreaTableEntry const* zoneEntry = nullptr); // built-in channel ctor
156 Channel(std::string const& name, uint32 team, std::string const& banList = ""); // custom player channel ctor
157
158 Channel(Channel const&) = delete;
159 Channel(Channel&&) = delete;
160 Channel& operator=(Channel const&) = delete;
162
164
165 static void GetChannelName(std::string& channelName, uint32 channelId, LocaleConstant locale, AreaTableEntry const* zoneEntry);
166 std::string GetName(LocaleConstant locale = DEFAULT_LOCALE) const;
167
168 uint32 GetChannelId() const { return _channelId; }
169 bool IsConstant() const { return _channelId != 0; }
170 bool IsLFG() const { return (GetFlags() & CHANNEL_FLAG_LFG) != 0; }
171
172 bool IsAnnounce() const { return _announceEnabled; }
173 void SetAnnounce(bool announce) { _announceEnabled = announce; }
174
175 // will be saved to DB on next channel save interval
176 void SetDirty() { _isDirty = true; }
177 void UpdateChannelInDB();
178
179 void SetPassword(std::string const& password) { _channelPassword = password; }
180 bool CheckPassword(std::string const& password) const { return _channelPassword.empty() || (_channelPassword == password); }
181
182 uint32 GetNumPlayers() const { return _playersStore.size(); }
183
184 uint8 GetFlags() const { return _channelFlags; }
185 bool HasFlag(uint8 flag) const { return (_channelFlags & flag) != 0; }
186
187 AreaTableEntry const* GetZoneEntry() const { return _zoneEntry; }
188
189 void JoinChannel(Player* player, std::string const& pass = "");
190 void LeaveChannel(Player* player, bool send = true);
191
192 void KickOrBan(Player const* player, std::string const& badname, bool ban);
193 void Kick(Player const* player, std::string const& badname) { KickOrBan(player, badname, false); }
194 void Ban(Player const* player, std::string const& badname) { KickOrBan(player, badname, true); }
195
196 void UnBan(Player const* player, std::string const& badname);
197 void Password(Player const* player, std::string const& pass);
198 void SetMode(Player const* player, std::string const& p2n, bool mod, bool set);
199
200 void SetModerator(Player const* player, std::string const& newname) { SetMode(player, newname, true, true); }
201 void UnsetModerator(Player const* player, std::string const& newname) { SetMode(player, newname, true, false); }
202 void SetMute(Player const* player, std::string const& newname) { SetMode(player, newname, false, true); }
203 void UnsetMute(Player const* player, std::string const& newname) { SetMode(player, newname, false, false); }
204
205 void SetInvisible(Player const* player, bool on);
206
207 void SetOwner(ObjectGuid guid, bool exclaim = true);
208 void SetOwner(Player const* player, std::string const& name);
209 void SendWhoOwner(ObjectGuid guid);
210
211 void List(Player const* player) const;
212 void Announce(Player const* player);
213 void Say(ObjectGuid guid, std::string const& what, uint32 lang) const;
214 void Invite(Player const* player, std::string const& newp);
215 void Voice(ObjectGuid guid1, ObjectGuid guid2) const;
216 void DeVoice(ObjectGuid guid1, ObjectGuid guid2) const;
217 void JoinNotify(ObjectGuid guid) const; // invisible notify
218 void LeaveNotify(ObjectGuid guid) const; // invisible notify
219 void SetOwnership(bool ownership) { _ownershipEnabled = ownership; }
220
221 private:
222
223 template<class Builder>
224 void SendToAll(Builder&, ObjectGuid guid = ObjectGuid::Empty) const;
225
226 template<class Builder>
227 void SendToAllButOne(Builder& builder, ObjectGuid who) const;
228
229 template<class Builder>
230 void SendToOne(Builder& builder, ObjectGuid who) const;
231
232 bool IsOn(ObjectGuid who) const { return _playersStore.find(who) != _playersStore.end(); }
233 bool IsBanned(ObjectGuid guid) const { return _bannedStore.find(guid) != _bannedStore.end(); }
234
236 {
237 PlayerContainer::const_iterator itr = _playersStore.find(guid);
238 return itr != _playersStore.end() ? itr->second.flags : 0;
239 }
240
241 void SetModerator(ObjectGuid guid, bool set);
242 void SetMute(ObjectGuid guid, bool set);
243
244 typedef std::map<ObjectGuid, PlayerInfo> PlayerContainer;
246
247 bool _isDirty; // whether the channel needs to be saved to DB
249
250 bool _announceEnabled; //< Whether we should broadcast a packet whenever a player joins/exits the channel
251 bool _ownershipEnabled; //< Whether the channel has to maintain an owner
252 bool _isOwnerInvisible; //< Whether the channel is owned by invisible GM, ownership should change to first player that joins channel
253
258 std::string _channelName;
259 std::string _channelPassword;
262
264};
265#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
uint16 flags
std::unordered_set< ObjectGuid > GuidUnorderedSet
Definition ObjectGuid.h:263
bool IsConstant() const
Definition Channel.h:169
uint32 _channelId
Definition Channel.h:255
BannedContainer _bannedStore
Definition Channel.h:261
GuidUnorderedSet BannedContainer
Definition Channel.h:245
Channel(Channel const &)=delete
bool _ownershipEnabled
Definition Channel.h:251
bool _announceEnabled
Definition Channel.h:250
bool HasFlag(uint8 flag) const
Definition Channel.h:185
uint32 _channelTeam
Definition Channel.h:256
time_t _nextActivityUpdateTime
Definition Channel.h:248
uint8 _channelFlags
Definition Channel.h:254
std::string _channelName
Definition Channel.h:258
void SetMute(Player const *player, std::string const &newname)
Definition Channel.h:202
void SetModerator(Player const *player, std::string const &newname)
Definition Channel.h:200
void Ban(Player const *player, std::string const &badname)
Definition Channel.h:194
bool IsLFG() const
Definition Channel.h:170
bool _isOwnerInvisible
Definition Channel.h:252
void UnsetMute(Player const *player, std::string const &newname)
Definition Channel.h:203
uint32 GetChannelId() const
Definition Channel.h:168
bool IsAnnounce() const
Definition Channel.h:172
bool CheckPassword(std::string const &password) const
Definition Channel.h:180
bool IsOn(ObjectGuid who) const
Definition Channel.h:232
void SetDirty()
Definition Channel.h:176
void UnsetModerator(Player const *player, std::string const &newname)
Definition Channel.h:201
void SetPassword(std::string const &password)
Definition Channel.h:179
bool _isDirty
Definition Channel.h:247
void Kick(Player const *player, std::string const &badname)
Definition Channel.h:193
Channel(Channel &&)=delete
Channel & operator=(Channel &&)=delete
void SetAnnounce(bool announce)
Definition Channel.h:173
void SetOwnership(bool ownership)
Definition Channel.h:219
uint8 GetPlayerFlags(ObjectGuid guid) const
Definition Channel.h:235
uint32 GetNumPlayers() const
Definition Channel.h:182
bool IsBanned(ObjectGuid guid) const
Definition Channel.h:233
AreaTableEntry const * _zoneEntry
Definition Channel.h:263
ObjectGuid _ownerGuid
Definition Channel.h:257
std::string _channelPassword
Definition Channel.h:259
uint8 GetFlags() const
Definition Channel.h:184
std::map< ObjectGuid, PlayerInfo > PlayerContainer
Definition Channel.h:244
PlayerContainer _playersStore
Definition Channel.h:260
Channel & operator=(Channel const &)=delete
AreaTableEntry const * GetZoneEntry() const
Definition Channel.h:187
static ObjectGuid const Empty
Definition ObjectGuid.h:140
void SetModerator(bool state)
Definition Channel.h:140
bool HasFlag(uint8 flag) const
Definition Channel.h:129
bool IsOwner() const
Definition Channel.h:132
bool IsMuted() const
Definition Channel.h:146
bool IsInvisible() const
Definition Channel.h:126
void SetInvisible(bool on)
Definition Channel.h:127
void SetFlag(uint8 flag)
Definition Channel.h:130
void SetOwner(bool state)
Definition Channel.h:133
void SetMuted(bool state)
Definition Channel.h:147
bool IsModerator() const
Definition Channel.h:139