Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
ChannelMgr.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#include "ChannelMgr.h"
7#include "Player.h"
8#include "World.h"
9#include "WorldSession.h"
10
12{
13 for (ChannelMap::iterator itr = channels.begin(); itr != channels.end(); ++itr)
14 delete itr->second;
15}
16
30
31Channel* ChannelMgr::GetJoinChannel(std::string const& name, uint32 channelId)
32{
33 std::wstring wname;
34 if (!Utf8toWStr(name, wname))
35 return NULL;
36
37 wstrToLower(wname);
38
39 ChannelMap::const_iterator i = channels.find(wname);
40
41 if (i == channels.end())
42 {
43 Channel* nchan = new Channel(name, channelId, team);
44 channels[wname] = nchan;
45 return nchan;
46 }
47
48 return i->second;
49}
50
51Channel* ChannelMgr::GetChannel(std::string const& name, Player* player, bool pkt)
52{
53 std::wstring wname;
54 if (!Utf8toWStr(name, wname))
55 return NULL;
56
57 wstrToLower(wname);
58
59 ChannelMap::const_iterator i = channels.find(wname);
60
61 if (i == channels.end())
62 {
63 if (pkt)
64 {
65 WorldPacket data;
66 MakeNotOnPacket(&data, name);
67 player->GetSession()->SendPacket(&data);
68 }
69
70 return NULL;
71 }
72
73 return i->second;
74}
75
76void ChannelMgr::LeftChannel(std::string const& name)
77{
78 std::wstring wname;
79 if (!Utf8toWStr(name, wname))
80 return;
81
82 wstrToLower(wname);
83
84 ChannelMap::const_iterator i = channels.find(wname);
85
86 if (i == channels.end())
87 return;
88
89 Channel* channel = i->second;
90
91 if (!channel->GetNumPlayers() && !channel->IsConstant())
92 {
93 channels.erase(wname);
94 delete channel;
95 }
96}
97
98void ChannelMgr::MakeNotOnPacket(WorldPacket* data, std::string const& name)
99{
100 data->Initialize(SMSG_CHANNEL_NOTIFY, 1 + name.size());
101 (*data) << uint8(5) << name;
102}
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
@ ALLIANCE
@ HORDE
bool Utf8toWStr(char const *utf8str, size_t csize, wchar_t *wstr, size_t &wsize)
Definition Util.cpp:305
void wstrToLower(std::wstring &str)
Definition Util.h:314
bool IsConstant() const
Definition Channel.h:140
uint32 GetNumPlayers() const
Definition Channel.h:146
void LeftChannel(std::string const &name)
uint32 team
Definition ChannelMgr.h:37
static ChannelMgr * forTeam(uint32 team)
ChannelMap channels
Definition ChannelMgr.h:36
Channel * GetChannel(std::string const &name, Player *p, bool pkt=true)
Channel * GetJoinChannel(std::string const &name, uint32 channel_id)
void MakeNotOnPacket(WorldPacket *data, std::string const &name)
WorldSession * GetSession() const
Definition Player.h:2417
static T * instance()
Definition Singleton.h:17
void Initialize(Opcodes opcode, size_t newres=200)
Definition WorldPacket.h:31
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
@ SMSG_CHANNEL_NOTIFY
Definition Opcodes.h:602
#define sWorld
Definition World.h:910
@ CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHANNEL
Definition World.h:97