[8483] Implement glyph 43361.
[getmangos.git] / src / game / ChannelMgr.cpp
blobe3b54d3463951bdfb323e2bd0a4a3ca6ea251d7f
1 /*
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
19 #include "ChannelMgr.h"
20 #include "Policies/SingletonImp.h"
21 #include "World.h"
23 INSTANTIATE_SINGLETON_1( AllianceChannelMgr );
24 INSTANTIATE_SINGLETON_1( HordeChannelMgr );
26 ChannelMgr* channelMgr(uint32 team)
28 if (sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHANNEL))
29 return &MaNGOS::Singleton<AllianceChannelMgr>::Instance(); // cross-faction
31 if(team == ALLIANCE)
32 return &MaNGOS::Singleton<AllianceChannelMgr>::Instance();
33 if(team == HORDE)
34 return &MaNGOS::Singleton<HordeChannelMgr>::Instance();
36 return NULL;
39 ChannelMgr::~ChannelMgr()
41 for(ChannelMap::iterator itr = channels.begin();itr!=channels.end(); ++itr)
42 delete itr->second;
44 channels.clear();
47 Channel *ChannelMgr::GetJoinChannel(std::string name, uint32 channel_id)
49 if (channels.find(name) == channels.end())
51 Channel *nchan = new Channel(name,channel_id);
52 channels[name] = nchan;
55 return channels[name];
58 Channel *ChannelMgr::GetChannel(std::string name, Player *p, bool pkt)
60 ChannelMap::const_iterator i = channels.find(name);
62 if(i == channels.end())
64 if(pkt)
66 WorldPacket data;
67 MakeNotOnPacket(&data,name);
68 p->GetSession()->SendPacket(&data);
71 return NULL;
73 else
74 return i->second;
77 void ChannelMgr::LeftChannel(std::string name)
79 ChannelMap::const_iterator i = channels.find(name);
81 if(i == channels.end())
82 return;
84 Channel* channel = i->second;
86 if(channel->GetNumPlayers() == 0 && !channel->IsConstant())
88 channels.erase(name);
89 delete channel;
93 void ChannelMgr::MakeNotOnPacket(WorldPacket *data, std::string name)
95 data->Initialize(SMSG_CHANNEL_NOTIFY, (1+10)); // we guess size
96 (*data) << (uint8)0x05 << name;