OregonCore  revision 71a6c59-git
Your Favourite TBC server
ChannelMgr.h
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef OREGONCORE_CHANNELMGR_H
19 #define OREGONCORE_CHANNELMGR_H
20 
21 #include "Channel.h"
22 #include "Policies/Singleton.h"
23 #include "World.h"
24 
25 #include <map>
26 #include <string>
27 
28 #define MAX_CHANNEL_PASS_STR 31
29 
31 {
32  public:
33  typedef std::map<std::string, Channel*> ChannelMap;
36  {
37  for (ChannelMap::iterator itr = channels.begin(); itr != channels.end(); ++itr)
38  delete itr->second;
39 
40  channels.clear();
41  }
42  Channel* GetJoinChannel(const std::string& name, uint32 channel_id)
43  {
44  if (channels.count(name) == 0)
45  {
46  Channel* nchan = new Channel(name, channel_id);
47  channels[name] = nchan;
48  }
49  return channels[name];
50  }
51  Channel* GetChannel(const std::string& name, Player* p)
52  {
53  ChannelMap::const_iterator i = channels.find(name);
54 
55  if (i == channels.end())
56  {
57  WorldPacket data;
58  MakeNotOnPacket(&data, name);
59  p->GetSession()->SendPacket(&data);
60  return NULL;
61  }
62  else
63  return i->second;
64  }
65  void LeftChannel(const std::string& name)
66  {
67  ChannelMap::const_iterator i = channels.find(name);
68 
69  if (i == channels.end())
70  return;
71 
72  Channel* channel = i->second;
73 
74  if (channel->GetNumPlayers() == 0 && !channel->IsConstant())
75  {
76  channels.erase(name);
77  delete channel;
78  }
79  }
80  private:
81  ChannelMap channels;
82  void MakeNotOnPacket(WorldPacket* data, const std::string& name)
83  {
84  data->Initialize(SMSG_CHANNEL_NOTIFY, 1 + name.size());
85  (*data) << uint8(CHAT_NOT_MEMBER_NOTICE) << name;
86  }
87 };
88 
89 class AllianceChannelMgr : public ChannelMgr {};
90 class HordeChannelMgr : public ChannelMgr {};
91 
93 {
95  //For Test,No Seprate Faction
97 
98  if (team == ALLIANCE)
100  if (team == HORDE)
102  return NULL;
103 }
104 #endif
105 
void Initialize(uint16 opcode, size_t newres=200)
Definition: WorldPacket.h:37
void SendPacket(WorldPacket const *packet)
static T & Instance()
Definition: Singleton.h:71
void MakeNotOnPacket(WorldPacket *data, const std::string &name)
Definition: ChannelMgr.h:82
ACE_UINT8 uint8
Definition: Define.h:73
uint32 GetNumPlayers() const
Definition: Channel.h:298
bool IsConstant() const
Definition: Channel.h:274
Channel * GetJoinChannel(const std::string &name, uint32 channel_id)
Definition: ChannelMgr.h:42
Channel * GetChannel(const std::string &name, Player *p)
Definition: ChannelMgr.h:51
std::map< std::string, Channel * > ChannelMap
Definition: ChannelMgr.h:33
WorldSession * GetSession() const
Definition: Player.h:1944
#define sWorld
Definition: World.h:860
ACE_UINT32 uint32
Definition: Define.h:71
ChannelMap channels
Definition: ChannelMgr.h:81
Definition: Player.h:922
ChannelMgr * channelMgr(uint32 team)
Definition: ChannelMgr.h:92
void LeftChannel(const std::string &name)
Definition: ChannelMgr.h:65