2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "ObjectMgr.h" // for normalizePlayerName
20 #include "ChannelMgr.h"
21 #include "Policies/SingletonImp.h"
23 INSTANTIATE_SINGLETON_1( AllianceChannelMgr
);
24 INSTANTIATE_SINGLETON_1( HordeChannelMgr
);
26 void WorldSession::HandleJoinChannel(WorldPacket
& recvPacket
)
28 sLog
.outDebug("Opcode %u", recvPacket
.GetOpcode());
29 //recvPacket.hexlike();
30 CHECK_PACKET_SIZE(recvPacket
, 4+1+1+1);
33 uint8 unknown1
, unknown2
;
34 std::string channelname
, pass
;
36 recvPacket
>> channel_id
>> unknown1
>> unknown2
;
37 recvPacket
>> channelname
;
39 if(channelname
.empty())
43 CHECK_PACKET_SIZE(recvPacket
, 4+1+1+(channelname
.size()+1)+1);
46 if(ChannelMgr
* cMgr
= channelMgr(_player
->GetTeam()))
47 if(Channel
*chn
= cMgr
->GetJoinChannel(channelname
, channel_id
))
48 chn
->Join(_player
->GetGUID(), pass
.c_str());
51 void WorldSession::HandleLeaveChannel(WorldPacket
& recvPacket
)
53 sLog
.outDebug("Opcode %u", recvPacket
.GetOpcode());
54 //recvPacket.hexlike();
55 CHECK_PACKET_SIZE(recvPacket
, 4+1);
58 std::string channelname
;
59 recvPacket
>> unk
; // channel id?
60 recvPacket
>> channelname
;
62 if(channelname
.empty())
65 if(ChannelMgr
* cMgr
= channelMgr(_player
->GetTeam()))
67 if(Channel
*chn
= cMgr
->GetChannel(channelname
, _player
))
68 chn
->Leave(_player
->GetGUID(), true);
69 cMgr
->LeftChannel(channelname
);
73 void WorldSession::HandleChannelList(WorldPacket
& recvPacket
)
75 sLog
.outDebug("Opcode %u", recvPacket
.GetOpcode());
76 //recvPacket.hexlike();
77 CHECK_PACKET_SIZE(recvPacket
, 1);
79 std::string channelname
;
80 recvPacket
>> channelname
;
82 if(ChannelMgr
* cMgr
= channelMgr(_player
->GetTeam()))
83 if(Channel
*chn
= cMgr
->GetChannel(channelname
, _player
))
87 void WorldSession::HandleChannelPassword(WorldPacket
& recvPacket
)
89 sLog
.outDebug("Opcode %u", recvPacket
.GetOpcode());
90 //recvPacket.hexlike();
91 CHECK_PACKET_SIZE(recvPacket
, 1+1);
93 std::string channelname
, pass
;
94 recvPacket
>> channelname
;
97 CHECK_PACKET_SIZE(recvPacket
, (channelname
.size()+1)+1);
101 if(ChannelMgr
* cMgr
= channelMgr(_player
->GetTeam()))
102 if(Channel
*chn
= cMgr
->GetChannel(channelname
, _player
))
103 chn
->Password(_player
->GetGUID(), pass
.c_str());
106 void WorldSession::HandleChannelSetOwner(WorldPacket
& recvPacket
)
108 sLog
.outDebug("Opcode %u", recvPacket
.GetOpcode());
109 //recvPacket.hexlike();
110 CHECK_PACKET_SIZE(recvPacket
, 1+1);
112 std::string channelname
, newp
;
113 recvPacket
>> channelname
;
116 CHECK_PACKET_SIZE(recvPacket
, (channelname
.size()+1)+1);
120 if(!normalizePlayerName(newp
))
123 if(ChannelMgr
* cMgr
= channelMgr(_player
->GetTeam()))
124 if(Channel
*chn
= cMgr
->GetChannel(channelname
, _player
))
125 chn
->SetOwner(_player
->GetGUID(), newp
.c_str());
128 void WorldSession::HandleChannelOwner(WorldPacket
& recvPacket
)
130 sLog
.outDebug("Opcode %u", recvPacket
.GetOpcode());
131 //recvPacket.hexlike();
132 CHECK_PACKET_SIZE(recvPacket
, 1);
134 std::string channelname
;
135 recvPacket
>> channelname
;
136 if(ChannelMgr
* cMgr
= channelMgr(_player
->GetTeam()))
137 if(Channel
*chn
= cMgr
->GetChannel(channelname
, _player
))
138 chn
->SendWhoOwner(_player
->GetGUID());
141 void WorldSession::HandleChannelModerator(WorldPacket
& recvPacket
)
143 sLog
.outDebug("Opcode %u", recvPacket
.GetOpcode());
144 //recvPacket.hexlike();
145 CHECK_PACKET_SIZE(recvPacket
, 1+1);
147 std::string channelname
, otp
;
148 recvPacket
>> channelname
;
151 CHECK_PACKET_SIZE(recvPacket
, (channelname
.size()+1)+1);
155 if(!normalizePlayerName(otp
))
158 if(ChannelMgr
* cMgr
= channelMgr(_player
->GetTeam()))
159 if(Channel
*chn
= cMgr
->GetChannel(channelname
, _player
))
160 chn
->SetModerator(_player
->GetGUID(), otp
.c_str());
163 void WorldSession::HandleChannelUnmoderator(WorldPacket
& recvPacket
)
165 sLog
.outDebug("Opcode %u", recvPacket
.GetOpcode());
166 //recvPacket.hexlike();
167 CHECK_PACKET_SIZE(recvPacket
, 1+1);
169 std::string channelname
, otp
;
170 recvPacket
>> channelname
;
173 CHECK_PACKET_SIZE(recvPacket
, (channelname
.size()+1)+1);
177 if(!normalizePlayerName(otp
))
180 if(ChannelMgr
* cMgr
= channelMgr(_player
->GetTeam()))
181 if(Channel
*chn
= cMgr
->GetChannel(channelname
, _player
))
182 chn
->UnsetModerator(_player
->GetGUID(), otp
.c_str());
185 void WorldSession::HandleChannelMute(WorldPacket
& recvPacket
)
187 sLog
.outDebug("Opcode %u", recvPacket
.GetOpcode());
188 //recvPacket.hexlike();
189 CHECK_PACKET_SIZE(recvPacket
, 1+1);
191 std::string channelname
, otp
;
192 recvPacket
>> channelname
;
195 CHECK_PACKET_SIZE(recvPacket
, (channelname
.size()+1)+1);
199 if(!normalizePlayerName(otp
))
202 if(ChannelMgr
* cMgr
= channelMgr(_player
->GetTeam()))
203 if(Channel
*chn
= cMgr
->GetChannel(channelname
, _player
))
204 chn
->SetMute(_player
->GetGUID(), otp
.c_str());
207 void WorldSession::HandleChannelUnmute(WorldPacket
& recvPacket
)
209 sLog
.outDebug("Opcode %u", recvPacket
.GetOpcode());
210 //recvPacket.hexlike();
211 CHECK_PACKET_SIZE(recvPacket
, 1+1);
213 std::string channelname
, otp
;
214 recvPacket
>> channelname
;
217 CHECK_PACKET_SIZE(recvPacket
, (channelname
.size()+1)+1);
221 if(!normalizePlayerName(otp
))
224 if(ChannelMgr
* cMgr
= channelMgr(_player
->GetTeam()))
225 if(Channel
*chn
= cMgr
->GetChannel(channelname
, _player
))
226 chn
->UnsetMute(_player
->GetGUID(), otp
.c_str());
229 void WorldSession::HandleChannelInvite(WorldPacket
& recvPacket
)
231 sLog
.outDebug("Opcode %u", recvPacket
.GetOpcode());
232 //recvPacket.hexlike();
233 CHECK_PACKET_SIZE(recvPacket
, 1+1);
235 std::string channelname
, otp
;
236 recvPacket
>> channelname
;
239 CHECK_PACKET_SIZE(recvPacket
, (channelname
.size()+1)+1);
243 if(!normalizePlayerName(otp
))
246 if(ChannelMgr
* cMgr
= channelMgr(_player
->GetTeam()))
247 if(Channel
*chn
= cMgr
->GetChannel(channelname
, _player
))
248 chn
->Invite(_player
->GetGUID(), otp
.c_str());
251 void WorldSession::HandleChannelKick(WorldPacket
& recvPacket
)
253 sLog
.outDebug("Opcode %u", recvPacket
.GetOpcode());
254 //recvPacket.hexlike();
255 CHECK_PACKET_SIZE(recvPacket
, 1+1);
257 std::string channelname
, otp
;
258 recvPacket
>> channelname
;
261 CHECK_PACKET_SIZE(recvPacket
, (channelname
.size()+1)+1);
264 if(!normalizePlayerName(otp
))
267 if(ChannelMgr
* cMgr
= channelMgr(_player
->GetTeam()))
268 if(Channel
*chn
= cMgr
->GetChannel(channelname
, _player
))
269 chn
->Kick(_player
->GetGUID(), otp
.c_str());
272 void WorldSession::HandleChannelBan(WorldPacket
& recvPacket
)
274 sLog
.outDebug("Opcode %u", recvPacket
.GetOpcode());
275 //recvPacket.hexlike();
276 CHECK_PACKET_SIZE(recvPacket
, 1+1);
278 std::string channelname
, otp
;
279 recvPacket
>> channelname
;
282 CHECK_PACKET_SIZE(recvPacket
, (channelname
.size()+1)+1);
286 if(!normalizePlayerName(otp
))
289 if(ChannelMgr
* cMgr
= channelMgr(_player
->GetTeam()))
290 if(Channel
*chn
= cMgr
->GetChannel(channelname
, _player
))
291 chn
->Ban(_player
->GetGUID(), otp
.c_str());
294 void WorldSession::HandleChannelUnban(WorldPacket
& recvPacket
)
296 sLog
.outDebug("Opcode %u", recvPacket
.GetOpcode());
297 //recvPacket.hexlike();
298 CHECK_PACKET_SIZE(recvPacket
, 1+1);
300 std::string channelname
, otp
;
301 recvPacket
>> channelname
;
304 CHECK_PACKET_SIZE(recvPacket
, (channelname
.size()+1)+1);
308 if(!normalizePlayerName(otp
))
311 if(ChannelMgr
* cMgr
= channelMgr(_player
->GetTeam()))
312 if(Channel
*chn
= cMgr
->GetChannel(channelname
, _player
))
313 chn
->UnBan(_player
->GetGUID(), otp
.c_str());
316 void WorldSession::HandleChannelAnnouncements(WorldPacket
& recvPacket
)
318 sLog
.outDebug("Opcode %u", recvPacket
.GetOpcode());
319 //recvPacket.hexlike();
320 CHECK_PACKET_SIZE(recvPacket
, 1);
322 std::string channelname
;
323 recvPacket
>> channelname
;
324 if(ChannelMgr
* cMgr
= channelMgr(_player
->GetTeam()))
325 if(Channel
*chn
= cMgr
->GetChannel(channelname
, _player
))
326 chn
->Announce(_player
->GetGUID());
329 void WorldSession::HandleChannelModerate(WorldPacket
& recvPacket
)
331 sLog
.outDebug("Opcode %u", recvPacket
.GetOpcode());
332 //recvPacket.hexlike();
333 CHECK_PACKET_SIZE(recvPacket
, 1);
335 std::string channelname
;
336 recvPacket
>> channelname
;
337 if(ChannelMgr
* cMgr
= channelMgr(_player
->GetTeam()))
338 if(Channel
*chn
= cMgr
->GetChannel(channelname
, _player
))
339 chn
->Moderate(_player
->GetGUID());
342 void WorldSession::HandleChannelDisplayListQuery(WorldPacket
&recvPacket
)
344 sLog
.outDebug("Opcode %u", recvPacket
.GetOpcode());
345 //recvPacket.hexlike();
346 CHECK_PACKET_SIZE(recvPacket
, 1);
348 std::string channelname
;
349 recvPacket
>> channelname
;
350 if(ChannelMgr
* cMgr
= channelMgr(_player
->GetTeam()))
351 if(Channel
*chn
= cMgr
->GetChannel(channelname
, _player
))
355 void WorldSession::HandleGetChannelMemberCount(WorldPacket
&recvPacket
)
357 sLog
.outDebug("Opcode %u", recvPacket
.GetOpcode());
358 //recvPacket.hexlike();
359 CHECK_PACKET_SIZE(recvPacket
, 1);
361 std::string channelname
;
362 recvPacket
>> channelname
;
363 if(ChannelMgr
* cMgr
= channelMgr(_player
->GetTeam()))
365 if(Channel
*chn
= cMgr
->GetChannel(channelname
, _player
))
367 WorldPacket
data(SMSG_CHANNEL_MEMBER_COUNT
, chn
->GetName().size()+1+1+4);
368 data
<< chn
->GetName();
369 data
<< uint8(chn
->GetFlags());
370 data
<< uint32(chn
->GetNumPlayers());
376 void WorldSession::HandleSetChannelWatch(WorldPacket
&recvPacket
)
378 sLog
.outDebug("Opcode %u", recvPacket
.GetOpcode());
379 //recvPacket.hexlike();
380 CHECK_PACKET_SIZE(recvPacket
, 1);
382 std::string channelname
;
383 recvPacket
>> channelname
;
384 /*if(ChannelMgr* cMgr = channelMgr(_player->GetTeam()))
385 if(Channel *chn = cMgr->GetChannel(channelname, _player))
386 chn->JoinNotify(_player->GetGUID());*/