Character re-customization fix
[getmangos.git] / src / game / ChannelHandler.cpp
blob3a3a73e971b3eb45bda81ce1dffdfd7f9cc4c495
1 /*
2 * Copyright (C) 2005-2008 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::HandleChannelJoin(WorldPacket& recvPacket)
28 sLog.outDebug("Opcode %u", recvPacket.GetOpcode());
29 //recvPacket.hexlike();
30 CHECK_PACKET_SIZE(recvPacket, 4+1+1+1);
32 uint32 channel_id;
33 uint8 unknown1, unknown2;
34 std::string channelname, pass;
36 recvPacket >> channel_id >> unknown1 >> unknown2;
37 recvPacket >> channelname;
39 if(channelname.empty())
40 return;
42 // recheck
43 CHECK_PACKET_SIZE(recvPacket, 4+1+1+(channelname.size()+1)+1);
45 recvPacket >> pass;
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::HandleChannelLeave(WorldPacket& recvPacket)
53 sLog.outDebug("Opcode %u", recvPacket.GetOpcode());
54 //recvPacket.hexlike();
55 CHECK_PACKET_SIZE(recvPacket, 4+1);
57 uint32 unk;
58 std::string channelname;
59 recvPacket >> unk; // channel id?
60 recvPacket >> channelname;
62 if(channelname.empty())
63 return;
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))
84 chn->List(_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;
96 // recheck
97 CHECK_PACKET_SIZE(recvPacket, (channelname.size()+1)+1);
99 recvPacket >> pass;
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;
115 // recheck
116 CHECK_PACKET_SIZE(recvPacket, (channelname.size()+1)+1);
118 recvPacket >> newp;
120 if(!normalizePlayerName(newp))
121 return;
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;
150 // recheck
151 CHECK_PACKET_SIZE(recvPacket, (channelname.size()+1)+1);
153 recvPacket >> otp;
155 if(!normalizePlayerName(otp))
156 return;
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;
172 // recheck
173 CHECK_PACKET_SIZE(recvPacket, (channelname.size()+1)+1);
175 recvPacket >> otp;
177 if(!normalizePlayerName(otp))
178 return;
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;
194 // recheck
195 CHECK_PACKET_SIZE(recvPacket, (channelname.size()+1)+1);
197 recvPacket >> otp;
199 if(!normalizePlayerName(otp))
200 return;
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;
216 // recheck
217 CHECK_PACKET_SIZE(recvPacket, (channelname.size()+1)+1);
219 recvPacket >> otp;
221 if(!normalizePlayerName(otp))
222 return;
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;
238 // recheck
239 CHECK_PACKET_SIZE(recvPacket, (channelname.size()+1)+1);
241 recvPacket >> otp;
243 if(!normalizePlayerName(otp))
244 return;
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;
260 // recheck
261 CHECK_PACKET_SIZE(recvPacket, (channelname.size()+1)+1);
263 recvPacket >> otp;
264 if(!normalizePlayerName(otp))
265 return;
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;
281 // recheck
282 CHECK_PACKET_SIZE(recvPacket, (channelname.size()+1)+1);
284 recvPacket >> otp;
286 if(!normalizePlayerName(otp))
287 return;
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;
303 // recheck
304 CHECK_PACKET_SIZE(recvPacket, (channelname.size()+1)+1);
306 recvPacket >> otp;
308 if(!normalizePlayerName(otp))
309 return;
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::HandleChannelAnnounce(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::HandleChannelRosterQuery(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))
352 chn->List(_player);
355 void WorldSession::HandleChannelInfoQuery(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());
371 SendPacket(&data);
376 void WorldSession::HandleChannelJoinNotify(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());*/