fix: Stops creating blocked packets entirely (#944)
Optimizes larger servers where users are logging in and packets are being created for no reason.
This commit is contained in:
parent
5db8b1354c
commit
941452de4a
58 changed files with 5510 additions and 5537 deletions
|
|
@ -15,146 +15,145 @@
|
|||
|
||||
using System;
|
||||
|
||||
namespace Server.Network
|
||||
namespace Server.Network;
|
||||
|
||||
[Flags]
|
||||
public enum MessageType
|
||||
{
|
||||
[Flags]
|
||||
public enum MessageType
|
||||
Regular = 0x00,
|
||||
System = 0x01,
|
||||
Emote = 0x02,
|
||||
Label = 0x06,
|
||||
Focus = 0x07,
|
||||
Whisper = 0x08,
|
||||
Yell = 0x09,
|
||||
Spell = 0x0A,
|
||||
|
||||
Guild = 0x0D,
|
||||
Alliance = 0x0E,
|
||||
Command = 0x0F,
|
||||
|
||||
Encoded = 0xC0
|
||||
}
|
||||
|
||||
public static class IncomingMessagePackets
|
||||
{
|
||||
private static readonly KeywordList m_KeywordList = new();
|
||||
|
||||
public static void Configure()
|
||||
{
|
||||
Regular = 0x00,
|
||||
System = 0x01,
|
||||
Emote = 0x02,
|
||||
Label = 0x06,
|
||||
Focus = 0x07,
|
||||
Whisper = 0x08,
|
||||
Yell = 0x09,
|
||||
Spell = 0x0A,
|
||||
|
||||
Guild = 0x0D,
|
||||
Alliance = 0x0E,
|
||||
Command = 0x0F,
|
||||
|
||||
Encoded = 0xC0
|
||||
IncomingPackets.Register(0x03, 0, true, AsciiSpeech);
|
||||
IncomingPackets.Register(0xAD, 0, true, UnicodeSpeech);
|
||||
}
|
||||
|
||||
public static class IncomingMessagePackets
|
||||
public static void AsciiSpeech(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
private static readonly KeywordList m_KeywordList = new();
|
||||
var from = state.Mobile;
|
||||
|
||||
public static void Configure()
|
||||
if (from == null)
|
||||
{
|
||||
IncomingPackets.Register(0x03, 0, true, AsciiSpeech);
|
||||
IncomingPackets.Register(0xAD, 0, true, UnicodeSpeech);
|
||||
return;
|
||||
}
|
||||
|
||||
public static void AsciiSpeech(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
var type = (MessageType)reader.ReadByte();
|
||||
int hue = reader.ReadInt16();
|
||||
reader.ReadInt16(); // font
|
||||
var text = reader.ReadAsciiSafe().Trim();
|
||||
|
||||
if (text.Length is <= 0 or > 128)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
|
||||
if (from == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var type = (MessageType)reader.ReadByte();
|
||||
int hue = reader.ReadInt16();
|
||||
reader.ReadInt16(); // font
|
||||
var text = reader.ReadAsciiSafe().Trim();
|
||||
|
||||
if (text.Length is <= 0 or > 128)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Enum.IsDefined(typeof(MessageType), type))
|
||||
{
|
||||
type = MessageType.Regular;
|
||||
}
|
||||
|
||||
from.DoSpeech(text, Array.Empty<int>(), type, Utility.ClipDyedHue(hue));
|
||||
return;
|
||||
}
|
||||
|
||||
public static void UnicodeSpeech(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
if (!Enum.IsDefined(typeof(MessageType), type))
|
||||
{
|
||||
var from = state.Mobile;
|
||||
type = MessageType.Regular;
|
||||
}
|
||||
|
||||
if (from == null)
|
||||
from.DoSpeech(text, Array.Empty<int>(), type, Utility.ClipDyedHue(hue));
|
||||
}
|
||||
|
||||
public static void UnicodeSpeech(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
|
||||
if (from == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var type = (MessageType)reader.ReadByte();
|
||||
int hue = reader.ReadInt16();
|
||||
reader.ReadInt16(); // font
|
||||
var lang = reader.ReadAscii(4);
|
||||
string text;
|
||||
|
||||
var isEncoded = (type & MessageType.Encoded) != 0;
|
||||
int[] keywords;
|
||||
|
||||
if (isEncoded)
|
||||
{
|
||||
int value = reader.ReadInt16();
|
||||
var count = (value & 0xFFF0) >> 4;
|
||||
var hold = value & 0xF;
|
||||
|
||||
if (count is < 0 or > 50)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var type = (MessageType)reader.ReadByte();
|
||||
int hue = reader.ReadInt16();
|
||||
reader.ReadInt16(); // font
|
||||
var lang = reader.ReadAscii(4);
|
||||
string text;
|
||||
var keyList = m_KeywordList;
|
||||
|
||||
var isEncoded = (type & MessageType.Encoded) != 0;
|
||||
int[] keywords;
|
||||
|
||||
if (isEncoded)
|
||||
for (var i = 0; i < count; ++i)
|
||||
{
|
||||
int value = reader.ReadInt16();
|
||||
var count = (value & 0xFFF0) >> 4;
|
||||
var hold = value & 0xF;
|
||||
int speechID;
|
||||
|
||||
if (count is < 0 or > 50)
|
||||
if ((i & 1) == 0)
|
||||
{
|
||||
return;
|
||||
hold <<= 8;
|
||||
hold |= reader.ReadByte();
|
||||
speechID = hold;
|
||||
hold = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = reader.ReadInt16();
|
||||
speechID = (value & 0xFFF0) >> 4;
|
||||
hold = value & 0xF;
|
||||
}
|
||||
|
||||
var keyList = m_KeywordList;
|
||||
|
||||
for (var i = 0; i < count; ++i)
|
||||
if (!keyList.Contains(speechID))
|
||||
{
|
||||
int speechID;
|
||||
|
||||
if ((i & 1) == 0)
|
||||
{
|
||||
hold <<= 8;
|
||||
hold |= reader.ReadByte();
|
||||
speechID = hold;
|
||||
hold = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = reader.ReadInt16();
|
||||
speechID = (value & 0xFFF0) >> 4;
|
||||
hold = value & 0xF;
|
||||
}
|
||||
|
||||
if (!keyList.Contains(speechID))
|
||||
{
|
||||
keyList.Add(speechID);
|
||||
}
|
||||
keyList.Add(speechID);
|
||||
}
|
||||
|
||||
text = reader.ReadUTF8Safe();
|
||||
|
||||
keywords = keyList.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
text = reader.ReadBigUniSafe();
|
||||
|
||||
keywords = Array.Empty<int>();
|
||||
}
|
||||
|
||||
text = text.Trim();
|
||||
text = reader.ReadUTF8Safe();
|
||||
|
||||
if (text.Length is <= 0 or > 128)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
type &= ~MessageType.Encoded;
|
||||
|
||||
if (!Enum.IsDefined(typeof(MessageType), type))
|
||||
{
|
||||
type = MessageType.Regular;
|
||||
}
|
||||
|
||||
from.Language = lang;
|
||||
from.DoSpeech(text, keywords, type, Utility.ClipDyedHue(hue));
|
||||
keywords = keyList.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
text = reader.ReadBigUniSafe();
|
||||
|
||||
keywords = Array.Empty<int>();
|
||||
}
|
||||
|
||||
text = text.Trim();
|
||||
|
||||
if (text.Length is <= 0 or > 128)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
type &= ~MessageType.Encoded;
|
||||
|
||||
if (!Enum.IsDefined(typeof(MessageType), type))
|
||||
{
|
||||
type = MessageType.Regular;
|
||||
}
|
||||
|
||||
from.Language = lang;
|
||||
from.DoSpeech(text, keywords, type, Utility.ClipDyedHue(hue));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue