TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Channel.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef _CHANNEL_H
20 #define _CHANNEL_H
21 
22 #include "Common.h"
23 #include "ObjectGuid.h"
24 #include "WorldPacket.h"
25 
26 class Player;
27 
28 namespace WorldPackets
29 {
30  namespace Channel
31  {
32  class ChannelNotify;
33  }
34 }
35 
37 {
38  CHAT_JOINED_NOTICE = 0x00, //+ "%s joined channel.";
39  CHAT_LEFT_NOTICE = 0x01, //+ "%s left channel.";
40  //CHAT_SUSPENDED_NOTICE = 0x01, // "%s left channel.";
41  CHAT_YOU_JOINED_NOTICE = 0x02, //+ "Joined Channel: [%s]"; -- You joined
42  //CHAT_YOU_CHANGED_NOTICE = 0x02, // "Changed Channel: [%s]";
43  CHAT_YOU_LEFT_NOTICE = 0x03, //+ "Left Channel: [%s]"; -- You left
44  CHAT_WRONG_PASSWORD_NOTICE = 0x04, //+ "Wrong password for %s.";
45  CHAT_NOT_MEMBER_NOTICE = 0x05, //+ "Not on channel %s.";
46  CHAT_NOT_MODERATOR_NOTICE = 0x06, //+ "Not a moderator of %s.";
47  CHAT_PASSWORD_CHANGED_NOTICE = 0x07, //+ "[%s] Password changed by %s.";
48  CHAT_OWNER_CHANGED_NOTICE = 0x08, //+ "[%s] Owner changed to %s.";
49  CHAT_PLAYER_NOT_FOUND_NOTICE = 0x09, //+ "[%s] Player %s was not found.";
50  CHAT_NOT_OWNER_NOTICE = 0x0A, //+ "[%s] You are not the channel owner.";
51  CHAT_CHANNEL_OWNER_NOTICE = 0x0B, //+ "[%s] Channel owner is %s.";
53  CHAT_ANNOUNCEMENTS_ON_NOTICE = 0x0D, //+ "[%s] Channel announcements enabled by %s.";
54  CHAT_ANNOUNCEMENTS_OFF_NOTICE = 0x0E, //+ "[%s] Channel announcements disabled by %s.";
55  CHAT_MODERATION_ON_NOTICE = 0x0F, //+ "[%s] Channel moderation enabled by %s.";
56  CHAT_MODERATION_OFF_NOTICE = 0x10, //+ "[%s] Channel moderation disabled by %s.";
57  CHAT_MUTED_NOTICE = 0x11, //+ "[%s] You do not have permission to speak.";
58  CHAT_PLAYER_KICKED_NOTICE = 0x12, //? "[%s] Player %s kicked by %s.";
59  CHAT_BANNED_NOTICE = 0x13, //+ "[%s] You are bannedStore from that channel.";
60  CHAT_PLAYER_BANNED_NOTICE = 0x14, //? "[%s] Player %s bannedStore by %s.";
61  CHAT_PLAYER_UNBANNED_NOTICE = 0x15, //? "[%s] Player %s unbanned by %s.";
62  CHAT_PLAYER_NOT_BANNED_NOTICE = 0x16, //+ "[%s] Player %s is not bannedStore.";
63  CHAT_PLAYER_ALREADY_MEMBER_NOTICE = 0x17, //+ "[%s] Player %s is already on the channel.";
64  CHAT_INVITE_NOTICE = 0x18, //+ "%2$s has invited you to join the channel '%1$s'.";
65  CHAT_INVITE_WRONG_FACTION_NOTICE = 0x19, //+ "Target is in the wrong alliance for %s.";
66  CHAT_WRONG_FACTION_NOTICE = 0x1A, //+ "Wrong alliance for %s.";
67  CHAT_INVALID_NAME_NOTICE = 0x1B, //+ "Invalid channel name";
68  CHAT_NOT_MODERATED_NOTICE = 0x1C, //+ "%s is not moderated";
69  CHAT_PLAYER_INVITED_NOTICE = 0x1D, //+ "[%s] You invited %s to join the channel";
70  CHAT_PLAYER_INVITE_BANNED_NOTICE = 0x1E, //+ "[%s] %s has been bannedStore.";
71  CHAT_THROTTLED_NOTICE = 0x1F, //+ "[%s] The number of messages that can be sent to this channel is limited, please wait to send another message.";
72  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.
73  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.
74  CHAT_VOICE_ON_NOTICE = 0x22, //+ "[%s] Channel voice enabled by %s.";
75  CHAT_VOICE_OFF_NOTICE = 0x23, //+ "[%s] Channel voice disabled by %s.";
78 };
79 
81 {
84  // 0x02
91  // General 0x18 = 0x10 | 0x08
92  // Trade 0x3C = 0x20 | 0x10 | 0x08 | 0x04
93  // LocalDefence 0x18 = 0x10 | 0x08
94  // GuildRecruitment 0x38 = 0x20 | 0x10 | 0x08
95  // LookingForGroup 0x50 = 0x40 | 0x10
96 };
97 
99 {
101  CHANNEL_DBC_FLAG_INITIAL = 0x00001, // General, Trade, LocalDefense, LFG
102  CHANNEL_DBC_FLAG_ZONE_DEP = 0x00002, // General, Trade, LocalDefense, GuildRecruitment
103  CHANNEL_DBC_FLAG_GLOBAL = 0x00004, // WorldDefense
104  CHANNEL_DBC_FLAG_TRADE = 0x00008, // Trade, LFG
105  CHANNEL_DBC_FLAG_CITY_ONLY = 0x00010, // Trade, GuildRecruitment, LFG
106  CHANNEL_DBC_FLAG_CITY_ONLY2 = 0x00020, // Trade, GuildRecruitment, LFG
107  CHANNEL_DBC_FLAG_DEFENSE = 0x10000, // LocalDefense, WorldDefense
108  CHANNEL_DBC_FLAG_GUILD_REQ = 0x20000, // GuildRecruitment
109  CHANNEL_DBC_FLAG_LFG = 0x40000, // LFG
110  CHANNEL_DBC_FLAG_UNK1 = 0x80000 // General
111 };
112 
114 {
122  // 0x40
123  // 0x80
124 };
125 
127 {
128  struct PlayerInfo
129  {
131 
132  uint8 GetFlags() const { return _flags; }
133  inline bool HasFlag(uint8 flag) const { return (_flags & flag) != 0; }
134  inline void SetFlag(uint8 flag) { _flags |= flag; }
135  inline void RemoveFlag(uint8 flag) { _flags &= ~flag; }
136 
137  bool IsOwner() const { return HasFlag(MEMBER_FLAG_OWNER); }
138  void SetOwner(bool state)
139  {
140  if (state)
141  SetFlag(MEMBER_FLAG_OWNER);
142  else
143  RemoveFlag(MEMBER_FLAG_OWNER);
144  }
145 
146  bool IsModerator() const { return HasFlag(MEMBER_FLAG_MODERATOR); }
147  void SetModerator(bool state)
148  {
149  if (state)
150  SetFlag(MEMBER_FLAG_MODERATOR);
151  else
152  RemoveFlag(MEMBER_FLAG_MODERATOR);
153  }
154 
155  bool IsMuted() const { return HasFlag(MEMBER_FLAG_MUTED); }
156  void SetMuted(bool state)
157  {
158  if (state)
159  SetFlag(MEMBER_FLAG_MUTED);
160  else
161  RemoveFlag(MEMBER_FLAG_MUTED);
162  }
163 
164  private:
166  };
167 
168  public:
169  Channel(std::string const& name, uint32 channel_id, uint32 Team = 0);
170 
171  std::string const& GetName() const { return _name; }
172  uint32 GetChannelId() const { return _channelId; }
173  bool IsConstant() const { return _channelId != 0; }
174  bool IsAnnounce() const { return _announce; }
175  bool IsLFG() const { return (GetFlags() & CHANNEL_FLAG_LFG) != 0; }
176  std::string const& GetPassword() const { return _password; }
177  void SetPassword(std::string const& npassword) { _password = npassword; }
178  void SetAnnounce(bool nannounce) { _announce = nannounce; }
179  uint32 GetNumPlayers() const { return uint32(_playersStore.size()); }
180  uint8 GetFlags() const { return _flags; }
181  bool HasFlag(uint8 flag) const { return (_flags & flag) != 0; }
182 
183  void JoinChannel(Player* player, std::string const& pass);
184  void LeaveChannel(Player* player, bool send = true);
185  void KickOrBan(Player const* player, std::string const& badname, bool ban);
186  void Kick(Player const* player, std::string const& badname) { KickOrBan(player, badname, false); }
187  void Ban(Player const* player, std::string const& badname) { KickOrBan(player, badname, true); }
188  void UnBan(Player const* player, std::string const& badname);
189  void Password(Player const* player, std::string const& pass);
190  void SetMode(Player const* player, std::string const& p2n, bool mod, bool set);
191  void SetOwner(ObjectGuid const& guid, bool exclaim = true);
192  void SetOwner(Player const* player, std::string const& name);
193  void SendWhoOwner(Player const* player);
194  void SetModerator(Player const* player, std::string const& newname) { SetMode(player, newname, true, true); }
195  void UnsetModerator(Player const* player, std::string const& newname) { SetMode(player, newname, true, false); }
196  void SetMute(Player const* player, std::string const& newname) { SetMode(player, newname, false, true); }
197  void UnsetMute(Player const* player, std::string const& newname) { SetMode(player, newname, false, false); }
198  void SilenceAll(Player const* player, std::string const& name);
199  void SilenceVoice(Player const* player, std::string const& name);
200  void UnsilenceAll(Player const* player, std::string const& name);
201  void UnsilenceVoice(Player const* player, std::string const& name);
202  void List(Player const* player);
203  void Announce(Player const* player);
204  void Say(ObjectGuid const& guid, std::string const& what, uint32 lang);
205  void DeclineInvite(Player const* player);
206  void Invite(Player const* player, std::string const& newp);
207  void Voice(Player const* player);
208  void DeVoice(Player const* player);
209  void JoinNotify(Player const* player);
210  void LeaveNotify(Player const* player);
211  void SetOwnership(bool ownership) { _ownership = ownership; }
212  static void CleanOldChannelsInDB();
213 
214  private:
215  // initial packet data (notify type and channel name)
216  void MakeNotifyPacket(WorldPackets::Channel::ChannelNotify& data, uint8 notifyType);
217  // type specific packet data
218  void MakeJoined(WorldPackets::Channel::ChannelNotify& data, ObjectGuid const& guid); //+ 0x00
219  void MakeLeft(WorldPackets::Channel::ChannelNotify& data, ObjectGuid const& guid); //+ 0x01
220  void MakeYouJoined(WorldPackets::Channel::ChannelNotify& data); //+ 0x02
221  void MakeYouLeft(WorldPackets::Channel::ChannelNotify& data); //+ 0x03
222  void MakeWrongPassword(WorldPackets::Channel::ChannelNotify& data); //? 0x04
223  void MakeNotMember(WorldPackets::Channel::ChannelNotify& data); //? 0x05
224  void MakeNotModerator(WorldPackets::Channel::ChannelNotify& data); //? 0x06
225  void MakePasswordChanged(WorldPackets::Channel::ChannelNotify& data, ObjectGuid const& guid); //+ 0x07
226  void MakeOwnerChanged(WorldPackets::Channel::ChannelNotify& data, ObjectGuid const& guid); //? 0x08
227  void MakePlayerNotFound(WorldPackets::Channel::ChannelNotify& data, std::string const& name); //+ 0x09
228  void MakeNotOwner(WorldPackets::Channel::ChannelNotify& data); //? 0x0A
229  void MakeChannelOwner(WorldPackets::Channel::ChannelNotify& data); //? 0x0B
230  void MakeModeChange(WorldPackets::Channel::ChannelNotify& data, ObjectGuid const& guid, uint8 oldFlags, uint8 newFlags); //+ 0x0C
231  void MakeAnnouncementsOn(WorldPackets::Channel::ChannelNotify& data, ObjectGuid const& guid); //+ 0x0D
232  void MakeAnnouncementsOff(WorldPackets::Channel::ChannelNotify& data, ObjectGuid const& guid); //+ 0x0E
233  void MakeMuted(WorldPackets::Channel::ChannelNotify& data); //? 0x11
234  void MakePlayerKicked(WorldPackets::Channel::ChannelNotify& data, ObjectGuid const& bad, ObjectGuid const& good); //? 0x12
235  void MakeBanned(WorldPackets::Channel::ChannelNotify& data); //? 0x13
236  void MakePlayerBanned(WorldPackets::Channel::ChannelNotify& data, ObjectGuid const& bad, ObjectGuid const& good); //? 0x14
237  void MakePlayerUnbanned(WorldPackets::Channel::ChannelNotify& data, ObjectGuid const& bad, ObjectGuid const& good); //? 0x15
238  void MakePlayerNotBanned(WorldPackets::Channel::ChannelNotify& data, std::string const& name); //? 0x16
239  void MakePlayerAlreadyMember(WorldPackets::Channel::ChannelNotify& data, ObjectGuid const& guid); //+ 0x17
240  void MakeInvite(WorldPackets::Channel::ChannelNotify& data, ObjectGuid const& guid); //? 0x18
241  void MakeInviteWrongFaction(WorldPackets::Channel::ChannelNotify& data); //? 0x19
242  void MakeWrongFaction(WorldPackets::Channel::ChannelNotify& data); //? 0x1A
243  void MakeInvalidName(WorldPackets::Channel::ChannelNotify& data); //? 0x1B
244  void MakeNotModerated(WorldPackets::Channel::ChannelNotify& data); //? 0x1C
245  void MakePlayerInvited(WorldPackets::Channel::ChannelNotify& data, std::string const& name); //+ 0x1D
246  void MakePlayerInviteBanned(WorldPackets::Channel::ChannelNotify& data, std::string const& name); //? 0x1E
247  void MakeThrottled(WorldPackets::Channel::ChannelNotify& data); //? 0x1F
248  void MakeNotInArea(WorldPackets::Channel::ChannelNotify& data); //? 0x20
249  void MakeNotInLfg(WorldPackets::Channel::ChannelNotify& data); //? 0x21
250  void MakeVoiceOn(WorldPackets::Channel::ChannelNotify& data, ObjectGuid const& guid); //+ 0x22
251  void MakeVoiceOff(WorldPackets::Channel::ChannelNotify& data, ObjectGuid const& guid); //+ 0x23
252 
253  void SendToAll(WorldPacket const* data, ObjectGuid const& guid = ObjectGuid::Empty);
254  void SendToAllButOne(WorldPacket const* data, ObjectGuid const& who);
255  void SendToOne(WorldPacket const* data, ObjectGuid const& who);
256 
257  bool IsOn(ObjectGuid const& who) const { return _playersStore.find(who) != _playersStore.end(); }
258  bool IsBanned(ObjectGuid const& guid) const { return _bannedStore.find(guid) != _bannedStore.end(); }
259 
260  void UpdateChannelInDB() const;
261  void UpdateChannelUseageInDB() const;
262 
263  uint8 GetPlayerFlags(ObjectGuid const& guid) const
264  {
265  PlayerContainer::const_iterator itr = _playersStore.find(guid);
266  return itr != _playersStore.end() ? itr->second.GetFlags() : 0;
267  }
268 
269  void SetModerator(ObjectGuid const& guid, bool set);
270  void SetMute(ObjectGuid const& guid, bool set);
271 
272  typedef std::map<ObjectGuid, PlayerInfo> PlayerContainer;
274 
275  bool _announce;
277  bool _IsSaved;
282  std::string _name;
283  std::string _password;
284  PlayerContainer _playersStore;
285  BannedContainer _bannedStore;
286 };
287 
288 #endif
Definition: Channel.h:102
BannedContainer _bannedStore
Definition: Channel.h:285
Definition: Channel.h:74
std::map< ObjectGuid, PlayerInfo > PlayerContainer
Definition: Channel.h:272
Definition: Channel.h:118
Definition: Channel.h:106
uint32 GetChannelId() const
Definition: Channel.h:172
uint8 GetPlayerFlags(ObjectGuid const &guid) const
Definition: Channel.h:263
Definition: Channel.h:109
void SetAnnounce(bool nannounce)
Definition: Channel.h:178
Definition: Channel.h:62
Definition: Channel.h:56
static ObjectGuid const Empty
Definition: ObjectGuid.h:196
Definition: Channel.h:117
Definition: Channel.h:52
Definition: Channel.h:48
Definition: Channel.h:70
void UnsetModerator(Player const *player, std::string const &newname)
Definition: Channel.h:195
Definition: Channel.h:53
Definition: Channel.h:60
void SetPassword(std::string const &npassword)
Definition: Channel.h:177
Definition: Channel.h:69
std::string _name
Definition: Channel.h:282
void RemoveFlag(uint8 flag)
Definition: Channel.h:135
Definition: Channel.h:72
Definition: Channel.h:41
Definition: ChannelPackets.h:52
bool IsBanned(ObjectGuid const &guid) const
Definition: Channel.h:258
Definition: Channel.h:73
Definition: Channel.h:38
Definition: Channel.h:71
Definition: Channel.h:76
uint8 _flags
Definition: Channel.h:278
Definition: Channel.h:75
Definition: Channel.h:54
Definition: Channel.h:67
ObjectGuid PlayerGuid
Definition: Channel.h:130
Definition: Channel.h:45
GuidSet BannedContainer
Definition: Channel.h:273
Definition: Channel.h:68
Definition: Channel.h:126
Definition: Channel.h:89
bool HasFlag(uint8 flag) const
Definition: Channel.h:133
Definition: Channel.h:128
Definition: Channel.h:108
bool IsAnnounce() const
Definition: Channel.h:174
Definition: Channel.h:44
Definition: Channel.h:65
ChatNotify
Definition: Channel.h:36
void SetMute(Player const *player, std::string const &newname)
Definition: Channel.h:196
std::string const & GetPassword() const
Definition: Channel.h:176
uint8 GetFlags() const
Definition: Channel.h:132
Definition: Channel.h:49
Definition: Channel.h:64
bool _ownership
Definition: Channel.h:276
void SetModerator(Player const *player, std::string const &newname)
Definition: Channel.h:194
Team
Definition: SharedDefines.h:997
Definition: Channel.h:82
Definition: Channel.h:105
Definition: Channel.h:101
bool IsOwner() const
Definition: Channel.h:137
Definition: Channel.h:47
bool HasFlag(uint8 flag) const
Definition: Channel.h:181
void SetOwnership(bool ownership)
Definition: Channel.h:211
void SetModerator(bool state)
Definition: Channel.h:147
uint32 GetNumPlayers() const
Definition: Channel.h:179
ChannelFlags
Definition: Channel.h:80
void Ban(Player const *player, std::string const &badname)
Definition: Channel.h:187
void Kick(Player const *player, std::string const &badname)
Definition: Channel.h:186
bool IsModerator() const
Definition: Channel.h:146
Definition: Channel.h:116
bool IsConstant() const
Definition: Channel.h:173
Definition: Channel.h:103
uint32_t uint32
Definition: Define.h:150
Definition: Channel.h:119
Definition: Channel.h:107
void UnsetMute(Player const *player, std::string const &newname)
Definition: Channel.h:197
Definition: Channel.h:58
void SetMuted(bool state)
Definition: Channel.h:156
Definition: Channel.h:83
ChannelMemberFlags
Definition: Channel.h:113
Definition: Channel.h:104
Definition: Channel.h:88
Definition: BattlegroundMgr.h:57
Definition: Channel.h:55
Definition: Channel.h:85
std::string _password
Definition: Channel.h:283
Definition: Channel.h:77
bool _announce
Definition: Channel.h:275
uint32 _channelId
Definition: Channel.h:279
Definition: Channel.h:115
Definition: Channel.h:57
std::set< ObjectGuid > GuidSet
Definition: ObjectGuid.h:332
bool IsLFG() const
Definition: Channel.h:175
#define TC_GAME_API
Definition: Define.h:134
Definition: Channel.h:87
Definition: Channel.h:46
Definition: Channel.h:110
Definition: Channel.h:61
ChannelDBCFlags
Definition: Channel.h:98
PlayerContainer _playersStore
Definition: Channel.h:284
uint8_t uint8
Definition: Define.h:152
bool IsMuted() const
Definition: Channel.h:155
Definition: Channel.h:51
void SetOwner(bool state)
Definition: Channel.h:138
std::string const & GetName() const
Definition: Channel.h:171
Definition: ObjectGuid.h:189
void SetFlag(uint8 flag)
Definition: Channel.h:134
uint32_t uint32
Definition: g3dmath.h:168
Definition: Channel.h:66
Definition: Channel.h:43
ObjectGuid _ownerGUID
Definition: Channel.h:281
Definition: Channel.h:39
Definition: Channel.h:90
bool IsOn(ObjectGuid const &who) const
Definition: Channel.h:257
Say
Definition: boss_broodlord_lashlayer.cpp:23
uint8 GetFlags() const
Definition: Channel.h:180
Definition: Channel.h:86
Definition: WorldPacket.h:26
Definition: Channel.h:120
Definition: Channel.h:100
Definition: Channel.h:50
Definition: Channel.h:63
Definition: Channel.h:121
bool _IsSaved
Definition: Channel.h:277
uint32 _team
Definition: Channel.h:280
Definition: Channel.h:59