OregonCore  revision fb2a440-git
Your Favourite TBC server
ChannelHandler.cpp
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 #include "WorldSession.h"
19 #include "Channel.h"
20 #include "ChannelMgr.h"
21 #include "DBCStores.h"
22 #include "Log.h"
23 #include "ObjectMgr.h" // for normalizePlayerName
24 #include "Player.h"
25 
28 
30 {
31  uint32 channelId;
32  uint8 unknown1, unknown2;
33  std::string channelName, password;
34 
35  recvPacket >> channelId >> unknown1 >> unknown2 >> channelName >> password;
36 
37  sLog.outDebug("CMSG_JOIN_CHANNEL %s Channel: %u, unk1: %u, unk2: %u, channel: %s, password: %s",
38  GetPlayerName(), channelId, unknown1, unknown2, channelName.c_str(), password.c_str());
39 
40  if (channelName.empty() || isdigit(channelName[0]))
41  {
42  WorldPacket data(SMSG_CHANNEL_NOTIFY, 1 + channelName.size());
43  data << uint8(CHAT_INVALID_NAME_NOTICE) << channelName;
44  SendPacket(&data);
45  return;
46  }
47 
48  if (ChannelMgr* cMgr = channelMgr(_player->GetTeam()))
49  if (Channel* channel = cMgr->GetJoinChannel(channelName, channelId))
50  channel->Join(_player->GetGUID(), password.c_str());
51 }
52 
54 {
55  uint32 channelId;
56  std::string channelName;
57  recvPacket >> channelId >> channelName;
58 
59  sLog.outDebug("CMSG_LEAVE_CHANNEL %s Channel: %s, channelId: %u",
60  GetPlayerName(), channelName.c_str(), channelId);
61 
62  if (channelName.empty() && !channelId)
63  return;
64 
65  if (ChannelMgr* cMgr = channelMgr(_player->GetTeam()))
66  {
67  if (Channel* channel = cMgr->GetChannel(channelName, _player))
68  channel->Leave(_player->GetGUID(), true);
69 
70  cMgr->LeftChannel(channelName);
71  }
72 }
73 
75 {
76  std::string channelName;
77  recvPacket >> channelName;
78 
79  if (ChannelMgr* cMgr = channelMgr(_player->GetTeam()))
80  if (Channel* channel = cMgr->GetChannel(channelName, _player))
81  channel->List(_player);
82 }
83 
85 {
86  std::string channelName, password;
87  recvPacket >> channelName >> password;
88 
89  sLog.outDebug("CMSG_CHANNEL_PASSWORD %s Channel: %s, Password: %s",
90  GetPlayerName(), channelName.c_str(), password.c_str());
91 
92  if (password.length() > MAX_CHANNEL_PASS_STR)
93  return;
94 
95  if (ChannelMgr* cMgr = channelMgr(_player->GetTeam()))
96  if (Channel* channel = cMgr->GetChannel(channelName, _player))
97  channel->Password(_player->GetGUID(), password.c_str());
98 }
99 
101 {
102  std::string channelName, targetName;
103  recvPacket >> channelName >> targetName;
104 
105  sLog.outDebug("CMSG_CHANNEL_SET_OWNER %s Channel: %s, Target: %s",
106  GetPlayerName(), channelName.c_str(), targetName.c_str());
107 
108  if (!normalizePlayerName(targetName))
109  return;
110 
111  if (ChannelMgr* cMgr = channelMgr(_player->GetTeam()))
112  if (Channel* channel = cMgr->GetChannel(channelName, _player))
113  channel->SetOwner(_player->GetGUID(), targetName.c_str());
114 }
115 
117 {
118  std::string channelName;
119  recvPacket >> channelName;
120 
121  sLog.outDebug("CMSG_CHANNEL_OWNER %s Channel: %s",
122  GetPlayerName(), channelName.c_str());
123 
124  if (ChannelMgr* cMgr = channelMgr(_player->GetTeam()))
125  if (Channel* channel = cMgr->GetChannel(channelName, _player))
126  channel->SendWhoOwner(_player->GetGUID());
127 }
128 
130 {
131  std::string channelName, targetName;
132  recvPacket >> channelName >> targetName;
133 
134  sLog.outDebug("CMSG_CHANNEL_MODERATOR %s Channel: %s, Target: %s",
135  GetPlayerName(), channelName.c_str(), targetName.c_str());
136 
137  if (!normalizePlayerName(targetName))
138  return;
139 
140  if (ChannelMgr* cMgr = channelMgr(_player->GetTeam()))
141  if (Channel* channel = cMgr->GetChannel(channelName, _player))
142  channel->SetModerator(_player->GetGUID(), targetName.c_str());
143 }
144 
146 {
147  std::string channelName, targetName;
148  recvPacket >> channelName >> targetName;
149 
150  sLog.outDebug("CMSG_CHANNEL_UNMODERATOR %s Channel: %s, Target: %s",
151  GetPlayerName(), channelName.c_str(), targetName.c_str());
152 
153  if (!normalizePlayerName(targetName))
154  return;
155 
156  if (ChannelMgr* cMgr = channelMgr(_player->GetTeam()))
157  if (Channel* channel = cMgr->GetChannel(channelName, _player))
158  channel->UnsetModerator(_player->GetGUID(), targetName.c_str());
159 }
160 
162 {
163  std::string channelName, targetName;
164  recvPacket >> channelName >> targetName;
165 
166  sLog.outDebug("CMSG_CHANNEL_MUTE %s Channel: %s, Target: %s",
167  GetPlayerName(), channelName.c_str(), targetName.c_str());
168 
169  if (!normalizePlayerName(targetName))
170  return;
171 
172  if (ChannelMgr* cMgr = channelMgr(_player->GetTeam()))
173  if (Channel* channel = cMgr->GetChannel(channelName, _player))
174  channel->SetMute(_player->GetGUID(), targetName.c_str());
175 }
176 
178 {
179  std::string channelName, targetName;
180  recvPacket >> channelName >> targetName;
181 
182  sLog.outDebug("CMSG_CHANNEL_UNMUTE %s Channel: %s, Target: %s",
183  GetPlayerName(), channelName.c_str(), targetName.c_str());
184 
185  if (!normalizePlayerName(targetName))
186  return;
187 
188  if (ChannelMgr* cMgr = channelMgr(_player->GetTeam()))
189  if (Channel* channel = cMgr->GetChannel(channelName, _player))
190  channel->UnsetMute(_player->GetGUID(), targetName.c_str());
191 }
192 
194 {
195  std::string channelName, targetName;
196  recvPacket >> channelName >> targetName;
197 
198  sLog.outDebug("CMSG_CHANNEL_INVITE %s Channel: %s, Target: %s",
199  GetPlayerName(), channelName.c_str(), targetName.c_str());
200 
201  if (!normalizePlayerName(targetName))
202  return;
203 
204  if (ChannelMgr* cMgr = channelMgr(_player->GetTeam()))
205  if (Channel* channel = cMgr->GetChannel(channelName, _player))
206  channel->Invite(_player->GetGUID(), targetName.c_str());
207 }
208 
210 {
211  std::string channelName, targetName;
212  recvPacket >> channelName >> targetName;
213 
214  sLog.outDebug("CMSG_CHANNEL_KICK %s Channel: %s, Target: %s",
215  GetPlayerName(), channelName.c_str(), targetName.c_str());
216 
217  if (!normalizePlayerName(targetName))
218  return;
219 
220  if (ChannelMgr* cMgr = channelMgr(_player->GetTeam()))
221  if (Channel* channel = cMgr->GetChannel(channelName, _player))
222  channel->Kick(_player->GetGUID(), targetName.c_str());
223 }
224 
226 {
227  std::string channelName, targetName;
228  recvPacket >> channelName >> targetName;
229 
230  sLog.outDebug("CMSG_CHANNEL_BAN %s Channel: %s, Target: %s",
231  GetPlayerName(), channelName.c_str(), targetName.c_str());
232 
233  if (!normalizePlayerName(targetName))
234  return;
235 
236  if (ChannelMgr* cMgr = channelMgr(_player->GetTeam()))
237  if (Channel* channel = cMgr->GetChannel(channelName, _player))
238  channel->Ban(_player->GetGUID(), targetName.c_str());
239 }
240 
242 {
243  std::string channelName, targetName;
244  recvPacket >> channelName >> targetName;
245 
246  sLog.outDebug("CMSG_CHANNEL_UNBAN %s Channel: %s, Target: %s",
247  GetPlayerName(), channelName.c_str(), targetName.c_str());
248 
249  if (!normalizePlayerName(targetName))
250  return;
251 
252  if (ChannelMgr* cMgr = channelMgr(_player->GetTeam()))
253  if (Channel* channel = cMgr->GetChannel(channelName, _player))
254  channel->UnBan(_player->GetGUID(), targetName.c_str());
255 }
256 
258 {
259  std::string channelName;
260  recvPacket >> channelName;
261 
262  sLog.outDebug("CMSG_CHANNEL_ANNOUNCEMENTS %s Channel: %s",
263  GetPlayerName(), channelName.c_str());
264 
265  if (ChannelMgr* cMgr = channelMgr(_player->GetTeam()))
266  if (Channel* channel = cMgr->GetChannel(channelName, _player))
267  channel->Announce(_player->GetGUID());
268 }
269 
271 {
272  std::string channelName;
273  recvPacket >> channelName;
274 
275  sLog.outDebug("CMSG_CHANNEL_MODERATE %s Channel: %s",
276  GetPlayerName(), channelName.c_str());
277 
278  if (ChannelMgr* cMgr = channelMgr(_player->GetTeam()))
279  if (Channel* channel = cMgr->GetChannel(channelName, _player))
280  channel->Moderate(_player->GetGUID());
281 }
282 
284 {
285  std::string channelName;
286  recvPacket >> channelName;
287 
288  sLog.outDebug("CMSG_CHANNEL_ROSTER %s Channel: %s",
289  GetPlayerName(), channelName.c_str());
290 
291  if (ChannelMgr* cMgr = channelMgr(_player->GetTeam()))
292  if (Channel* channel = cMgr->GetChannel(channelName, _player))
293  channel->List(_player);
294 }
295 
297 {
298  std::string channelName;
299  recvPacket >> channelName;
300 
301  sLog.outDebug("CMSG_GET_CHANNEL_MEMBER_COUNT %s Channel: %s",
302  GetPlayerName(), channelName.c_str());
303 
304  if (ChannelMgr* cMgr = channelMgr(_player->GetTeam()))
305  {
306  if (Channel* channel = cMgr->GetChannel(channelName, _player))
307  {
308  WorldPacket data(SMSG_CHANNEL_MEMBER_COUNT, channel->GetName().size() + 1 + 1 + 4);
309  data << channel->GetName();
310  data << uint8(channel->GetFlags());
311  data << uint32(channel->GetNumPlayers());
312  SendPacket(&data);
313  }
314  }
315 }
316 
318 {
319  std::string channelName;
320  recvPacket >> channelName;
321 
322  sLog.outDebug("CMSG_SET_CHANNEL_WATCH %s Channel: %s",
323  GetPlayerName(), channelName.c_str());
324 
325  /*if (ChannelMgr* cMgr = channelMgr(_player->GetTeam()))
326  if (Channel *chn = cMgr->GetChannel(channelname, _player))
327  chn->JoinNotify(_player->GetGUID());*/
328 }
329 
INSTANTIATE_SINGLETON_1(AllianceChannelMgr)
void HandleChannelSetOwner(WorldPacket &recvPacket)
void HandleChannelOwner(WorldPacket &recvPacket)
void HandleChannelModerator(WorldPacket &recvPacket)
void HandleChannelKick(WorldPacket &recvPacket)
void HandleChannelAnnounce(WorldPacket &recvPacket)
void HandleChannelUnmute(WorldPacket &recvPacket)
#define sLog
Log class singleton.
Definition: Log.h:187
void HandleJoinChannel(WorldPacket &recvPacket)
void HandleChannelMute(WorldPacket &recvPacket)
void HandleChannelModerate(WorldPacket &recvPacket)
void SendPacket(WorldPacket const *packet)
void HandleChannelBan(WorldPacket &recvPacket)
void HandleChannelRosterQuery(WorldPacket &recvPacket)
void HandleChannelUnban(WorldPacket &recvPacket)
bool normalizePlayerName(std::string &name)
Definition: ObjectMgr.cpp:225
ACE_UINT8 uint8
Definition: Define.h:73
void HandleChannelPassword(WorldPacket &recvPacket)
void HandleChannelInvite(WorldPacket &recvPacket)
void HandleChannelList(WorldPacket &recvPacket)
void HandleGetChannelMemberCount(WorldPacket &recvPacket)
void HandleSetChannelWatch(WorldPacket &recvPacket)
char const * GetPlayerName() const
void HandleChannelUnmoderator(WorldPacket &recvPacket)
#define MAX_CHANNEL_PASS_STR
Definition: ChannelMgr.h:28
Player * _player
Definition: WorldSession.h:730
void HandleLeaveChannel(WorldPacket &recvPacket)
uint32 GetTeam() const
Definition: Player.h:2063
ACE_UINT32 uint32
Definition: Define.h:71
ChannelMgr * channelMgr(uint32 team)
Definition: ChannelMgr.h:92
const uint64 & GetGUID() const
Definition: Object.h:162