Core/Chat: Fixed chat channel name validation
Port From (https://github.com/TrinityCore/TrinityCore/commit/cf525beefd3c12e07b0883963806f202a6daff60)
This commit is contained in:
@@ -44,7 +44,7 @@ namespace Game.Chat
|
|||||||
uint oldMSTime = Time.GetMSTime();
|
uint oldMSTime = Time.GetMSTime();
|
||||||
uint days = WorldConfig.GetUIntValue(WorldCfg.PreserveCustomChannelDuration);
|
uint days = WorldConfig.GetUIntValue(WorldCfg.PreserveCustomChannelDuration);
|
||||||
if (days != 0)
|
if (days != 0)
|
||||||
{
|
{
|
||||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_OLD_CHANNELS);
|
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_OLD_CHANNELS);
|
||||||
stmt.AddValue(0, days * Time.Day);
|
stmt.AddValue(0, days * Time.Day);
|
||||||
DB.Characters.Execute(stmt);
|
DB.Characters.Execute(stmt);
|
||||||
@@ -86,7 +86,7 @@ namespace Game.Chat
|
|||||||
} while (result.NextRow());
|
} while (result.NextRow());
|
||||||
|
|
||||||
foreach (var (name, team) in toDelete)
|
foreach (var (name, team) in toDelete)
|
||||||
{
|
{
|
||||||
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_CHANNEL);
|
PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_CHANNEL);
|
||||||
stmt.AddValue(0, name);
|
stmt.AddValue(0, name);
|
||||||
stmt.AddValue(1, (uint)team);
|
stmt.AddValue(1, (uint)team);
|
||||||
@@ -165,7 +165,7 @@ namespace Game.Chat
|
|||||||
{
|
{
|
||||||
return _customChannels.LookupByKey(name.ToLower());
|
return _customChannels.LookupByKey(name.ToLower());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Channel GetChannel(uint channelId, string name, Player player, bool notify = true, AreaTableRecord zoneEntry = null)
|
public Channel GetChannel(uint channelId, string name, Player player, bool notify = true, AreaTableRecord zoneEntry = null)
|
||||||
{
|
{
|
||||||
Channel result = null;
|
Channel result = null;
|
||||||
|
|||||||
@@ -41,51 +41,45 @@ namespace Game
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packet.ChannelName.IsEmpty() || char.IsDigit(packet.ChannelName[0]))
|
|
||||||
{
|
|
||||||
ChannelNotify channelNotify = new();
|
|
||||||
channelNotify.Type = ChatNotify.InvalidNameNotice;
|
|
||||||
channelNotify.Channel = packet.ChannelName;
|
|
||||||
SendPacket(channelNotify);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (packet.Password.Length > 127)
|
|
||||||
{
|
|
||||||
Log.outError(LogFilter.Network, $"Player {GetPlayer().GetGUID()} tried to create a channel with a password more than 127 characters long - blocked");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ChannelManager cMgr = ChannelManager.ForTeam(GetPlayer().GetTeam());
|
ChannelManager cMgr = ChannelManager.ForTeam(GetPlayer().GetTeam());
|
||||||
if (cMgr != null)
|
if (cMgr == null)
|
||||||
{
|
return;
|
||||||
if (packet.ChatChannelId != 0)
|
|
||||||
|
if (packet.ChatChannelId != 0)
|
||||||
|
{ // system channel
|
||||||
|
Channel channel = cMgr.GetSystemChannel((uint)packet.ChatChannelId, zone);
|
||||||
|
if (channel != null)
|
||||||
|
channel.JoinChannel(GetPlayer());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // custom channel
|
||||||
|
if (packet.ChannelName.IsEmpty() || Char.IsDigit(packet.ChannelName[0]))
|
||||||
{
|
{
|
||||||
// system channel
|
ChannelNotify channelNotify = new();
|
||||||
Channel channel = cMgr.GetSystemChannel((uint)packet.ChatChannelId, zone);
|
channelNotify.Type = ChatNotify.InvalidNameNotice;
|
||||||
if (channel != null)
|
channelNotify.Channel = packet.ChannelName;
|
||||||
channel.JoinChannel(GetPlayer());
|
SendPacket(channelNotify);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (packet.Password.Length > 127)
|
||||||
|
{
|
||||||
|
Log.outError(LogFilter.Network, $"Player {GetPlayer().GetGUID()} tried to create a channel with a password more than {127} characters long - blocked");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!DisallowHyperlinksAndMaybeKick(packet.ChannelName))
|
||||||
|
return;
|
||||||
|
|
||||||
|
Channel channel = cMgr.GetCustomChannel(packet.ChannelName);
|
||||||
|
if (channel != null)
|
||||||
|
channel.JoinChannel(GetPlayer(), packet.Password);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// custom channel
|
channel = cMgr.CreateCustomChannel(packet.ChannelName);
|
||||||
if (packet.ChannelName.Length > 31)
|
|
||||||
{
|
|
||||||
Log.outError(LogFilter.Network, $"Player {GetPlayer().GetGUID()} tried to create a channel with a name more than 31 characters long - blocked");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Channel channel = cMgr.GetCustomChannel(packet.ChannelName);
|
|
||||||
if (channel != null)
|
if (channel != null)
|
||||||
channel.JoinChannel(GetPlayer(), packet.Password);
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
channel = cMgr.CreateCustomChannel(packet.ChannelName);
|
channel.SetPassword(packet.Password);
|
||||||
if (channel != null)
|
channel.JoinChannel(GetPlayer(), packet.Password);
|
||||||
{
|
|
||||||
channel.SetPassword(packet.Password);
|
|
||||||
channel.JoinChannel(GetPlayer(), packet.Password);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user