[2] | 1 | /* |
---|
[44] | 2 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
[2] | 3 | * |
---|
[44] | 4 | * Thanks to the original authors: MaNGOS <http://www.mangosproject.org/> |
---|
| 5 | * |
---|
[2] | 6 | * This program is free software; you can redistribute it and/or modify |
---|
| 7 | * it under the terms of the GNU General Public License as published by |
---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 9 | * (at your option) any later version. |
---|
| 10 | * |
---|
| 11 | * This program is distributed in the hope that it will be useful, |
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
[44] | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
[2] | 14 | * GNU General Public License for more details. |
---|
| 15 | * |
---|
| 16 | * You should have received a copy of the GNU General Public License |
---|
| 17 | * along with this program; if not, write to the Free Software |
---|
[44] | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
[2] | 19 | */ |
---|
| 20 | |
---|
| 21 | #ifndef _CHANNEL_H |
---|
| 22 | #define _CHANNEL_H |
---|
| 23 | |
---|
| 24 | #include "Common.h" |
---|
| 25 | #include "WorldPacket.h" |
---|
| 26 | #include "WorldSession.h" |
---|
| 27 | #include "Opcodes.h" |
---|
| 28 | #include "Player.h" |
---|
| 29 | |
---|
| 30 | #include <list> |
---|
| 31 | #include <map> |
---|
| 32 | #include <string> |
---|
| 33 | |
---|
| 34 | class Channel |
---|
| 35 | { |
---|
| 36 | enum ChatNotify |
---|
| 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."; |
---|
| 52 | CHAT_MODE_CHANGE_NOTICE = 0x0C, //? |
---|
| 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 banned from that channel."; |
---|
| 60 | CHAT_PLAYER_BANNED_NOTICE = 0x14, //? "[%s] Player %s banned 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 banned."; |
---|
| 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 banned."; |
---|
| 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."; |
---|
| 76 | }; |
---|
| 77 | |
---|
| 78 | enum ChannelFlags |
---|
| 79 | { |
---|
| 80 | CHANNEL_FLAG_NONE = 0x00, |
---|
| 81 | CHANNEL_FLAG_CUSTOM = 0x01, |
---|
| 82 | // 0x02 |
---|
| 83 | CHANNEL_FLAG_TRADE = 0x04, |
---|
| 84 | CHANNEL_FLAG_NOT_LFG = 0x08, |
---|
| 85 | CHANNEL_FLAG_GENERAL = 0x10, |
---|
| 86 | CHANNEL_FLAG_CITY = 0x20, |
---|
| 87 | CHANNEL_FLAG_LFG = 0x40, |
---|
| 88 | CHANNEL_FLAG_VOICE = 0x80 |
---|
| 89 | // General 0x18 = 0x10 | 0x08 |
---|
| 90 | // Trade 0x3C = 0x20 | 0x10 | 0x08 | 0x04 |
---|
| 91 | // LocalDefence 0x18 = 0x10 | 0x08 |
---|
| 92 | // GuildRecruitment 0x38 = 0x20 | 0x10 | 0x08 |
---|
| 93 | // LookingForGroup 0x50 = 0x40 | 0x10 |
---|
| 94 | }; |
---|
| 95 | |
---|
| 96 | enum ChannelDBCFlags |
---|
| 97 | { |
---|
| 98 | CHANNEL_DBC_FLAG_NONE = 0x00000, |
---|
| 99 | CHANNEL_DBC_FLAG_INITIAL = 0x00001, // General, Trade, LocalDefense, LFG |
---|
| 100 | CHANNEL_DBC_FLAG_ZONE_DEP = 0x00002, // General, Trade, LocalDefense, GuildRecruitment |
---|
| 101 | CHANNEL_DBC_FLAG_GLOBAL = 0x00004, // WorldDefense |
---|
| 102 | CHANNEL_DBC_FLAG_TRADE = 0x00008, // Trade |
---|
| 103 | CHANNEL_DBC_FLAG_CITY_ONLY = 0x00010, // Trade, GuildRecruitment |
---|
| 104 | CHANNEL_DBC_FLAG_CITY_ONLY2 = 0x00020, // Trade, GuildRecruitment |
---|
| 105 | CHANNEL_DBC_FLAG_DEFENSE = 0x10000, // LocalDefense, WorldDefense |
---|
| 106 | CHANNEL_DBC_FLAG_GUILD_REQ = 0x20000, // GuildRecruitment |
---|
| 107 | CHANNEL_DBC_FLAG_LFG = 0x40000 // LookingForGroup |
---|
| 108 | }; |
---|
| 109 | |
---|
| 110 | enum ChannelMemberFlags |
---|
| 111 | { |
---|
| 112 | MEMBER_FLAG_NONE = 0x00, |
---|
| 113 | MEMBER_FLAG_OWNER = 0x01, |
---|
| 114 | MEMBER_FLAG_MODERATOR = 0x02, |
---|
| 115 | MEMBER_FLAG_VOICED = 0x04, |
---|
| 116 | MEMBER_FLAG_MUTED = 0x08, |
---|
| 117 | MEMBER_FLAG_CUSTOM = 0x10, |
---|
| 118 | MEMBER_FLAG_MIC_MUTED = 0x20, |
---|
| 119 | // 0x40 |
---|
| 120 | // 0x80 |
---|
| 121 | }; |
---|
| 122 | |
---|
| 123 | struct PlayerInfo |
---|
| 124 | { |
---|
| 125 | uint64 player; |
---|
| 126 | uint8 flags; |
---|
| 127 | |
---|
| 128 | bool HasFlag(uint8 flag) { return flags & flag; } |
---|
| 129 | void SetFlag(uint8 flag) { if(!HasFlag(flag)) flags |= flag; } |
---|
| 130 | bool IsOwner() { return flags & MEMBER_FLAG_OWNER; } |
---|
| 131 | void SetOwner(bool state) |
---|
| 132 | { |
---|
| 133 | if(state) flags |= MEMBER_FLAG_OWNER; |
---|
| 134 | else flags &= ~MEMBER_FLAG_OWNER; |
---|
| 135 | } |
---|
| 136 | bool IsModerator() { return flags & MEMBER_FLAG_MODERATOR; } |
---|
| 137 | void SetModerator(bool state) |
---|
| 138 | { |
---|
| 139 | if(state) flags |= MEMBER_FLAG_MODERATOR; |
---|
| 140 | else flags &= ~MEMBER_FLAG_MODERATOR; |
---|
| 141 | } |
---|
| 142 | bool IsMuted() { return flags & MEMBER_FLAG_MUTED; } |
---|
| 143 | void SetMuted(bool state) |
---|
| 144 | { |
---|
| 145 | if(state) flags |= MEMBER_FLAG_MUTED; |
---|
| 146 | else flags &= ~MEMBER_FLAG_MUTED; |
---|
| 147 | } |
---|
| 148 | }; |
---|
| 149 | |
---|
| 150 | typedef std::map<uint64, PlayerInfo> PlayerList; |
---|
| 151 | PlayerList players; |
---|
| 152 | typedef std::list<uint64> BannedList; |
---|
| 153 | BannedList banned; |
---|
| 154 | bool m_announce; |
---|
| 155 | bool m_moderate; |
---|
| 156 | std::string m_name; |
---|
| 157 | std::string m_password; |
---|
| 158 | uint8 m_flags; |
---|
| 159 | uint32 m_channelId; |
---|
| 160 | uint64 m_ownerGUID; |
---|
| 161 | |
---|
| 162 | private: |
---|
| 163 | // initial packet data (notify type and channel name) |
---|
| 164 | void MakeNotifyPacket(WorldPacket *data, uint8 notify_type); |
---|
| 165 | // type specific packet data |
---|
| 166 | void MakeJoined(WorldPacket *data, uint64 guid); //+ 0x00 |
---|
| 167 | void MakeLeft(WorldPacket *data, uint64 guid); //+ 0x01 |
---|
| 168 | void MakeYouJoined(WorldPacket *data); //+ 0x02 |
---|
| 169 | void MakeYouLeft(WorldPacket *data); //+ 0x03 |
---|
| 170 | void MakeWrongPassword(WorldPacket *data); //? 0x04 |
---|
| 171 | void MakeNotMember(WorldPacket *data); //? 0x05 |
---|
| 172 | void MakeNotModerator(WorldPacket *data); //? 0x06 |
---|
| 173 | void MakePasswordChanged(WorldPacket *data, uint64 guid); //+ 0x07 |
---|
| 174 | void MakeOwnerChanged(WorldPacket *data, uint64 guid); //? 0x08 |
---|
| 175 | void MakePlayerNotFound(WorldPacket *data, std::string name); //+ 0x09 |
---|
| 176 | void MakeNotOwner(WorldPacket *data); //? 0x0A |
---|
| 177 | void MakeChannelOwner(WorldPacket *data); //? 0x0B |
---|
| 178 | void MakeModeChange(WorldPacket *data, uint64 guid, uint8 oldflags); //+ 0x0C |
---|
| 179 | void MakeAnnouncementsOn(WorldPacket *data, uint64 guid); //+ 0x0D |
---|
| 180 | void MakeAnnouncementsOff(WorldPacket *data, uint64 guid); //+ 0x0E |
---|
| 181 | void MakeModerationOn(WorldPacket *data, uint64 guid); //+ 0x0F |
---|
| 182 | void MakeModerationOff(WorldPacket *data, uint64 guid); //+ 0x10 |
---|
| 183 | void MakeMuted(WorldPacket *data); //? 0x11 |
---|
| 184 | void MakePlayerKicked(WorldPacket *data, uint64 bad, uint64 good); //? 0x12 |
---|
| 185 | void MakeBanned(WorldPacket *data); //? 0x13 |
---|
| 186 | void MakePlayerBanned(WorldPacket *data, uint64 bad, uint64 good); //? 0x14 |
---|
| 187 | void MakePlayerUnbanned(WorldPacket *data, uint64 bad, uint64 good); //? 0x15 |
---|
| 188 | void MakePlayerNotBanned(WorldPacket *data, uint64 guid); //? 0x16 |
---|
| 189 | void MakePlayerAlreadyMember(WorldPacket *data, uint64 guid); //+ 0x17 |
---|
| 190 | void MakeInvite(WorldPacket *data, uint64 guid); //? 0x18 |
---|
| 191 | void MakeInviteWrongFaction(WorldPacket *data); //? 0x19 |
---|
| 192 | void MakeWrongFaction(WorldPacket *data); //? 0x1A |
---|
| 193 | void MakeInvalidName(WorldPacket *data); //? 0x1B |
---|
| 194 | void MakeNotModerated(WorldPacket *data); //? 0x1C |
---|
| 195 | void MakePlayerInvited(WorldPacket *data, uint64 guid); //+ 0x1D |
---|
| 196 | void MakePlayerInviteBanned(WorldPacket *data, uint64 guid); //? 0x1E |
---|
| 197 | void MakeThrottled(WorldPacket *data); //? 0x1F |
---|
| 198 | void MakeNotInArea(WorldPacket *data); //? 0x20 |
---|
| 199 | void MakeNotInLfg(WorldPacket *data); //? 0x21 |
---|
| 200 | void MakeVoiceOn(WorldPacket *data, uint64 guid); //+ 0x22 |
---|
| 201 | void MakeVoiceOff(WorldPacket *data, uint64 guid); //+ 0x23 |
---|
| 202 | |
---|
| 203 | void SendToAll(WorldPacket *data, uint64 p = 0); |
---|
| 204 | void SendToAllButOne(WorldPacket *data, uint64 who); |
---|
| 205 | void SendToOne(WorldPacket *data, uint64 who); |
---|
| 206 | |
---|
| 207 | bool IsOn(uint64 who) const { return players.count(who) > 0; } |
---|
| 208 | |
---|
| 209 | bool IsBanned(const uint64 guid) const |
---|
| 210 | { |
---|
| 211 | for(BannedList::const_iterator i = banned.begin(); i != banned.end(); ++i) |
---|
| 212 | if(*i == guid) |
---|
| 213 | return true; |
---|
| 214 | return false; |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | bool IsFirst() const { return !(players.size() > 1); } |
---|
| 218 | |
---|
| 219 | uint8 GetPlayerFlags(uint64 p) const |
---|
| 220 | { |
---|
| 221 | PlayerList::const_iterator p_itr = players.find(p); |
---|
| 222 | if(p_itr == players.end()) |
---|
| 223 | return 0; |
---|
| 224 | |
---|
| 225 | return p_itr->second.flags; |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | void SetModerator(uint64 p, bool set) |
---|
| 229 | { |
---|
| 230 | if(players[p].IsModerator() != set) |
---|
| 231 | { |
---|
| 232 | uint8 oldFlag = GetPlayerFlags(p); |
---|
| 233 | players[p].SetModerator(set); |
---|
| 234 | |
---|
| 235 | WorldPacket data; |
---|
| 236 | MakeModeChange(&data, p, oldFlag); |
---|
| 237 | SendToAll(&data); |
---|
| 238 | } |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | void SetMute(uint64 p, bool set) |
---|
| 242 | { |
---|
| 243 | if(players[p].IsMuted() != set) |
---|
| 244 | { |
---|
| 245 | uint8 oldFlag = GetPlayerFlags(p); |
---|
| 246 | players[p].SetMuted(set); |
---|
| 247 | |
---|
| 248 | WorldPacket data; |
---|
| 249 | MakeModeChange(&data, p, oldFlag); |
---|
| 250 | SendToAll(&data); |
---|
| 251 | } |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | public: |
---|
| 255 | Channel(std::string name, uint32 channel_id); |
---|
| 256 | std::string GetName() const { return m_name; } |
---|
| 257 | uint32 GetChannelId() const { return m_channelId; } |
---|
| 258 | bool IsConstant() const { return m_channelId != 0; } |
---|
| 259 | bool IsAnnounce() const { return m_announce; } |
---|
| 260 | bool IsLFG() const { return GetFlags() & CHANNEL_FLAG_LFG; } |
---|
| 261 | std::string GetPassword() const { return m_password; } |
---|
| 262 | void SetPassword(std::string npassword) { m_password = npassword; } |
---|
| 263 | void SetAnnounce(bool nannounce) { m_announce = nannounce; } |
---|
| 264 | uint32 GetNumPlayers() const { return players.size(); } |
---|
| 265 | uint8 GetFlags() const { return m_flags; } |
---|
| 266 | bool HasFlag(uint8 flag) { return m_flags & flag; } |
---|
| 267 | |
---|
| 268 | void Join(uint64 p, const char *pass); |
---|
| 269 | void Leave(uint64 p, bool send = true); |
---|
| 270 | void KickOrBan(uint64 good, const char *badname, bool ban); |
---|
| 271 | void Kick(uint64 good, const char *badname) { KickOrBan(good, badname, false); } |
---|
| 272 | void Ban(uint64 good, const char *badname) { KickOrBan(good, badname, true); } |
---|
| 273 | void UnBan(uint64 good, const char *badname); |
---|
| 274 | void Password(uint64 p, const char *pass); |
---|
| 275 | void SetMode(uint64 p, const char *p2n, bool mod, bool set); |
---|
| 276 | void SetOwner(uint64 p, bool exclaim = true); |
---|
| 277 | void SetOwner(uint64 p, const char *newname); |
---|
| 278 | void SendWhoOwner(uint64 p); |
---|
| 279 | void SetModerator(uint64 p, const char *newname) { SetMode(p, newname, true, true); } |
---|
| 280 | void UnsetModerator(uint64 p, const char *newname) { SetMode(p, newname, true, false); } |
---|
| 281 | void SetMute(uint64 p, const char *newname) { SetMode(p, newname, false, true); } |
---|
| 282 | void UnsetMute(uint64 p, const char *newname) { SetMode(p, newname, false, false); } |
---|
| 283 | void List(Player* p); |
---|
| 284 | void Announce(uint64 p); |
---|
| 285 | void Moderate(uint64 p); |
---|
| 286 | void Say(uint64 p, const char *what, uint32 lang); |
---|
| 287 | void Invite(uint64 p, const char *newp); |
---|
| 288 | void Voice(uint64 guid1, uint64 guid2); |
---|
| 289 | void DeVoice(uint64 guid1, uint64 guid2); |
---|
| 290 | void JoinNotify(uint64 guid); // invisible notify |
---|
| 291 | void LeaveNotify(uint64 guid); // invisible notify |
---|
| 292 | }; |
---|
| 293 | #endif |
---|