2010-10-07 15:35:36 +02:00
|
|
|
/*
|
2015-01-01 00:27:46 +01:00
|
|
|
* Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/>
|
2010-10-07 15:35:36 +02:00
|
|
|
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
|
* option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
|
* more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-10-02 16:23:55 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "ObjectMgr.h" // for normalizePlayerName
|
|
|
|
|
#include "ChannelMgr.h"
|
2014-11-23 04:25:47 +01:00
|
|
|
#include "ChannelPackets.h"
|
2012-11-17 05:18:37 +01:00
|
|
|
#include "Player.h"
|
2012-11-20 16:01:31 +01:00
|
|
|
#include "WorldSession.h"
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2014-07-29 14:59:17 +01:00
|
|
|
#include <cctype>
|
|
|
|
|
|
2014-11-23 04:25:47 +01:00
|
|
|
void WorldSession::HandleJoinChannel(WorldPackets::Channel::JoinChannel& packet)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2014-11-23 04:25:47 +01:00
|
|
|
TC_LOG_DEBUG("chat.system", "CMSG_JOIN_CHANNEL %s ChatChannelId: %u, CreateVoiceSession: %u, Internal: %u, ChannelName: %s, Password: %s",
|
|
|
|
|
GetPlayerInfo().c_str(), packet.ChatChannelId, packet.CreateVoiceSession, packet.Internal, packet.ChannelName.c_str(), packet.Password.c_str());
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2014-11-23 04:25:47 +01:00
|
|
|
if (packet.ChatChannelId)
|
2010-10-16 12:59:53 +02:00
|
|
|
{
|
2014-11-23 04:25:47 +01:00
|
|
|
ChatChannelsEntry const* channel = sChatChannelsStore.LookupEntry(packet.ChatChannelId);
|
2010-10-16 12:59:53 +02:00
|
|
|
if (!channel)
|
|
|
|
|
return;
|
2011-09-05 13:53:14 +02:00
|
|
|
|
2012-11-22 12:11:35 +01:00
|
|
|
AreaTableEntry const* zone = GetAreaEntryByAreaID(GetPlayer()->GetZoneId());
|
|
|
|
|
if (!zone || !GetPlayer()->CanJoinConstantChannelInZone(channel, zone))
|
2011-09-05 13:53:14 +02:00
|
|
|
return;
|
2010-10-16 12:59:53 +02:00
|
|
|
}
|
|
|
|
|
|
2014-11-23 04:25:47 +01:00
|
|
|
if (packet.ChannelName.empty())
|
2008-10-02 16:23:55 -05:00
|
|
|
return;
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2014-11-23 04:25:47 +01:00
|
|
|
if (isdigit(packet.ChannelName[0]))
|
2014-07-29 14:59:17 +01:00
|
|
|
return;
|
|
|
|
|
|
2014-11-23 04:25:47 +01:00
|
|
|
if (ChannelMgr* cMgr = ChannelMgr::ForTeam(GetPlayer()->GetTeam()))
|
2009-07-18 22:15:56 +02:00
|
|
|
{
|
2014-11-23 04:25:47 +01:00
|
|
|
cMgr->SetTeam(GetPlayer()->GetTeam());
|
|
|
|
|
if (Channel* channel = cMgr->GetJoinChannel(packet.ChannelName, packet.ChatChannelId))
|
|
|
|
|
channel->JoinChannel(GetPlayer(), packet.Password);
|
2009-07-18 22:15:56 +02:00
|
|
|
}
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2014-11-23 04:25:47 +01:00
|
|
|
void WorldSession::HandleLeaveChannel(WorldPackets::Channel::LeaveChannel& packet)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2014-11-23 04:25:47 +01:00
|
|
|
TC_LOG_DEBUG("chat.system", "CMSG_LEAVE_CHANNEL %s ChannelName: %s, ZoneChannelID: %u",
|
|
|
|
|
GetPlayerInfo().c_str(), packet.ChannelName.c_str(), packet.ZoneChannelID);
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2014-11-23 04:25:47 +01:00
|
|
|
if (packet.ChannelName.empty())
|
2008-10-02 16:23:55 -05:00
|
|
|
return;
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2014-11-23 04:25:47 +01:00
|
|
|
if (ChannelMgr* cMgr = ChannelMgr::ForTeam(GetPlayer()->GetTeam()))
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2014-11-23 04:25:47 +01:00
|
|
|
if (Channel* channel = cMgr->GetChannel(packet.ChannelName, GetPlayer()))
|
2012-11-22 12:11:35 +01:00
|
|
|
channel->LeaveChannel(GetPlayer(), true);
|
2014-11-23 04:25:47 +01:00
|
|
|
cMgr->LeftChannel(packet.ChannelName);
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2015-01-02 02:20:40 +01:00
|
|
|
template<void(Channel::*CommandFunction)(Player const*)>
|
|
|
|
|
void WorldSession::HandleChannelCommand(WorldPackets::Channel::ChannelPlayerCommand& packet)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2014-11-23 04:25:47 +01:00
|
|
|
TC_LOG_DEBUG("chat.system", "%s %s ChannelName: %s",
|
|
|
|
|
GetOpcodeNameForLogging(packet.GetOpcode()).c_str(), GetPlayerInfo().c_str(), packet.ChannelName.c_str());
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2014-11-23 04:25:47 +01:00
|
|
|
if (ChannelMgr* cMgr = ChannelMgr::ForTeam(GetPlayer()->GetTeam()))
|
|
|
|
|
if (Channel* channel = cMgr->GetChannel(packet.ChannelName, GetPlayer()))
|
2015-01-02 02:20:40 +01:00
|
|
|
(channel->*CommandFunction)(GetPlayer());
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2015-01-02 02:20:40 +01:00
|
|
|
template<void(Channel::*CommandFunction)(Player const*, std::string const&)>
|
|
|
|
|
void WorldSession::HandleChannelPlayerCommand(WorldPackets::Channel::ChannelPlayerCommand& packet)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2015-01-02 02:20:40 +01:00
|
|
|
if (packet.Name.length() >= MAX_CHANNEL_NAME_STR)
|
|
|
|
|
{
|
|
|
|
|
TC_LOG_DEBUG("chat.system", "%s %s ChannelName: %s, Name: %s, Name too long.",
|
|
|
|
|
GetOpcodeNameForLogging(packet.GetOpcode()).c_str(), GetPlayerInfo().c_str(), packet.ChannelName.c_str(), packet.Name.c_str());
|
2008-10-02 16:23:55 -05:00
|
|
|
return;
|
2015-01-02 02:20:40 +01:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2015-01-02 02:20:40 +01:00
|
|
|
TC_LOG_DEBUG("chat.system", "%s %s ChannelName: %s, Name: %s",
|
|
|
|
|
GetOpcodeNameForLogging(packet.GetOpcode()).c_str(), GetPlayerInfo().c_str(), packet.ChannelName.c_str(), packet.Name.c_str());
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2015-01-02 02:20:40 +01:00
|
|
|
if (!normalizePlayerName(packet.Name))
|
2008-10-02 16:23:55 -05:00
|
|
|
return;
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2014-11-23 04:25:47 +01:00
|
|
|
if (ChannelMgr* cMgr = ChannelMgr::ForTeam(GetPlayer()->GetTeam()))
|
2015-01-02 02:20:40 +01:00
|
|
|
if (Channel* channel = cMgr->GetChannel(packet.ChannelName, GetPlayer()))
|
|
|
|
|
(channel->*CommandFunction)(GetPlayer(), packet.Name);
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2015-01-02 02:20:40 +01:00
|
|
|
template<>
|
|
|
|
|
void WorldSession::HandleChannelPlayerCommand<&Channel::Password>(WorldPackets::Channel::ChannelPlayerCommand& packet)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2015-01-02 02:20:40 +01:00
|
|
|
if (packet.Name.length() > MAX_CHANNEL_PASS_STR)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2015-01-02 02:20:40 +01:00
|
|
|
TC_LOG_DEBUG("chat.system", "%s %s ChannelName: %s, Password: %s, Password too long.",
|
|
|
|
|
GetOpcodeNameForLogging(packet.GetOpcode()).c_str(), GetPlayerInfo().c_str(), packet.ChannelName.c_str(), packet.Name.c_str());
|
|
|
|
|
return;
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2012-11-22 12:11:35 +01:00
|
|
|
|
2015-01-02 02:20:40 +01:00
|
|
|
TC_LOG_DEBUG("chat.system", "%s %s ChannelName: %s, Password: %s",
|
|
|
|
|
GetOpcodeNameForLogging(packet.GetOpcode()).c_str(), GetPlayerInfo().c_str(), packet.ChannelName.c_str(), packet.Name.c_str());
|
2012-11-22 12:11:35 +01:00
|
|
|
|
2015-01-02 02:20:40 +01:00
|
|
|
if (ChannelMgr* cMgr = ChannelMgr::ForTeam(GetPlayer()->GetTeam()))
|
|
|
|
|
if (Channel* channel = cMgr->GetChannel(packet.ChannelName, GetPlayer()))
|
|
|
|
|
channel->Password(GetPlayer(), packet.Name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template void WorldSession::HandleChannelCommand<&Channel::Announce>(WorldPackets::Channel::ChannelPlayerCommand&);
|
|
|
|
|
template void WorldSession::HandleChannelPlayerCommand<&Channel::Ban>(WorldPackets::Channel::ChannelPlayerCommand&);
|
|
|
|
|
template void WorldSession::HandleChannelCommand<&Channel::DeclineInvite>(WorldPackets::Channel::ChannelPlayerCommand&);
|
|
|
|
|
template void WorldSession::HandleChannelPlayerCommand<&Channel::Invite>(WorldPackets::Channel::ChannelPlayerCommand&);
|
|
|
|
|
template void WorldSession::HandleChannelPlayerCommand<&Channel::Kick>(WorldPackets::Channel::ChannelPlayerCommand&);
|
|
|
|
|
template void WorldSession::HandleChannelCommand<&Channel::List>(WorldPackets::Channel::ChannelPlayerCommand&);
|
|
|
|
|
template void WorldSession::HandleChannelPlayerCommand<&Channel::SetModerator>(WorldPackets::Channel::ChannelPlayerCommand&);
|
|
|
|
|
template void WorldSession::HandleChannelPlayerCommand<&Channel::SetMute>(WorldPackets::Channel::ChannelPlayerCommand&);
|
|
|
|
|
template void WorldSession::HandleChannelCommand<&Channel::SendWhoOwner>(WorldPackets::Channel::ChannelPlayerCommand&);
|
|
|
|
|
template void WorldSession::HandleChannelPlayerCommand<&Channel::SetOwner>(WorldPackets::Channel::ChannelPlayerCommand&);
|
|
|
|
|
template void WorldSession::HandleChannelPlayerCommand<&Channel::SilenceAll>(WorldPackets::Channel::ChannelPlayerCommand&);
|
|
|
|
|
template void WorldSession::HandleChannelPlayerCommand<&Channel::SilenceVoice>(WorldPackets::Channel::ChannelPlayerCommand&);
|
|
|
|
|
template void WorldSession::HandleChannelPlayerCommand<&Channel::UnBan>(WorldPackets::Channel::ChannelPlayerCommand&);
|
|
|
|
|
template void WorldSession::HandleChannelPlayerCommand<&Channel::UnsetModerator>(WorldPackets::Channel::ChannelPlayerCommand&);
|
|
|
|
|
template void WorldSession::HandleChannelPlayerCommand<&Channel::UnsetMute>(WorldPackets::Channel::ChannelPlayerCommand&);
|
|
|
|
|
template void WorldSession::HandleChannelPlayerCommand<&Channel::UnsilenceAll>(WorldPackets::Channel::ChannelPlayerCommand&);
|
|
|
|
|
template void WorldSession::HandleChannelPlayerCommand<&Channel::UnsilenceVoice>(WorldPackets::Channel::ChannelPlayerCommand&);
|
|
|
|
|
template void WorldSession::HandleChannelCommand<&Channel::DeVoice>(WorldPackets::Channel::ChannelPlayerCommand&);
|
|
|
|
|
template void WorldSession::HandleChannelCommand<&Channel::Voice>(WorldPackets::Channel::ChannelPlayerCommand&);
|