root/trunk/src/game/Channel.h @ 28

Revision 2, 15.0 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
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.
8 *
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.
13 *
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
17 */
18
19#ifndef _CHANNEL_H
20#define _CHANNEL_H
21
22#include "Common.h"
23#include "WorldPacket.h"
24#include "WorldSession.h"
25#include "Opcodes.h"
26#include "Player.h"
27
28#include <list>
29#include <map>
30#include <string>
31
32class Channel
33{
34    enum ChatNotify
35    {
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.";
74    };
75
76    enum ChannelFlags
77    {
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
92    };
93
94    enum ChannelDBCFlags
95    {
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
106    };
107
108    enum ChannelMemberFlags
109    {
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
119    };
120
121    struct PlayerInfo
122    {
123        uint64 player;
124        uint8 flags;
125
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)
130        {
131            if(state) flags |= MEMBER_FLAG_OWNER;
132            else flags &= ~MEMBER_FLAG_OWNER;
133        }
134        bool IsModerator() { return flags & MEMBER_FLAG_MODERATOR; }
135        void SetModerator(bool state)
136        {
137            if(state) flags |= MEMBER_FLAG_MODERATOR;
138            else flags &= ~MEMBER_FLAG_MODERATOR;
139        }
140        bool IsMuted() { return flags & MEMBER_FLAG_MUTED; }
141        void SetMuted(bool state)
142        {
143            if(state) flags |= MEMBER_FLAG_MUTED;
144            else flags &= ~MEMBER_FLAG_MUTED;
145        }
146    };
147
148    typedef     std::map<uint64, PlayerInfo> PlayerList;
149    PlayerList  players;
150    typedef     std::list<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;
159
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, 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, uint64 guid);                 //+ 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
200
201        void SendToAll(WorldPacket *data, uint64 p = 0);
202        void SendToAllButOne(WorldPacket *data, uint64 who);
203        void SendToOne(WorldPacket *data, uint64 who);
204
205        bool IsOn(uint64 who) const { return players.count(who) > 0; }
206
207        bool IsBanned(const uint64 guid) const
208        {
209            for(BannedList::const_iterator i = banned.begin(); i != banned.end(); ++i)
210                if(*i == guid)
211                    return true;
212            return false;
213        }
214
215        bool IsFirst() const { return !(players.size() > 1); }
216
217        uint8 GetPlayerFlags(uint64 p) const
218        {
219            PlayerList::const_iterator p_itr = players.find(p);
220            if(p_itr == players.end())
221                return 0;
222
223            return p_itr->second.flags;
224        }
225
226        void SetModerator(uint64 p, bool set)
227        {
228            if(players[p].IsModerator() != set)
229            {
230                uint8 oldFlag = GetPlayerFlags(p);
231                players[p].SetModerator(set);
232
233                WorldPacket data;
234                MakeModeChange(&data, p, oldFlag);
235                SendToAll(&data);
236            }
237        }
238
239        void SetMute(uint64 p, bool set)
240        {
241            if(players[p].IsMuted() != set)
242            {
243                uint8 oldFlag = GetPlayerFlags(p);
244                players[p].SetMuted(set);
245
246                WorldPacket data;
247                MakeModeChange(&data, p, oldFlag);
248                SendToAll(&data);
249            }
250        }
251
252    public:
253        Channel(std::string name, uint32 channel_id);
254        std::string GetName() const { return m_name; }
255        uint32 GetChannelId() const { return m_channelId; }
256        bool IsConstant() const { return m_channelId != 0; }
257        bool IsAnnounce() const { return m_announce; }
258        bool IsLFG() const { return GetFlags() & CHANNEL_FLAG_LFG; }
259        std::string GetPassword() const { return m_password; }
260        void SetPassword(std::string npassword) { m_password = npassword; }
261        void SetAnnounce(bool nannounce) { m_announce = nannounce; }
262        uint32 GetNumPlayers() const { return players.size(); }
263        uint8 GetFlags() const { return m_flags; }
264        bool HasFlag(uint8 flag) { return m_flags & flag; }
265
266        void Join(uint64 p, const char *pass);
267        void Leave(uint64 p, bool send = true);
268        void KickOrBan(uint64 good, const char *badname, bool ban);
269        void Kick(uint64 good, const char *badname) { KickOrBan(good, badname, false); }
270        void Ban(uint64 good, const char *badname) { KickOrBan(good, badname, true); }
271        void UnBan(uint64 good, const char *badname);
272        void Password(uint64 p, const char *pass);
273        void SetMode(uint64 p, const char *p2n, bool mod, bool set);
274        void SetOwner(uint64 p, bool exclaim = true);
275        void SetOwner(uint64 p, const char *newname);
276        void SendWhoOwner(uint64 p);
277        void SetModerator(uint64 p, const char *newname) { SetMode(p, newname, true, true); }
278        void UnsetModerator(uint64 p, const char *newname) { SetMode(p, newname, true, false); }
279        void SetMute(uint64 p, const char *newname) { SetMode(p, newname, false, true); }
280        void UnsetMute(uint64 p, const char *newname) { SetMode(p, newname, false, false); }
281        void List(Player* p);
282        void Announce(uint64 p);
283        void Moderate(uint64 p);
284        void Say(uint64 p, const char *what, uint32 lang);
285        void Invite(uint64 p, const char *newp);
286        void Voice(uint64 guid1, uint64 guid2);
287        void DeVoice(uint64 guid1, uint64 guid2);
288        void JoinNotify(uint64 guid);                                           // invisible notify
289        void LeaveNotify(uint64 guid);                                          // invisible notify
290};
291#endif
Note: See TracBrowser for help on using the browser.