Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
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
11
ChannelMgr::~ChannelMgr
()
12
{
13
for
(ChannelMap::iterator itr =
channels
.begin(); itr !=
channels
.end(); ++itr)
14
delete
itr->second;
15
}
16
17
ChannelMgr
*
ChannelMgr::forTeam
(
uint32
team
)
18
{
19
if
(
sWorld
->GetBoolConfig(
WorldBoolConfigs::CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHANNEL
))
20
return
Skyfire::Singleton<AllianceChannelMgr, Skyfire::NullMutex>::instance
();
// cross-faction
21
22
if
(
team
==
ALLIANCE
)
23
return
Skyfire::Singleton<AllianceChannelMgr, Skyfire::NullMutex>::instance
();
24
25
if
(
team
==
HORDE
)
26
return
Skyfire::Singleton<HordeChannelMgr, Skyfire::NullMutex>::instance
();
27
28
return
NULL;
29
}
30
31
Channel
*
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
51
Channel
*
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
76
void
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
98
void
ChannelMgr::MakeNotOnPacket
(
WorldPacket
* data, std::string
const
& name)
99
{
100
data->
Initialize
(
SMSG_CHANNEL_NOTIFY
, 1 + name.size());
101
(*data) <<
uint8
(5) << name;
102
}
ChannelMgr.h
uint8
std::uint8_t uint8
Definition
Define.h:79
uint32
std::uint32_t uint32
Definition
Define.h:77
Player.h
ALLIANCE
@ ALLIANCE
Definition
SharedDefines.h:877
HORDE
@ HORDE
Definition
SharedDefines.h:876
Utf8toWStr
bool Utf8toWStr(char const *utf8str, size_t csize, wchar_t *wstr, size_t &wsize)
Definition
Util.cpp:305
wstrToLower
void wstrToLower(std::wstring &str)
Definition
Util.h:314
World.h
WorldSession.h
Channel
Definition
Channel.h:107
Channel::IsConstant
bool IsConstant() const
Definition
Channel.h:140
Channel::GetNumPlayers
uint32 GetNumPlayers() const
Definition
Channel.h:146
ChannelMgr::LeftChannel
void LeftChannel(std::string const &name)
Definition
ChannelMgr.cpp:76
ChannelMgr::~ChannelMgr
~ChannelMgr()
Definition
ChannelMgr.cpp:11
ChannelMgr::team
uint32 team
Definition
ChannelMgr.h:37
ChannelMgr::ChannelMgr
ChannelMgr()
Definition
ChannelMgr.h:23
ChannelMgr::forTeam
static ChannelMgr * forTeam(uint32 team)
Definition
ChannelMgr.cpp:17
ChannelMgr::channels
ChannelMap channels
Definition
ChannelMgr.h:36
ChannelMgr::GetChannel
Channel * GetChannel(std::string const &name, Player *p, bool pkt=true)
Definition
ChannelMgr.cpp:51
ChannelMgr::GetJoinChannel
Channel * GetJoinChannel(std::string const &name, uint32 channel_id)
Definition
ChannelMgr.cpp:31
ChannelMgr::MakeNotOnPacket
void MakeNotOnPacket(WorldPacket *data, std::string const &name)
Definition
ChannelMgr.cpp:98
Player
Definition
Player.h:1289
Player::GetSession
WorldSession * GetSession() const
Definition
Player.h:2417
Skyfire::Singleton::instance
static T * instance()
Definition
Singleton.h:17
WorldPacket
Definition
WorldPacket.h:16
WorldPacket::Initialize
void Initialize(Opcodes opcode, size_t newres=200)
Definition
WorldPacket.h:31
WorldSession::SendPacket
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
Definition
WorldSession.cpp:196
SMSG_CHANNEL_NOTIFY
@ SMSG_CHANNEL_NOTIFY
Definition
Opcodes.h:602
sWorld
#define sWorld
Definition
World.h:910
WorldBoolConfigs::CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHANNEL
@ CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHANNEL
Definition
World.h:97
src
server
game
Chat
Channels
ChannelMgr.cpp
Generated on
for Project SkyFire Core by
1.17.0