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