2 * Copyright (C) 2005-2013 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
23 #include "ObjectGuid.h"
24 #include "WorldPacket.h"
34 CHAT_JOINED_NOTICE
= 0x00, //+ "%s joined channel.";
35 CHAT_LEFT_NOTICE
= 0x01, //+ "%s left channel.";
36 // CHAT_SUSPENDED_NOTICE = 0x01, // "%s left channel.";
37 CHAT_YOU_JOINED_NOTICE
= 0x02, //+ "Joined Channel: [%s]"; -- You joined
38 // CHAT_YOU_CHANGED_NOTICE = 0x02, // "Changed Channel: [%s]";
39 CHAT_YOU_LEFT_NOTICE
= 0x03, //+ "Left Channel: [%s]"; -- You left
40 CHAT_WRONG_PASSWORD_NOTICE
= 0x04, //+ "Wrong password for %s.";
41 CHAT_NOT_MEMBER_NOTICE
= 0x05, //+ "Not on channel %s.";
42 CHAT_NOT_MODERATOR_NOTICE
= 0x06, //+ "Not a moderator of %s.";
43 CHAT_PASSWORD_CHANGED_NOTICE
= 0x07, //+ "[%s] Password changed by %s.";
44 CHAT_OWNER_CHANGED_NOTICE
= 0x08, //+ "[%s] Owner changed to %s.";
45 CHAT_PLAYER_NOT_FOUND_NOTICE
= 0x09, //+ "[%s] Player %s was not found.";
46 CHAT_NOT_OWNER_NOTICE
= 0x0A, //+ "[%s] You are not the channel owner.";
47 CHAT_CHANNEL_OWNER_NOTICE
= 0x0B, //+ "[%s] Channel owner is %s.";
48 CHAT_MODE_CHANGE_NOTICE
= 0x0C, //?
49 CHAT_ANNOUNCEMENTS_ON_NOTICE
= 0x0D, //+ "[%s] Channel announcements enabled by %s.";
50 CHAT_ANNOUNCEMENTS_OFF_NOTICE
= 0x0E, //+ "[%s] Channel announcements disabled by %s.";
51 CHAT_MODERATION_ON_NOTICE
= 0x0F, //+ "[%s] Channel moderation enabled by %s.";
52 CHAT_MODERATION_OFF_NOTICE
= 0x10, //+ "[%s] Channel moderation disabled by %s.";
53 CHAT_MUTED_NOTICE
= 0x11, //+ "[%s] You do not have permission to speak.";
54 CHAT_PLAYER_KICKED_NOTICE
= 0x12, //? "[%s] Player %s kicked by %s.";
55 CHAT_BANNED_NOTICE
= 0x13, //+ "[%s] You are banned from that channel.";
56 CHAT_PLAYER_BANNED_NOTICE
= 0x14, //? "[%s] Player %s banned by %s.";
57 CHAT_PLAYER_UNBANNED_NOTICE
= 0x15, //? "[%s] Player %s unbanned by %s.";
58 CHAT_PLAYER_NOT_BANNED_NOTICE
= 0x16, //+ "[%s] Player %s is not banned.";
59 CHAT_PLAYER_ALREADY_MEMBER_NOTICE
= 0x17, //+ "[%s] Player %s is already on the channel.";
60 CHAT_INVITE_NOTICE
= 0x18, //+ "%2$s has invited you to join the channel '%1$s'.";
61 CHAT_INVITE_WRONG_FACTION_NOTICE
= 0x19, //+ "Target is in the wrong alliance for %s.";
62 CHAT_WRONG_FACTION_NOTICE
= 0x1A, //+ "Wrong alliance for %s.";
63 CHAT_INVALID_NAME_NOTICE
= 0x1B, //+ "Invalid channel name";
64 CHAT_NOT_MODERATED_NOTICE
= 0x1C, //+ "%s is not moderated";
65 CHAT_PLAYER_INVITED_NOTICE
= 0x1D, //+ "[%s] You invited %s to join the channel";
66 CHAT_PLAYER_INVITE_BANNED_NOTICE
= 0x1E, //+ "[%s] %s has been banned.";
67 CHAT_THROTTLED_NOTICE
= 0x1F, //+ "[%s] The number of messages that can be sent to this channel is limited, please wait to send another message.";
68 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.
69 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.
70 CHAT_VOICE_ON_NOTICE
= 0x22, //+ "[%s] Channel voice enabled by %s.";
71 CHAT_VOICE_OFF_NOTICE
= 0x23 //+ "[%s] Channel voice disabled by %s.";
79 CHANNEL_FLAG_NONE
= 0x00,
80 CHANNEL_FLAG_CUSTOM
= 0x01,
82 CHANNEL_FLAG_TRADE
= 0x04,
83 CHANNEL_FLAG_NOT_LFG
= 0x08,
84 CHANNEL_FLAG_GENERAL
= 0x10,
85 CHANNEL_FLAG_CITY
= 0x20,
86 CHANNEL_FLAG_LFG
= 0x40,
87 CHANNEL_FLAG_VOICE
= 0x80
88 // General 0x18 = 0x10 | 0x08
89 // Trade 0x3C = 0x20 | 0x10 | 0x08 | 0x04
90 // LocalDefence 0x18 = 0x10 | 0x08
91 // GuildRecruitment 0x38 = 0x20 | 0x10 | 0x08
92 // LookingForGroup 0x50 = 0x40 | 0x10
97 CHANNEL_DBC_FLAG_NONE
= 0x00000,
98 CHANNEL_DBC_FLAG_INITIAL
= 0x00001, // General, Trade, LocalDefense, LFG
99 CHANNEL_DBC_FLAG_ZONE_DEP
= 0x00002, // General, Trade, LocalDefense, GuildRecruitment
100 CHANNEL_DBC_FLAG_GLOBAL
= 0x00004, // WorldDefense
101 CHANNEL_DBC_FLAG_TRADE
= 0x00008, // Trade
102 CHANNEL_DBC_FLAG_CITY_ONLY
= 0x00010, // Trade, GuildRecruitment
103 CHANNEL_DBC_FLAG_CITY_ONLY2
= 0x00020, // Trade, GuildRecruitment
104 CHANNEL_DBC_FLAG_DEFENSE
= 0x10000, // LocalDefense, WorldDefense
105 CHANNEL_DBC_FLAG_GUILD_REQ
= 0x20000, // GuildRecruitment
106 CHANNEL_DBC_FLAG_LFG
= 0x40000 // LookingForGroup
109 enum ChannelMemberFlags
111 MEMBER_FLAG_NONE
= 0x00,
112 MEMBER_FLAG_OWNER
= 0x01,
113 MEMBER_FLAG_MODERATOR
= 0x02,
114 MEMBER_FLAG_VOICED
= 0x04,
115 MEMBER_FLAG_MUTED
= 0x08,
116 MEMBER_FLAG_CUSTOM
= 0x10,
117 MEMBER_FLAG_MIC_MUTED
= 0x20,
127 bool HasFlag(uint8 flag
) { return flags
& flag
; }
128 void SetFlag(uint8 flag
) { if (!HasFlag(flag
)) flags
|= flag
; }
129 bool IsOwner() { return flags
& MEMBER_FLAG_OWNER
; }
130 void SetOwner(bool state
)
132 if (state
) flags
|= MEMBER_FLAG_OWNER
;
133 else flags
&= ~MEMBER_FLAG_OWNER
;
135 bool IsModerator() { return flags
& MEMBER_FLAG_MODERATOR
; }
136 void SetModerator(bool state
)
138 if (state
) flags
|= MEMBER_FLAG_MODERATOR
;
139 else flags
&= ~MEMBER_FLAG_MODERATOR
;
141 bool IsMuted() { return flags
& MEMBER_FLAG_MUTED
; }
142 void SetMuted(bool state
)
144 if (state
) flags
|= MEMBER_FLAG_MUTED
;
145 else flags
&= ~MEMBER_FLAG_MUTED
;
150 Channel(const std::string
& name
, uint32 channel_id
);
151 std::string
GetName() const { return m_name
; }
152 uint32
GetChannelId() const { return m_channelId
; }
153 bool IsConstant() const { return m_channelId
!= 0; }
154 bool IsAnnounce() const { return m_announce
; }
155 bool IsLFG() const { return GetFlags() & CHANNEL_FLAG_LFG
; }
156 std::string
GetPassword() const { return m_password
; }
157 void SetPassword(const std::string
& npassword
) { m_password
= npassword
; }
158 void SetAnnounce(bool nannounce
) { m_announce
= nannounce
; }
159 uint32
GetNumPlayers() const { return m_players
.size(); }
160 uint8
GetFlags() const { return m_flags
; }
161 bool HasFlag(uint8 flag
) { return m_flags
& flag
; }
163 void Join(ObjectGuid p
, const char* pass
);
164 void Leave(ObjectGuid p
, bool send
= true);
165 void KickOrBan(ObjectGuid good
, const char* badname
, bool ban
);
166 void Kick(ObjectGuid good
, const char* badname
) { KickOrBan(good
, badname
, false); }
167 void Ban(ObjectGuid good
, const char* badname
) { KickOrBan(good
, badname
, true); }
168 void UnBan(ObjectGuid good
, const char* badname
);
169 void Password(ObjectGuid p
, const char* pass
);
170 void SetMode(ObjectGuid p
, const char* p2n
, bool mod
, bool set
);
171 void SetOwner(ObjectGuid p
, bool exclaim
= true);
172 void SetOwner(ObjectGuid p
, const char* newname
);
173 void SendWhoOwner(ObjectGuid p
);
174 void SetModerator(ObjectGuid p
, const char* newname
) { SetMode(p
, newname
, true, true); }
175 void UnsetModerator(ObjectGuid p
, const char* newname
) { SetMode(p
, newname
, true, false); }
176 void SetMute(ObjectGuid p
, const char* newname
) { SetMode(p
, newname
, false, true); }
177 void UnsetMute(ObjectGuid p
, const char* newname
) { SetMode(p
, newname
, false, false); }
178 void List(Player
* p
);
179 void Announce(ObjectGuid p
);
180 void Moderate(ObjectGuid p
);
181 void Say(ObjectGuid p
, const char* what
, uint32 lang
);
182 void Invite(ObjectGuid p
, const char* newp
);
183 void Voice(ObjectGuid guid1
, ObjectGuid guid2
);
184 void DeVoice(ObjectGuid guid1
, ObjectGuid guid2
);
185 void JoinNotify(ObjectGuid guid
); // invisible notify
186 void LeaveNotify(ObjectGuid guid
); // invisible notify
189 // initial packet data (notify type and channel name)
190 void MakeNotifyPacket(WorldPacket
* data
, uint8 notify_type
);
191 // type specific packet data
192 void MakeJoined(WorldPacket
* data
, ObjectGuid guid
); //+ 0x00
193 void MakeLeft(WorldPacket
* data
, ObjectGuid guid
); //+ 0x01
194 void MakeYouJoined(WorldPacket
* data
); //+ 0x02
195 void MakeYouLeft(WorldPacket
* data
); //+ 0x03
196 void MakeWrongPassword(WorldPacket
* data
); //? 0x04
197 void MakeNotMember(WorldPacket
* data
); //? 0x05
198 void MakeNotModerator(WorldPacket
* data
); //? 0x06
199 void MakePasswordChanged(WorldPacket
* data
, ObjectGuid guid
); //+ 0x07
200 void MakeOwnerChanged(WorldPacket
* data
, ObjectGuid guid
); //? 0x08
201 void MakePlayerNotFound(WorldPacket
* data
, const std::string
& name
); //+ 0x09
202 void MakeNotOwner(WorldPacket
* data
); //? 0x0A
203 void MakeChannelOwner(WorldPacket
* data
); //? 0x0B
204 void MakeModeChange(WorldPacket
* data
, ObjectGuid guid
, uint8 oldflags
);//+ 0x0C
205 void MakeAnnouncementsOn(WorldPacket
* data
, ObjectGuid guid
); //+ 0x0D
206 void MakeAnnouncementsOff(WorldPacket
* data
, ObjectGuid guid
); //+ 0x0E
207 void MakeModerationOn(WorldPacket
* data
, ObjectGuid guid
); //+ 0x0F
208 void MakeModerationOff(WorldPacket
* data
, ObjectGuid guid
); //+ 0x10
209 void MakeMuted(WorldPacket
* data
); //? 0x11
210 void MakePlayerKicked(WorldPacket
* data
, ObjectGuid bad
, ObjectGuid good
);//? 0x12
211 void MakeBanned(WorldPacket
* data
); //? 0x13
212 void MakePlayerBanned(WorldPacket
* data
, ObjectGuid bad
, ObjectGuid good
);//? 0x14
213 void MakePlayerUnbanned(WorldPacket
* data
, ObjectGuid bad
, ObjectGuid good
);//? 0x15
214 void MakePlayerNotBanned(WorldPacket
* data
, ObjectGuid guid
); //? 0x16
215 void MakePlayerAlreadyMember(WorldPacket
* data
, ObjectGuid guid
); //+ 0x17
216 void MakeInvite(WorldPacket
* data
, ObjectGuid guid
); //? 0x18
217 void MakeInviteWrongFaction(WorldPacket
* data
); //? 0x19
218 void MakeWrongFaction(WorldPacket
* data
); //? 0x1A
219 void MakeInvalidName(WorldPacket
* data
); //? 0x1B
220 void MakeNotModerated(WorldPacket
* data
); //? 0x1C
221 void MakePlayerInvited(WorldPacket
* data
, const std::string
& name
); //+ 0x1D
222 void MakePlayerInviteBanned(WorldPacket
* data
, ObjectGuid guid
); //? 0x1E
223 void MakeThrottled(WorldPacket
* data
); //? 0x1F
224 void MakeNotInArea(WorldPacket
* data
); //? 0x20
225 void MakeNotInLfg(WorldPacket
* data
); //? 0x21
226 void MakeVoiceOn(WorldPacket
* data
, ObjectGuid guid
); //+ 0x22
227 void MakeVoiceOff(WorldPacket
* data
, ObjectGuid guid
); //+ 0x23
229 void SendToAll(WorldPacket
* data
, ObjectGuid p
= ObjectGuid());
230 void SendToOne(WorldPacket
* data
, ObjectGuid who
);
232 bool IsOn(ObjectGuid who
) const { return m_players
.find(who
) != m_players
.end(); }
233 bool IsBanned(ObjectGuid guid
) const { return m_banned
.find(guid
) != m_banned
.end(); }
235 uint8
GetPlayerFlags(ObjectGuid p
) const
237 PlayerList::const_iterator p_itr
= m_players
.find(p
);
238 if (p_itr
== m_players
.end())
241 return p_itr
->second
.flags
;
244 void SetModerator(ObjectGuid p
, bool set
)
246 if (m_players
[p
].IsModerator() != set
)
248 uint8 oldFlag
= GetPlayerFlags(p
);
249 m_players
[p
].SetModerator(set
);
252 MakeModeChange(&data
, p
, oldFlag
);
257 void SetMute(ObjectGuid p
, bool set
)
259 if (m_players
[p
].IsMuted() != set
)
261 uint8 oldFlag
= GetPlayerFlags(p
);
262 m_players
[p
].SetMuted(set
);
265 MakeModeChange(&data
, p
, oldFlag
);
274 std::string m_password
;
277 ObjectGuid m_ownerGuid
;
279 typedef std::map
<ObjectGuid
, PlayerInfo
> PlayerList
;
280 PlayerList m_players
;