OregonCore  revision 3611e8a-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  channels.clear();
40  }
41  Channel* GetJoinChannel(const 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(const 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(const 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, const std::string& name)
82  {
83  data->Initialize(SMSG_CHANNEL_NOTIFY, (1 + 10)); // we guess size
84  (*data) << (uint8)0x05 << name;
85  }
86 };
87 
88 class AllianceChannelMgr : public ChannelMgr {};
89 class HordeChannelMgr : public ChannelMgr {};
90 
92 {
94  //For Test,No Seprate Faction
96 
97  if (team == ALLIANCE)
99  if (team == HORDE)
101  return NULL;
102 }
103 #endif
104 
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:81
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:41
Channel * GetChannel(const std::string &name, Player *p)
Definition: ChannelMgr.h:50
std::map< std::string, Channel * > ChannelMap
Definition: ChannelMgr.h:33
WorldSession * GetSession() const
Definition: Player.h:1959
#define sWorld
Definition: World.h:860
ACE_UINT32 uint32
Definition: Define.h:71
ChannelMap channels
Definition: ChannelMgr.h:80
Definition: Player.h:922
ChannelMgr * channelMgr(uint32 team)
Definition: ChannelMgr.h:91
void LeftChannel(const std::string &name)
Definition: ChannelMgr.h:64