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"
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
32 return &MaNGOS::Singleton
<AllianceChannelMgr
>::Instance();
34 return &MaNGOS::Singleton
<HordeChannelMgr
>::Instance();
39 ChannelMgr::~ChannelMgr()
41 for(ChannelMap::iterator itr
= channels
.begin();itr
!=channels
.end(); ++itr
)
47 Channel
*ChannelMgr::GetJoinChannel(std::string name
, uint32 channel_id
)
50 Utf8toWStr(name
,wname
);
53 if (channels
.find(wname
) == channels
.end())
55 Channel
*nchan
= new Channel(name
,channel_id
);
56 channels
[wname
] = nchan
;
60 return channels
[wname
];
63 Channel
*ChannelMgr::GetChannel(std::string name
, Player
*p
, bool pkt
)
66 Utf8toWStr(name
,wname
);
69 ChannelMap::const_iterator i
= channels
.find(wname
);
71 if(i
== channels
.end())
76 MakeNotOnPacket(&data
,name
);
77 p
->GetSession()->SendPacket(&data
);
86 void ChannelMgr::LeftChannel(std::string name
)
89 Utf8toWStr(name
,wname
);
92 ChannelMap::const_iterator i
= channels
.find(wname
);
94 if(i
== channels
.end())
97 Channel
* channel
= i
->second
;
99 if(channel
->GetNumPlayers() == 0 && !channel
->IsConstant())
101 channels
.erase(wname
);
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
;