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
|
|
@ -16,36 +16,35 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
|
||||
namespace Server.Network
|
||||
namespace Server.Network;
|
||||
|
||||
public static class OutgoingDamagePackets
|
||||
{
|
||||
public static class OutgoingDamagePackets
|
||||
public static void SendDamage(this NetState ns, Serial serial, int amount)
|
||||
{
|
||||
public static void SendDamage(this NetState ns, Serial serial, int amount)
|
||||
if (ns.CannotSendPackets())
|
||||
{
|
||||
if (ns == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var writer = new SpanWriter(stackalloc byte[ns.DamagePacket ? 7 : 11]);
|
||||
|
||||
if (ns.DamagePacket)
|
||||
{
|
||||
writer.Write((byte)0x0B); // Packet ID
|
||||
writer.Write(serial);
|
||||
writer.Write((ushort)Math.Clamp(amount, 0, 0xFFFF));
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write((byte)0xBF); // Packet ID
|
||||
writer.Write((ushort)11); // Length
|
||||
writer.Write((ushort)0x22);
|
||||
writer.Write((byte)1);
|
||||
writer.Write(serial);
|
||||
writer.Write((byte)Math.Clamp(amount, 0, 0xFF));
|
||||
}
|
||||
|
||||
ns.Send(writer.Span);
|
||||
return;
|
||||
}
|
||||
|
||||
var writer = new SpanWriter(stackalloc byte[ns.DamagePacket ? 7 : 11]);
|
||||
|
||||
if (ns.DamagePacket)
|
||||
{
|
||||
writer.Write((byte)0x0B); // Packet ID
|
||||
writer.Write(serial);
|
||||
writer.Write((ushort)Math.Clamp(amount, 0, 0xFFFF));
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write((byte)0xBF); // Packet ID
|
||||
writer.Write((ushort)11); // Length
|
||||
writer.Write((ushort)0x22);
|
||||
writer.Write((byte)1);
|
||||
writer.Write(serial);
|
||||
writer.Write((byte)Math.Clamp(amount, 0, 0xFF));
|
||||
}
|
||||
|
||||
ns.Send(writer.Span);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue