[9529] Make Player::IsValidPos const
[getmangos.git] / src / game / ChannelMgr.cpp
bloba873f4a54894d67d3e954eca018282e7f377d84c
1 /*
2 * Copyright (C) 2005-2010 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_BOOL_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 std::wstring wname;
50 Utf8toWStr(name,wname);
51 wstrToLower(wname);
53 if (channels.find(wname) == channels.end())
55 Channel *nchan = new Channel(name,channel_id);
56 channels[wname] = nchan;
57 return nchan;
60 return channels[wname];
63 Channel *ChannelMgr::GetChannel(std::string name, Player *p, bool pkt)
65 std::wstring wname;
66 Utf8toWStr(name,wname);
67 wstrToLower(wname);
69 ChannelMap::const_iterator i = channels.find(wname);
71 if(i == channels.end())
73 if(pkt)
75 WorldPacket data;
76 MakeNotOnPacket(&data,name);
77 p->GetSession()->SendPacket(&data);
80 return NULL;
82 else
83 return i->second;
86 void ChannelMgr::LeftChannel(std::string name)
88 std::wstring wname;
89 Utf8toWStr(name,wname);
90 wstrToLower(wname);
92 ChannelMap::const_iterator i = channels.find(wname);
94 if(i == channels.end())
95 return;
97 Channel* channel = i->second;
99 if(channel->GetNumPlayers() == 0 && !channel->IsConstant())
101 channels.erase(wname);
102 delete channel;
106 void ChannelMgr::MakeNotOnPacket(WorldPacket *data, std::string name)
108 data->Initialize(SMSG_CHANNEL_NOTIFY, (1+10)); // we guess size
109 (*data) << (uint8)0x05 << name;