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
|
|
@ -17,108 +17,107 @@ using System;
|
|||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Server.Network
|
||||
namespace Server.Network;
|
||||
|
||||
public class EquipInfoAttribute
|
||||
{
|
||||
public class EquipInfoAttribute
|
||||
public EquipInfoAttribute(int number, int charges = -1)
|
||||
{
|
||||
public EquipInfoAttribute(int number, int charges = -1)
|
||||
{
|
||||
Number = number;
|
||||
Charges = charges;
|
||||
}
|
||||
|
||||
public int Number { get; }
|
||||
|
||||
public int Charges { get; }
|
||||
Number = number;
|
||||
Charges = charges;
|
||||
}
|
||||
|
||||
public static class OutgoingEquipmentPackets
|
||||
public int Number { get; }
|
||||
|
||||
public int Charges { get; }
|
||||
}
|
||||
|
||||
public static class OutgoingEquipmentPackets
|
||||
{
|
||||
public static void SendDisplayEquipmentInfo(
|
||||
this NetState ns,
|
||||
Serial serial, int number, string crafterName, bool unidentified, List<EquipInfoAttribute> attrs
|
||||
)
|
||||
{
|
||||
public static void SendDisplayEquipmentInfo(
|
||||
this NetState ns,
|
||||
Serial serial, int number, string crafterName, bool unidentified, List<EquipInfoAttribute> attrs
|
||||
)
|
||||
if (ns.CannotSendPackets())
|
||||
{
|
||||
if (ns == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
crafterName = crafterName.DefaultIfNullOrEmpty("");
|
||||
|
||||
var length = 17 +
|
||||
(crafterName.Length > 0 ? 6 + crafterName.Length : 0) +
|
||||
(unidentified ? 4 : 0) +
|
||||
attrs.Count * 6;
|
||||
|
||||
var writer = new SpanWriter(stackalloc byte[length]);
|
||||
writer.Write((byte)0xBF); // Packet ID
|
||||
writer.Write((ushort)length);
|
||||
writer.Write((ushort)0x10); // Subpacket
|
||||
writer.Write(serial);
|
||||
writer.Write(number);
|
||||
|
||||
if (crafterName.Length > 0)
|
||||
{
|
||||
writer.Write(-3); // crafted by
|
||||
|
||||
writer.Write((ushort)crafterName.Length);
|
||||
writer.WriteAscii(crafterName);
|
||||
}
|
||||
|
||||
if (unidentified)
|
||||
{
|
||||
writer.Write(-4);
|
||||
}
|
||||
|
||||
for (var i = 0; i < attrs.Count; ++i)
|
||||
{
|
||||
var attr = attrs[i];
|
||||
writer.Write(attr.Number);
|
||||
writer.Write((short)attr.Charges);
|
||||
}
|
||||
|
||||
writer.Write(-1);
|
||||
|
||||
ns.Send(writer.Span);
|
||||
return;
|
||||
}
|
||||
|
||||
public static void SendEquipUpdate(this NetState ns, Item item)
|
||||
crafterName = crafterName.DefaultIfNullOrEmpty("");
|
||||
|
||||
var length = 17 +
|
||||
(crafterName.Length > 0 ? 6 + crafterName.Length : 0) +
|
||||
(unidentified ? 4 : 0) +
|
||||
attrs.Count * 6;
|
||||
|
||||
var writer = new SpanWriter(stackalloc byte[length]);
|
||||
writer.Write((byte)0xBF); // Packet ID
|
||||
writer.Write((ushort)length);
|
||||
writer.Write((ushort)0x10); // Subpacket
|
||||
writer.Write(serial);
|
||||
writer.Write(number);
|
||||
|
||||
if (crafterName.Length > 0)
|
||||
{
|
||||
if (ns == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
writer.Write(-3); // crafted by
|
||||
|
||||
Serial parentSerial;
|
||||
|
||||
var parent = item.Parent as Mobile;
|
||||
var hue = item.Hue;
|
||||
|
||||
if (parent != null)
|
||||
{
|
||||
parentSerial = parent.Serial;
|
||||
|
||||
if (parent.SolidHueOverride >= 0)
|
||||
{
|
||||
hue = parent.SolidHueOverride;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Warning: EquipUpdate on item with !(parent is Mobile)");
|
||||
parentSerial = Serial.Zero;
|
||||
}
|
||||
|
||||
var writer = new SpanWriter(stackalloc byte[15]);
|
||||
writer.Write((byte)0x2E); // Packet ID
|
||||
writer.Write(item.Serial);
|
||||
writer.Write((short)item.ItemID);
|
||||
writer.Write((ushort)item.Layer);
|
||||
writer.Write(parentSerial);
|
||||
writer.Write((short)hue);
|
||||
|
||||
ns.Send(writer.Span);
|
||||
writer.Write((ushort)crafterName.Length);
|
||||
writer.WriteAscii(crafterName);
|
||||
}
|
||||
|
||||
if (unidentified)
|
||||
{
|
||||
writer.Write(-4);
|
||||
}
|
||||
|
||||
for (var i = 0; i < attrs.Count; ++i)
|
||||
{
|
||||
var attr = attrs[i];
|
||||
writer.Write(attr.Number);
|
||||
writer.Write((short)attr.Charges);
|
||||
}
|
||||
|
||||
writer.Write(-1);
|
||||
|
||||
ns.Send(writer.Span);
|
||||
}
|
||||
|
||||
public static void SendEquipUpdate(this NetState ns, Item item)
|
||||
{
|
||||
if (ns.CannotSendPackets())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Serial parentSerial;
|
||||
|
||||
var parent = item.Parent as Mobile;
|
||||
var hue = item.Hue;
|
||||
|
||||
if (parent != null)
|
||||
{
|
||||
parentSerial = parent.Serial;
|
||||
|
||||
if (parent.SolidHueOverride >= 0)
|
||||
{
|
||||
hue = parent.SolidHueOverride;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Warning: EquipUpdate on item with !(parent is Mobile)");
|
||||
parentSerial = Serial.Zero;
|
||||
}
|
||||
|
||||
var writer = new SpanWriter(stackalloc byte[15]);
|
||||
writer.Write((byte)0x2E); // Packet ID
|
||||
writer.Write(item.Serial);
|
||||
writer.Write((short)item.ItemID);
|
||||
writer.Write((ushort)item.Layer);
|
||||
writer.Write(parentSerial);
|
||||
writer.Write((short)hue);
|
||||
|
||||
ns.Send(writer.Span);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue