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

@ -17,111 +17,110 @@ using System.Buffers;
using System.Collections.Generic;
using Server.Items;
namespace Server.Network
namespace Server.Network;
public static class OutgoingVendorBuyPackets
{
public static class OutgoingVendorBuyPackets
public static void SendVendorBuyContent(this NetState ns, List<BuyItemState> list)
{
public static void SendVendorBuyContent(this NetState ns, List<BuyItemState> list)
if (ns.CannotSendPackets())
{
if (ns == null)
{
return;
}
var length = 5 + list.Count * (ns.ContainerGridLines ? 20 : 19);
var writer = new SpanWriter(stackalloc byte[length]);
writer.Write((byte)0x3C); // Packet ID
writer.Write((ushort)length);
writer.Write((short)list.Count);
for (var i = list.Count - 1; i >= 0; --i)
{
var bis = list[i];
writer.Write(bis.MySerial);
writer.Write((ushort)bis.ItemID);
writer.Write((byte)0); // itemID offset
writer.Write((ushort)bis.Amount);
writer.Write((short)(i + 1)); // x
writer.Write((short)1); // y
if (ns.ContainerGridLines)
{
writer.Write((byte)0); // Grid Location?
}
writer.Write(bis.ContainerSerial);
writer.Write((ushort)bis.Hue);
}
ns.Send(writer.Span);
return;
}
public static void SendDisplayBuyList(this NetState ns, Serial vendor)
var length = 5 + list.Count * (ns.ContainerGridLines ? 20 : 19);
var writer = new SpanWriter(stackalloc byte[length]);
writer.Write((byte)0x3C); // Packet ID
writer.Write((ushort)length);
writer.Write((short)list.Count);
for (var i = list.Count - 1; i >= 0; --i)
{
if (ns == null)
{
return;
}
var bis = list[i];
var writer = new SpanWriter(stackalloc byte[ns.HighSeas ? 9 : 7]);
writer.Write((byte)0x24); // Packet ID
writer.Write(vendor);
writer.Write((short)0x30); // Vendor Buy Window
if (ns.HighSeas)
writer.Write(bis.MySerial);
writer.Write((ushort)bis.ItemID);
writer.Write((byte)0); // itemID offset
writer.Write((ushort)bis.Amount);
writer.Write((short)(i + 1)); // x
writer.Write((short)1); // y
if (ns.ContainerGridLines)
{
writer.Write((short)0x0);
writer.Write((byte)0); // Grid Location?
}
ns.Send(writer.Span);
writer.Write(bis.ContainerSerial);
writer.Write((ushort)bis.Hue);
}
public static void SendVendorBuyList(this NetState ns, Mobile vendor, List<BuyItemState> list)
ns.Send(writer.Span);
}
public static void SendDisplayBuyList(this NetState ns, Serial vendor)
{
if (ns.CannotSendPackets())
{
if (ns == null)
{
return;
}
var length = 8;
for (int i = 0; i < list.Count; i++)
{
length += 6 + list[i].Description?.Length ?? 0;
}
var writer = new SpanWriter(stackalloc byte[length]);
writer.Write((byte)0x74); // Packet ID
writer.Write((ushort)length);
writer.Write((vendor.FindItemOnLayer(Layer.ShopBuy) as Container)?.Serial ?? Serial.MinusOne);
writer.Write((byte)list.Count);
for (var i = 0; i < list.Count; ++i)
{
var bis = list[i];
writer.Write(bis.Price);
var desc = bis.Description ?? "";
writer.Write((byte)(desc.Length + 1));
writer.WriteAsciiNull(desc);
}
ns.Send(writer.Span);
return;
}
public static void SendEndVendorBuy(this NetState ns, Serial vendor)
var writer = new SpanWriter(stackalloc byte[ns.HighSeas ? 9 : 7]);
writer.Write((byte)0x24); // Packet ID
writer.Write(vendor);
writer.Write((short)0x30); // Vendor Buy Window
if (ns.HighSeas)
{
if (ns == null)
{
return;
}
var writer = new SpanWriter(stackalloc byte[8]);
writer.Write((byte)0x3B); // Packet ID
writer.Write((ushort)8);
writer.Write(vendor);
writer.Write((byte)0); // Buy count
ns.Send(writer.Span);
writer.Write((short)0x0);
}
ns.Send(writer.Span);
}
public static void SendVendorBuyList(this NetState ns, Mobile vendor, List<BuyItemState> list)
{
if (ns.CannotSendPackets())
{
return;
}
var length = 8;
for (int i = 0; i < list.Count; i++)
{
length += 6 + list[i].Description?.Length ?? 0;
}
var writer = new SpanWriter(stackalloc byte[length]);
writer.Write((byte)0x74); // Packet ID
writer.Write((ushort)length);
writer.Write((vendor.FindItemOnLayer(Layer.ShopBuy) as Container)?.Serial ?? Serial.MinusOne);
writer.Write((byte)list.Count);
for (var i = 0; i < list.Count; ++i)
{
var bis = list[i];
writer.Write(bis.Price);
var desc = bis.Description ?? "";
writer.Write((byte)(desc.Length + 1));
writer.WriteAsciiNull(desc);
}
ns.Send(writer.Span);
}
public static void SendEndVendorBuy(this NetState ns, Serial vendor)
{
if (ns.CannotSendPackets())
{
return;
}
var writer = new SpanWriter(stackalloc byte[8]);
writer.Write((byte)0x3B); // Packet ID
writer.Write((ushort)8);
writer.Write(vendor);
writer.Write((byte)0); // Buy count
ns.Send(writer.Span);
}
}