fix(core): Cleans up uninitialized packets (#397)

- [X] Encapsulates/abstracts buffer cache checking
- [X] Changes mobile moving cache to use Span2D
This commit is contained in:
Kamron Batman 2021-01-09 14:10:29 -08:00 committed by GitHub
parent 0b9fb9c071
commit 8763be8a21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 417 additions and 529 deletions

View file

@ -56,6 +56,11 @@ namespace Server.Network
Serial serial, int graphic, MessageType type, int hue, int font, int number, string name = "", string args = ""
)
{
if (buffer[0] != 0)
{
return buffer.Length;
}
name ??= "";
args ??= "";
@ -91,7 +96,7 @@ namespace Server.Network
return;
}
Span<byte> buffer = stackalloc byte[GetMaxMessageLocalizedAffixLength(affix, args)];
Span<byte> buffer = stackalloc byte[GetMaxMessageLocalizedAffixLength(affix, args)].InitializePacket();
var length = CreateMessageLocalizedAffix(
buffer, serial, graphic, type, hue, font, number, name, affixType, affix, args
);
@ -108,6 +113,11 @@ namespace Server.Network
AffixType affixType, string affix = "", string args = ""
)
{
if (buffer[0] != 0)
{
return buffer.Length;
}
name ??= "";
affix ??= "";
args ??= "";
@ -146,7 +156,7 @@ namespace Server.Network
return;
}
Span<byte> buffer = stackalloc byte[GetMaxMessageLength(text)];
Span<byte> buffer = stackalloc byte[GetMaxMessageLength(text)].InitializePacket();
var length = CreateMessage(
buffer,
serial,
@ -179,6 +189,11 @@ namespace Server.Network
string text
)
{
if (buffer[0] != 0)
{
return buffer.Length;
}
name ??= "";
text ??= "";
lang ??= "ENU";