[7023] Remove not used useCharges for IsImmunedToSpell/IsImmunedToDamage
[getmangos.git] / src / game / Channel.h
blob8a0c944923970a15b1f379cf43f3abbfc57fdb38
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef _CHANNEL_H
20 #define _CHANNEL_H
22 #include "Common.h"
23 #include "WorldPacket.h"
24 #include "WorldSession.h"
25 #include "Opcodes.h"
26 #include "Player.h"
28 #include <list>
29 #include <map>
30 #include <string>
32 class Channel
34 enum ChatNotify
36 CHAT_JOINED_NOTICE = 0x00, //+ "%s joined channel.";
37 CHAT_LEFT_NOTICE = 0x01, //+ "%s left channel.";
38 //CHAT_SUSPENDED_NOTICE = 0x01, // "%s left channel.";
39 CHAT_YOU_JOINED_NOTICE = 0x02, //+ "Joined Channel: [%s]"; -- You joined
40 //CHAT_YOU_CHANGED_NOTICE = 0x02, // "Changed Channel: [%s]";
41 CHAT_YOU_LEFT_NOTICE = 0x03, //+ "Left Channel: [%s]"; -- You left
42 CHAT_WRONG_PASSWORD_NOTICE = 0x04, //+ "Wrong password for %s.";
43 CHAT_NOT_MEMBER_NOTICE = 0x05, //+ "Not on channel %s.";
44 CHAT_NOT_MODERATOR_NOTICE = 0x06, //+ "Not a moderator of %s.";
45 CHAT_PASSWORD_CHANGED_NOTICE = 0x07, //+ "[%s] Password changed by %s.";
46 CHAT_OWNER_CHANGED_NOTICE = 0x08, //+ "[%s] Owner changed to %s.";
47 CHAT_PLAYER_NOT_FOUND_NOTICE = 0x09, //+ "[%s] Player %s was not found.";
48 CHAT_NOT_OWNER_NOTICE = 0x0A, //+ "[%s] You are not the channel owner.";
49 CHAT_CHANNEL_OWNER_NOTICE = 0x0B, //+ "[%s] Channel owner is %s.";
50 CHAT_MODE_CHANGE_NOTICE = 0x0C, //?
51 CHAT_ANNOUNCEMENTS_ON_NOTICE = 0x0D, //+ "[%s] Channel announcements enabled by %s.";
52 CHAT_ANNOUNCEMENTS_OFF_NOTICE = 0x0E, //+ "[%s] Channel announcements disabled by %s.";
53 CHAT_MODERATION_ON_NOTICE = 0x0F, //+ "[%s] Channel moderation enabled by %s.";
54 CHAT_MODERATION_OFF_NOTICE = 0x10, //+ "[%s] Channel moderation disabled by %s.";
55 CHAT_MUTED_NOTICE = 0x11, //+ "[%s] You do not have permission to speak.";
56 CHAT_PLAYER_KICKED_NOTICE = 0x12, //? "[%s] Player %s kicked by %s.";
57 CHAT_BANNED_NOTICE = 0x13, //+ "[%s] You are banned from that channel.";
58 CHAT_PLAYER_BANNED_NOTICE = 0x14, //? "[%s] Player %s banned by %s.";
59 CHAT_PLAYER_UNBANNED_NOTICE = 0x15, //? "[%s] Player %s unbanned by %s.";
60 CHAT_PLAYER_NOT_BANNED_NOTICE = 0x16, //+ "[%s] Player %s is not banned.";
61 CHAT_PLAYER_ALREADY_MEMBER_NOTICE = 0x17, //+ "[%s] Player %s is already on the channel.";
62 CHAT_INVITE_NOTICE = 0x18, //+ "%2$s has invited you to join the channel '%1$s'.";
63 CHAT_INVITE_WRONG_FACTION_NOTICE = 0x19, //+ "Target is in the wrong alliance for %s.";
64 CHAT_WRONG_FACTION_NOTICE = 0x1A, //+ "Wrong alliance for %s.";
65 CHAT_INVALID_NAME_NOTICE = 0x1B, //+ "Invalid channel name";
66 CHAT_NOT_MODERATED_NOTICE = 0x1C, //+ "%s is not moderated";
67 CHAT_PLAYER_INVITED_NOTICE = 0x1D, //+ "[%s] You invited %s to join the channel";
68 CHAT_PLAYER_INVITE_BANNED_NOTICE = 0x1E, //+ "[%s] %s has been banned.";
69 CHAT_THROTTLED_NOTICE = 0x1F, //+ "[%s] The number of messages that can be sent to this channel is limited, please wait to send another message.";
70 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.
71 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.
72 CHAT_VOICE_ON_NOTICE = 0x22, //+ "[%s] Channel voice enabled by %s.";
73 CHAT_VOICE_OFF_NOTICE = 0x23, //+ "[%s] Channel voice disabled by %s.";
76 enum ChannelFlags
78 CHANNEL_FLAG_NONE = 0x00,
79 CHANNEL_FLAG_CUSTOM = 0x01,
80 // 0x02
81 CHANNEL_FLAG_TRADE = 0x04,
82 CHANNEL_FLAG_NOT_LFG = 0x08,
83 CHANNEL_FLAG_GENERAL = 0x10,
84 CHANNEL_FLAG_CITY = 0x20,
85 CHANNEL_FLAG_LFG = 0x40,
86 CHANNEL_FLAG_VOICE = 0x80
87 // General 0x18 = 0x10 | 0x08
88 // Trade 0x3C = 0x20 | 0x10 | 0x08 | 0x04
89 // LocalDefence 0x18 = 0x10 | 0x08
90 // GuildRecruitment 0x38 = 0x20 | 0x10 | 0x08
91 // LookingForGroup 0x50 = 0x40 | 0x10
94 enum ChannelDBCFlags
96 CHANNEL_DBC_FLAG_NONE = 0x00000,
97 CHANNEL_DBC_FLAG_INITIAL = 0x00001, // General, Trade, LocalDefense, LFG
98 CHANNEL_DBC_FLAG_ZONE_DEP = 0x00002, // General, Trade, LocalDefense, GuildRecruitment
99 CHANNEL_DBC_FLAG_GLOBAL = 0x00004, // WorldDefense
100 CHANNEL_DBC_FLAG_TRADE = 0x00008, // Trade
101 CHANNEL_DBC_FLAG_CITY_ONLY = 0x00010, // Trade, GuildRecruitment
102 CHANNEL_DBC_FLAG_CITY_ONLY2 = 0x00020, // Trade, GuildRecruitment
103 CHANNEL_DBC_FLAG_DEFENSE = 0x10000, // LocalDefense, WorldDefense
104 CHANNEL_DBC_FLAG_GUILD_REQ = 0x20000, // GuildRecruitment
105 CHANNEL_DBC_FLAG_LFG = 0x40000 // LookingForGroup
108 enum ChannelMemberFlags
110 MEMBER_FLAG_NONE = 0x00,
111 MEMBER_FLAG_OWNER = 0x01,
112 MEMBER_FLAG_MODERATOR = 0x02,
113 MEMBER_FLAG_VOICED = 0x04,
114 MEMBER_FLAG_MUTED = 0x08,
115 MEMBER_FLAG_CUSTOM = 0x10,
116 MEMBER_FLAG_MIC_MUTED = 0x20,
117 // 0x40
118 // 0x80
121 struct PlayerInfo
123 uint64 player;
124 uint8 flags;
126 bool HasFlag(uint8 flag) { return flags & flag; }
127 void SetFlag(uint8 flag) { if(!HasFlag(flag)) flags |= flag; }
128 bool IsOwner() { return flags & MEMBER_FLAG_OWNER; }
129 void SetOwner(bool state)
131 if(state) flags |= MEMBER_FLAG_OWNER;
132 else flags &= ~MEMBER_FLAG_OWNER;
134 bool IsModerator() { return flags & MEMBER_FLAG_MODERATOR; }
135 void SetModerator(bool state)
137 if(state) flags |= MEMBER_FLAG_MODERATOR;
138 else flags &= ~MEMBER_FLAG_MODERATOR;
140 bool IsMuted() { return flags & MEMBER_FLAG_MUTED; }
141 void SetMuted(bool state)
143 if(state) flags |= MEMBER_FLAG_MUTED;
144 else flags &= ~MEMBER_FLAG_MUTED;
148 typedef std::map<uint64, PlayerInfo> PlayerList;
149 PlayerList players;
150 typedef std::set<uint64> BannedList;
151 BannedList banned;
152 bool m_announce;
153 bool m_moderate;
154 std::string m_name;
155 std::string m_password;
156 uint8 m_flags;
157 uint32 m_channelId;
158 uint64 m_ownerGUID;
160 private:
161 // initial packet data (notify type and channel name)
162 void MakeNotifyPacket(WorldPacket *data, uint8 notify_type);
163 // type specific packet data
164 void MakeJoined(WorldPacket *data, uint64 guid); //+ 0x00
165 void MakeLeft(WorldPacket *data, uint64 guid); //+ 0x01
166 void MakeYouJoined(WorldPacket *data); //+ 0x02
167 void MakeYouLeft(WorldPacket *data); //+ 0x03
168 void MakeWrongPassword(WorldPacket *data); //? 0x04
169 void MakeNotMember(WorldPacket *data); //? 0x05
170 void MakeNotModerator(WorldPacket *data); //? 0x06
171 void MakePasswordChanged(WorldPacket *data, uint64 guid); //+ 0x07
172 void MakeOwnerChanged(WorldPacket *data, uint64 guid); //? 0x08
173 void MakePlayerNotFound(WorldPacket *data, const std::string& name); //+ 0x09
174 void MakeNotOwner(WorldPacket *data); //? 0x0A
175 void MakeChannelOwner(WorldPacket *data); //? 0x0B
176 void MakeModeChange(WorldPacket *data, uint64 guid, uint8 oldflags); //+ 0x0C
177 void MakeAnnouncementsOn(WorldPacket *data, uint64 guid); //+ 0x0D
178 void MakeAnnouncementsOff(WorldPacket *data, uint64 guid); //+ 0x0E
179 void MakeModerationOn(WorldPacket *data, uint64 guid); //+ 0x0F
180 void MakeModerationOff(WorldPacket *data, uint64 guid); //+ 0x10
181 void MakeMuted(WorldPacket *data); //? 0x11
182 void MakePlayerKicked(WorldPacket *data, uint64 bad, uint64 good); //? 0x12
183 void MakeBanned(WorldPacket *data); //? 0x13
184 void MakePlayerBanned(WorldPacket *data, uint64 bad, uint64 good); //? 0x14
185 void MakePlayerUnbanned(WorldPacket *data, uint64 bad, uint64 good); //? 0x15
186 void MakePlayerNotBanned(WorldPacket *data, uint64 guid); //? 0x16
187 void MakePlayerAlreadyMember(WorldPacket *data, uint64 guid); //+ 0x17
188 void MakeInvite(WorldPacket *data, uint64 guid); //? 0x18
189 void MakeInviteWrongFaction(WorldPacket *data); //? 0x19
190 void MakeWrongFaction(WorldPacket *data); //? 0x1A
191 void MakeInvalidName(WorldPacket *data); //? 0x1B
192 void MakeNotModerated(WorldPacket *data); //? 0x1C
193 void MakePlayerInvited(WorldPacket *data, const std::string& name); //+ 0x1D
194 void MakePlayerInviteBanned(WorldPacket *data, uint64 guid); //? 0x1E
195 void MakeThrottled(WorldPacket *data); //? 0x1F
196 void MakeNotInArea(WorldPacket *data); //? 0x20
197 void MakeNotInLfg(WorldPacket *data); //? 0x21
198 void MakeVoiceOn(WorldPacket *data, uint64 guid); //+ 0x22
199 void MakeVoiceOff(WorldPacket *data, uint64 guid); //+ 0x23
201 void SendToAll(WorldPacket *data, uint64 p = 0);
202 void SendToAllButOne(WorldPacket *data, uint64 who);
203 void SendToOne(WorldPacket *data, uint64 who);
205 bool IsOn(uint64 who) const { return players.count(who) != 0; }
207 bool IsBanned(const uint64 guid) const {return banned.count(guid) != 0; }
209 bool IsFirst() const { return !(players.size() > 1); }
211 uint8 GetPlayerFlags(uint64 p) const
213 PlayerList::const_iterator p_itr = players.find(p);
214 if(p_itr == players.end())
215 return 0;
217 return p_itr->second.flags;
220 void SetModerator(uint64 p, bool set)
222 if(players[p].IsModerator() != set)
224 uint8 oldFlag = GetPlayerFlags(p);
225 players[p].SetModerator(set);
227 WorldPacket data;
228 MakeModeChange(&data, p, oldFlag);
229 SendToAll(&data);
233 void SetMute(uint64 p, bool set)
235 if(players[p].IsMuted() != set)
237 uint8 oldFlag = GetPlayerFlags(p);
238 players[p].SetMuted(set);
240 WorldPacket data;
241 MakeModeChange(&data, p, oldFlag);
242 SendToAll(&data);
246 public:
247 Channel(const std::string& name, uint32 channel_id);
248 std::string GetName() const { return m_name; }
249 uint32 GetChannelId() const { return m_channelId; }
250 bool IsConstant() const { return m_channelId != 0; }
251 bool IsAnnounce() const { return m_announce; }
252 bool IsLFG() const { return GetFlags() & CHANNEL_FLAG_LFG; }
253 std::string GetPassword() const { return m_password; }
254 void SetPassword(const std::string& npassword) { m_password = npassword; }
255 void SetAnnounce(bool nannounce) { m_announce = nannounce; }
256 uint32 GetNumPlayers() const { return players.size(); }
257 uint8 GetFlags() const { return m_flags; }
258 bool HasFlag(uint8 flag) { return m_flags & flag; }
260 void Join(uint64 p, const char *pass);
261 void Leave(uint64 p, bool send = true);
262 void KickOrBan(uint64 good, const char *badname, bool ban);
263 void Kick(uint64 good, const char *badname) { KickOrBan(good, badname, false); }
264 void Ban(uint64 good, const char *badname) { KickOrBan(good, badname, true); }
265 void UnBan(uint64 good, const char *badname);
266 void Password(uint64 p, const char *pass);
267 void SetMode(uint64 p, const char *p2n, bool mod, bool set);
268 void SetOwner(uint64 p, bool exclaim = true);
269 void SetOwner(uint64 p, const char *newname);
270 void SendWhoOwner(uint64 p);
271 void SetModerator(uint64 p, const char *newname) { SetMode(p, newname, true, true); }
272 void UnsetModerator(uint64 p, const char *newname) { SetMode(p, newname, true, false); }
273 void SetMute(uint64 p, const char *newname) { SetMode(p, newname, false, true); }
274 void UnsetMute(uint64 p, const char *newname) { SetMode(p, newname, false, false); }
275 void List(Player* p);
276 void Announce(uint64 p);
277 void Moderate(uint64 p);
278 void Say(uint64 p, const char *what, uint32 lang);
279 void Invite(uint64 p, const char *newp);
280 void Voice(uint64 guid1, uint64 guid2);
281 void DeVoice(uint64 guid1, uint64 guid2);
282 void JoinNotify(uint64 guid); // invisible notify
283 void LeaveNotify(uint64 guid); // invisible notify
285 #endif