Files
TCPlayerbotCore/src/server/game/Handlers/ChannelHandler.cpp
T

340 lines
12 KiB
C++
Raw Normal View History

/*
2015-01-01 00:27:46 +01:00
* Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/>
* 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"
#include "Player.h"
2012-11-20 16:01:31 +01:00
#include "WorldSession.h"
2009-10-17 15:51:44 -07: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;
AreaTableEntry const* zone = GetAreaEntryByAreaID(GetPlayer()->GetZoneId());
if (!zone || !GetPlayer()->CanJoinConstantChannelInZone(channel, zone))
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]))
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()))
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
2014-11-23 04:25:47 +01:00
void WorldSession::HandleChannelList(WorldPackets::Channel::ChannelListRequest& 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()))
channel->List(GetPlayer());
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void WorldSession::HandleChannelPassword(WorldPacket& recvPacket)
{
uint32 nameLength = recvPacket.ReadBits(8);
uint32 passLength = recvPacket.ReadBits(7);
2012-11-22 15:04:59 +01:00
std::string channelName = recvPacket.ReadString(nameLength);
std::string password = recvPacket.ReadString(passLength);
2009-10-17 15:51:44 -07:00
TC_LOG_DEBUG("chat.system", "CMSG_CHANNEL_PASSWORD %s Channel: %s, Password: %s",
GetPlayerInfo().c_str(), channelName.c_str(), password.c_str());
2009-10-17 15:51:44 -07:00
if (password.length() > MAX_CHANNEL_PASS_STR)
return;
2014-11-23 04:25:47 +01:00
if (ChannelMgr* cMgr = ChannelMgr::ForTeam(GetPlayer()->GetTeam()))
if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer()))
channel->Password(GetPlayer(), password);
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void WorldSession::HandleChannelSetOwner(WorldPacket& recvPacket)
{
uint32 channelLength = recvPacket.ReadBits(8);
uint32 nameLength = recvPacket.ReadBits(7);
2009-10-17 15:51:44 -07:00
2012-11-22 15:04:59 +01:00
std::string targetName = recvPacket.ReadString(nameLength);
std::string channelName = recvPacket.ReadString(channelLength);
TC_LOG_DEBUG("chat.system", "CMSG_CHANNEL_SET_OWNER %s Channel: %s, Target: %s",
GetPlayerInfo().c_str(), channelName.c_str(), targetName.c_str());
2009-10-17 15:51:44 -07:00
if (!normalizePlayerName(targetName))
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()))
if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer()))
channel->SetOwner(GetPlayer(), targetName);
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void WorldSession::HandleChannelOwner(WorldPacket& recvPacket)
{
uint32 length = recvPacket.ReadBits(8);
2012-11-22 15:04:59 +01:00
std::string channelName = recvPacket.ReadString(length);
TC_LOG_DEBUG("chat.system", "CMSG_CHANNEL_OWNER %s Channel: %s",
GetPlayerInfo().c_str(), channelName.c_str());
2014-11-23 04:25:47 +01:00
if (ChannelMgr* cMgr = ChannelMgr::ForTeam(GetPlayer()->GetTeam()))
if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer()))
2014-11-23 04:25:47 +01:00
channel->SendWhoOwner(GetPlayer());
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void WorldSession::HandleChannelModerator(WorldPacket& recvPacket)
{
uint32 channelLength = recvPacket.ReadBits(8);
uint32 nameLength = recvPacket.ReadBits(7);
2012-11-22 15:04:59 +01:00
std::string targetName = recvPacket.ReadString(nameLength);
std::string channelName = recvPacket.ReadString(channelLength);
2009-10-17 15:51:44 -07:00
TC_LOG_DEBUG("chat.system", "CMSG_CHANNEL_MODERATOR %s Channel: %s, Target: %s",
GetPlayerInfo().c_str(), channelName.c_str(), targetName.c_str());
if (!normalizePlayerName(targetName))
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()))
if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer()))
channel->SetModerator(GetPlayer(), targetName);
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void WorldSession::HandleChannelUnmoderator(WorldPacket& recvPacket)
{
uint32 nameLength = recvPacket.ReadBits(7);
uint32 channelLength = recvPacket.ReadBits(8);
2012-11-22 15:04:59 +01:00
std::string channelName = recvPacket.ReadString(channelLength);
std::string targetName = recvPacket.ReadString(nameLength);
2009-10-17 15:51:44 -07:00
TC_LOG_DEBUG("chat.system", "CMSG_CHANNEL_UNMODERATOR %s Channel: %s, Target: %s",
GetPlayerInfo().c_str(), channelName.c_str(), targetName.c_str());
2009-10-17 15:51:44 -07:00
if (!normalizePlayerName(targetName))
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()))
if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer()))
channel->UnsetModerator(GetPlayer(), targetName);
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void WorldSession::HandleChannelMute(WorldPacket& recvPacket)
{
uint32 channelLength = recvPacket.ReadBits(8);
uint32 nameLength = recvPacket.ReadBits(7);
2012-11-22 15:04:59 +01:00
std::string channelName = recvPacket.ReadString(channelLength);
std::string targetName = recvPacket.ReadString(nameLength);
2009-10-17 15:51:44 -07:00
TC_LOG_DEBUG("chat.system", "CMSG_CHANNEL_MUTE %s Channel: %s, Target: %s",
GetPlayerInfo().c_str(), channelName.c_str(), targetName.c_str());
2009-10-17 15:51:44 -07:00
if (!normalizePlayerName(targetName))
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()))
if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer()))
channel->SetMute(GetPlayer(), targetName);
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void WorldSession::HandleChannelUnmute(WorldPacket& recvPacket)
{
uint32 nameLength = recvPacket.ReadBits(8);
uint32 channelLength = recvPacket.ReadBits(7);
2009-10-17 15:51:44 -07:00
2012-11-22 15:04:59 +01:00
std::string targetName = recvPacket.ReadString(nameLength);
std::string channelName = recvPacket.ReadString(channelLength);
TC_LOG_DEBUG("chat.system", "CMSG_CHANNEL_UNMUTE %s Channel: %s, Target: %s",
GetPlayerInfo().c_str(), channelName.c_str(), targetName.c_str());
2009-10-17 15:51:44 -07:00
if (!normalizePlayerName(targetName))
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()))
if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer()))
channel->UnsetMute(GetPlayer(), targetName);
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void WorldSession::HandleChannelInvite(WorldPacket& recvPacket)
{
uint32 nameLength = recvPacket.ReadBits(7);
uint32 channelLength = recvPacket.ReadBits(8);
2012-11-22 15:04:59 +01:00
std::string targetName = recvPacket.ReadString(nameLength);
std::string channelName = recvPacket.ReadString(channelLength);
2009-10-17 15:51:44 -07:00
TC_LOG_DEBUG("chat.system", "CMSG_CHANNEL_INVITE %s Channel: %s, Target: %s",
GetPlayerInfo().c_str(), channelName.c_str(), targetName.c_str());
if (!normalizePlayerName(targetName))
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()))
if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer()))
channel->Invite(GetPlayer(), targetName);
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void WorldSession::HandleChannelKick(WorldPacket& recvPacket)
{
uint32 channelLength = recvPacket.ReadBits(8);
uint32 nameLength = recvPacket.ReadBits(7);
2012-11-22 15:04:59 +01:00
std::string channelName = recvPacket.ReadString(channelLength);
std::string targetName = recvPacket.ReadString(nameLength);
2009-10-17 15:51:44 -07:00
TC_LOG_DEBUG("chat.system", "CMSG_CHANNEL_KICK %s Channel: %s, Target: %s",
GetPlayerInfo().c_str(), channelName.c_str(), targetName.c_str());
if (!normalizePlayerName(targetName))
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()))
if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer()))
channel->Kick(GetPlayer(), targetName);
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void WorldSession::HandleChannelBan(WorldPacket& recvPacket)
{
uint32 channelLength, nameLength;
std::string channelName, targetName;
channelLength = recvPacket.ReadBits(8);
nameLength = recvPacket.ReadBits(7);
2009-10-17 15:51:44 -07:00
2012-11-22 15:04:59 +01:00
targetName = recvPacket.ReadString(nameLength);
channelName = recvPacket.ReadString(channelLength);
2009-10-17 15:51:44 -07:00
TC_LOG_DEBUG("chat.system", "CMSG_CHANNEL_BAN %s Channel: %s, Target: %s",
GetPlayerInfo().c_str(), channelName.c_str(), targetName.c_str());
2009-10-17 15:51:44 -07:00
if (!normalizePlayerName(targetName))
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()))
if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer()))
channel->Ban(GetPlayer(), targetName);
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void WorldSession::HandleChannelUnban(WorldPacket& recvPacket)
{
uint32 channelLength = recvPacket.ReadBits(7);
uint32 nameLength = recvPacket.ReadBits(8);
2012-11-22 15:04:59 +01:00
std::string targetName = recvPacket.ReadString(nameLength);
std::string channelName = recvPacket.ReadString(channelLength);
TC_LOG_DEBUG("chat.system", "CMSG_CHANNEL_UNBAN %s Channel: %s, Target: %s",
GetPlayerInfo().c_str(), channelName.c_str(), targetName.c_str());
2009-10-17 15:51:44 -07:00
if (!normalizePlayerName(targetName))
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()))
if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer()))
channel->UnBan(GetPlayer(), targetName);
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2009-05-31 15:56:51 -05:00
void WorldSession::HandleChannelAnnouncements(WorldPacket& recvPacket)
2008-10-02 16:23:55 -05:00
{
uint32 length = recvPacket.ReadBits(8);
2012-11-22 15:04:59 +01:00
std::string channelName = recvPacket.ReadString(length);
TC_LOG_DEBUG("chat.system", "CMSG_CHANNEL_ANNOUNCEMENTS %s Channel: %s",
GetPlayerInfo().c_str(), channelName.c_str());
2014-11-23 04:25:47 +01:00
if (ChannelMgr* cMgr = ChannelMgr::ForTeam(GetPlayer()->GetTeam()))
if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer()))
channel->Announce(GetPlayer());
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2009-05-31 15:56:51 -05:00
void WorldSession::HandleGetChannelMemberCount(WorldPacket &recvPacket)
2008-10-02 16:23:55 -05:00
{
std::string channelName;
recvPacket >> channelName;
TC_LOG_DEBUG("chat.system", "CMSG_GET_CHANNEL_MEMBER_COUNT %s Channel: %s",
GetPlayerInfo().c_str(), channelName.c_str());
2014-11-23 04:25:47 +01:00
if (ChannelMgr* cMgr = ChannelMgr::ForTeam(GetPlayer()->GetTeam()))
2008-10-02 16:23:55 -05:00
{
if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer()))
2008-10-02 16:23:55 -05:00
{
TC_LOG_DEBUG("chat.system", "SMSG_CHANNEL_MEMBER_COUNT %s Channel: %s Count: %u",
GetPlayerInfo().c_str(), channelName.c_str(), channel->GetNumPlayers());
WorldPacket data(SMSG_CHANNEL_MEMBER_COUNT, channel->GetName().size() + 1 + 4);
data << channel->GetName();
data << uint8(channel->GetFlags());
data << uint32(channel->GetNumPlayers());
2008-10-02 16:23:55 -05:00
SendPacket(&data);
}
}
}
2009-10-17 15:51:44 -07:00
2012-08-10 18:56:06 -05:00
void WorldSession::HandleSetChannelWatch(WorldPacket& recvPacket)
2008-10-02 16:23:55 -05:00
{
std::string channelName;
recvPacket >> channelName;
TC_LOG_DEBUG("chat.system", "CMSG_SET_CHANNEL_WATCH %s Channel: %s",
GetPlayerInfo().c_str(), channelName.c_str());
/*
if (ChannelMgr* cMgr = channelMgr(GetPlayer()->GetTeam()))
if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer()))
channel->JoinNotify(GetPlayer());
*/
2008-10-02 16:23:55 -05:00
}