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:
Kamron Batman 2022-02-27 00:13:49 -08:00 committed by GitHub
parent 5db8b1354c
commit 941452de4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
58 changed files with 5510 additions and 5537 deletions

View file

@ -16,56 +16,55 @@
using System.Buffers;
using Server.Targeting;
namespace Server.Network
namespace Server.Network;
public static class OutgoingTargetPackets
{
public static class OutgoingTargetPackets
public static void SendMultiTargetReq(this NetState ns, MultiTarget t)
{
public static void SendMultiTargetReq(this NetState ns, MultiTarget t)
if (ns.CannotSendPackets())
{
if (ns == null)
{
return;
}
var writer = new SpanWriter(stackalloc byte[ns.HighSeas ? 30 : 26]);
writer.Write((byte)0x99); // Packet ID
writer.Write(t.AllowGround);
writer.Write(t.TargetID);
writer.Write((byte)t.Flags);
writer.Clear(11);
writer.Write((short)t.MultiID);
writer.Write((short)t.Offset.X);
writer.Write((short)t.Offset.Y);
writer.Write((short)t.Offset.Z);
if (ns.HighSeas)
{
writer.Write(0);
}
ns.Send(writer.Span);
return;
}
public static void SendCancelTarget(this NetState ns) =>
ns?.Send(stackalloc byte[]
{
0x6C, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
});
public static void SendTargetReq(this NetState ns, Target t)
var writer = new SpanWriter(stackalloc byte[ns.HighSeas ? 30 : 26]);
writer.Write((byte)0x99); // Packet ID
writer.Write(t.AllowGround);
writer.Write(t.TargetID);
writer.Write((byte)t.Flags);
writer.Clear(11);
writer.Write((short)t.MultiID);
writer.Write((short)t.Offset.X);
writer.Write((short)t.Offset.Y);
writer.Write((short)t.Offset.Z);
if (ns.HighSeas)
{
if (ns == null)
{
return;
}
var writer = new SpanWriter(stackalloc byte[19]);
writer.Write((byte)0x6C); // Packet ID
writer.Write(t.AllowGround);
writer.Write(t.TargetID);
writer.Write((byte)t.Flags);
writer.Clear(12);
ns.Send(writer.Span);
writer.Write(0);
}
ns.Send(writer.Span);
}
public static void SendCancelTarget(this NetState ns) =>
ns?.Send(stackalloc byte[]
{
0x6C, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
});
public static void SendTargetReq(this NetState ns, Target t)
{
if (ns.CannotSendPackets())
{
return;
}
var writer = new SpanWriter(stackalloc byte[19]);
writer.Write((byte)0x6C); // Packet ID
writer.Write(t.AllowGround);
writer.Write(t.TargetID);
writer.Write((byte)t.Flags);
writer.Clear(12);
ns.Send(writer.Span);
}
}