root/trunk/src/game/ChannelMgr.h @ 250

Revision 209, 3.2 kB (checked in by yumileroy, 17 years ago)

[svn] Fix some typos.

Original author: megamage
Date: 2008-11-10 17:19:35-06:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
5 *
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
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
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
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20#ifndef TRINITYCORE_CHANNELMGR_H
21#define TRINITYCORE_CHANNELMGR_H
22
23#include "Channel.h"
24#include "Policies/Singleton.h"
25#include "World.h"
26
27#include <map>
28#include <string>
29
30class ChannelMgr
31{
32    public:
33        typedef std::map<std::string,Channel *> ChannelMap;
34        ChannelMgr() {}
35        ~ChannelMgr()
36        {
37            for(ChannelMap::iterator itr = channels.begin();itr!=channels.end(); ++itr)
38                delete itr->second;
39            channels.clear();
40        }
41        Channel *GetJoinChannel(std::string name, uint32 channel_id)
42        {
43            if(channels.count(name) == 0)
44            {
45                Channel *nchan = new Channel(name,channel_id);
46                channels[name] = nchan;
47            }
48            return channels[name];
49        }
50        Channel *GetChannel(std::string name, Player *p)
51        {
52            ChannelMap::const_iterator i = channels.find(name);
53
54            if(i == channels.end())
55            {
56                WorldPacket data;
57                MakeNotOnPacket(&data,name);
58                p->GetSession()->SendPacket(&data);
59                return NULL;
60            }
61            else
62                return i->second;
63        }
64        void LeftChannel(std::string name)
65        {
66            ChannelMap::const_iterator i = channels.find(name);
67
68            if(i == channels.end())
69                return;
70
71            Channel* channel = i->second;
72
73            if(channel->GetNumPlayers() == 0 && !channel->IsConstant())
74            {
75                channels.erase(name);
76                delete channel;
77            }
78        }
79    private:
80        ChannelMap channels;
81        void MakeNotOnPacket(WorldPacket *data, std::string name)
82        {
83            data->Initialize(SMSG_CHANNEL_NOTIFY, (1+10));  // we guess size
84            (*data) << (uint8)0x05 << name;
85        }
86};
87
88class AllianceChannelMgr : public ChannelMgr {};
89class HordeChannelMgr    : public ChannelMgr {};
90
91inline ChannelMgr* channelMgr(uint32 team)
92{
93    if (sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHANNEL))
94                                                            //For Test,No Seprate Faction
95        return &Trinity::Singleton<AllianceChannelMgr>::Instance();
96
97    if(team==ALLIANCE)
98        return &Trinity::Singleton<AllianceChannelMgr>::Instance();
99    if(team==HORDE)
100        return &Trinity::Singleton<HordeChannelMgr>::Instance();
101    return NULL;
102}
103#endif
Note: See TracBrowser for help on using the browser.