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,159 +17,158 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using Server.Items;
|
||||
|
||||
namespace Server.Network
|
||||
namespace Server.Network;
|
||||
|
||||
public static class IncomingItemPackets
|
||||
{
|
||||
public static class IncomingItemPackets
|
||||
public static void Configure()
|
||||
{
|
||||
public static void Configure()
|
||||
IncomingPackets.Register(0x07, 7, true, LiftReq);
|
||||
IncomingPackets.Register(0x08, 15, true, DropReq);
|
||||
IncomingPackets.Register(0x13, 10, true, EquipReq);
|
||||
IncomingPackets.Register(0xEC, 0, false, EquipMacro);
|
||||
IncomingPackets.Register(0xED, 0, false, UnequipMacro);
|
||||
}
|
||||
|
||||
public static void LiftReq(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
var serial = (Serial)reader.ReadUInt32();
|
||||
int amount = reader.ReadUInt16();
|
||||
var item = World.FindItem(serial);
|
||||
|
||||
state.Mobile.Lift(item, amount, out _, out _);
|
||||
}
|
||||
|
||||
public static void EquipReq(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
var item = from.Holding;
|
||||
|
||||
var valid = item != null && item.HeldBy == from && item.Map == Map.Internal;
|
||||
|
||||
from.Holding = null;
|
||||
|
||||
if (!valid)
|
||||
{
|
||||
IncomingPackets.Register(0x07, 7, true, LiftReq);
|
||||
IncomingPackets.Register(0x08, 15, true, DropReq);
|
||||
IncomingPackets.Register(0x13, 10, true, EquipReq);
|
||||
IncomingPackets.Register(0xEC, 0, false, EquipMacro);
|
||||
IncomingPackets.Register(0xED, 0, false, UnequipMacro);
|
||||
return;
|
||||
}
|
||||
|
||||
public static void LiftReq(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
var serial = (Serial)reader.ReadUInt32();
|
||||
int amount = reader.ReadUInt16();
|
||||
var item = World.FindItem(serial);
|
||||
reader.Seek(5, SeekOrigin.Current);
|
||||
var to = World.FindMobile((Serial)reader.ReadUInt32()) ?? from;
|
||||
|
||||
state.Mobile.Lift(item, amount, out _, out _);
|
||||
if (!to.AllowEquipFrom(from) || !to.EquipItem(item))
|
||||
{
|
||||
item.Bounce(from);
|
||||
}
|
||||
|
||||
public static void EquipReq(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
item.ClearBounce();
|
||||
}
|
||||
|
||||
public static void DropReq(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
reader.ReadInt32(); // serial, ignored
|
||||
int x = reader.ReadInt16();
|
||||
int y = reader.ReadInt16();
|
||||
int z = reader.ReadSByte();
|
||||
if (state.ContainerGridLines)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
var item = from.Holding;
|
||||
|
||||
var valid = item != null && item.HeldBy == from && item.Map == Map.Internal;
|
||||
|
||||
from.Holding = null;
|
||||
|
||||
if (!valid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
reader.Seek(5, SeekOrigin.Current);
|
||||
var to = World.FindMobile((Serial)reader.ReadUInt32()) ?? from;
|
||||
|
||||
if (!to.AllowEquipFrom(from) || !to.EquipItem(item))
|
||||
{
|
||||
item.Bounce(from);
|
||||
}
|
||||
|
||||
item.ClearBounce();
|
||||
}
|
||||
|
||||
public static void DropReq(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
reader.ReadInt32(); // serial, ignored
|
||||
int x = reader.ReadInt16();
|
||||
int y = reader.ReadInt16();
|
||||
int z = reader.ReadSByte();
|
||||
if (state.ContainerGridLines)
|
||||
{
|
||||
reader.ReadByte(); // Grid Location?
|
||||
}
|
||||
else
|
||||
{
|
||||
packetLength -= 1;
|
||||
}
|
||||
|
||||
Serial dest = (Serial)reader.ReadUInt32();
|
||||
|
||||
var loc = new Point3D(x, y, z);
|
||||
|
||||
var from = state.Mobile;
|
||||
|
||||
if (dest.IsMobile)
|
||||
{
|
||||
from.Drop(World.FindMobile(dest), loc);
|
||||
}
|
||||
else if (dest.IsItem)
|
||||
{
|
||||
var item = World.FindItem(dest);
|
||||
|
||||
if (item is BaseMulti multi && multi.AllowsRelativeDrop)
|
||||
{
|
||||
loc.m_X += multi.X;
|
||||
loc.m_Y += multi.Y;
|
||||
from.Drop(loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
from.Drop(item, loc);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
from.Drop(loc);
|
||||
}
|
||||
}
|
||||
|
||||
public static void DropReq6017(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
reader.ReadInt32(); // serial, ignored
|
||||
int x = reader.ReadInt16();
|
||||
int y = reader.ReadInt16();
|
||||
int z = reader.ReadSByte();
|
||||
reader.ReadByte(); // Grid Location?
|
||||
Serial dest = (Serial)reader.ReadUInt32();
|
||||
}
|
||||
else
|
||||
{
|
||||
packetLength -= 1;
|
||||
}
|
||||
|
||||
var loc = new Point3D(x, y, z);
|
||||
Serial dest = (Serial)reader.ReadUInt32();
|
||||
|
||||
var from = state.Mobile;
|
||||
var loc = new Point3D(x, y, z);
|
||||
|
||||
if (dest.IsMobile)
|
||||
var from = state.Mobile;
|
||||
|
||||
if (dest.IsMobile)
|
||||
{
|
||||
from.Drop(World.FindMobile(dest), loc);
|
||||
}
|
||||
else if (dest.IsItem)
|
||||
{
|
||||
var item = World.FindItem(dest);
|
||||
|
||||
if (item is BaseMulti multi && multi.AllowsRelativeDrop)
|
||||
{
|
||||
from.Drop(World.FindMobile(dest), loc);
|
||||
}
|
||||
else if (dest.IsItem)
|
||||
{
|
||||
var item = World.FindItem(dest);
|
||||
|
||||
if (item is BaseMulti multi && multi.AllowsRelativeDrop)
|
||||
{
|
||||
loc.m_X += multi.X;
|
||||
loc.m_Y += multi.Y;
|
||||
from.Drop(loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
from.Drop(item, loc);
|
||||
}
|
||||
loc.m_X += multi.X;
|
||||
loc.m_Y += multi.Y;
|
||||
from.Drop(loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
from.Drop(loc);
|
||||
from.Drop(item, loc);
|
||||
}
|
||||
}
|
||||
|
||||
public static void EquipMacro(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
else
|
||||
{
|
||||
int count = reader.ReadByte();
|
||||
var serialList = new List<Serial>(count);
|
||||
for (var i = 0; i < count; ++i)
|
||||
{
|
||||
serialList.Add((Serial)reader.ReadUInt32());
|
||||
}
|
||||
|
||||
EventSink.InvokeEquipMacro(state.Mobile, serialList);
|
||||
}
|
||||
|
||||
public static void UnequipMacro(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
int count = reader.ReadByte();
|
||||
var layers = new List<Layer>(count);
|
||||
for (var i = 0; i < count; ++i)
|
||||
{
|
||||
layers.Add((Layer)reader.ReadUInt16());
|
||||
}
|
||||
|
||||
EventSink.InvokeUnequipMacro(state.Mobile, layers);
|
||||
from.Drop(loc);
|
||||
}
|
||||
}
|
||||
|
||||
public static void DropReq6017(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
reader.ReadInt32(); // serial, ignored
|
||||
int x = reader.ReadInt16();
|
||||
int y = reader.ReadInt16();
|
||||
int z = reader.ReadSByte();
|
||||
reader.ReadByte(); // Grid Location?
|
||||
Serial dest = (Serial)reader.ReadUInt32();
|
||||
|
||||
var loc = new Point3D(x, y, z);
|
||||
|
||||
var from = state.Mobile;
|
||||
|
||||
if (dest.IsMobile)
|
||||
{
|
||||
from.Drop(World.FindMobile(dest), loc);
|
||||
}
|
||||
else if (dest.IsItem)
|
||||
{
|
||||
var item = World.FindItem(dest);
|
||||
|
||||
if (item is BaseMulti multi && multi.AllowsRelativeDrop)
|
||||
{
|
||||
loc.m_X += multi.X;
|
||||
loc.m_Y += multi.Y;
|
||||
from.Drop(loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
from.Drop(item, loc);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
from.Drop(loc);
|
||||
}
|
||||
}
|
||||
|
||||
public static void EquipMacro(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
int count = reader.ReadByte();
|
||||
var serialList = new List<Serial>(count);
|
||||
for (var i = 0; i < count; ++i)
|
||||
{
|
||||
serialList.Add((Serial)reader.ReadUInt32());
|
||||
}
|
||||
|
||||
EventSink.InvokeEquipMacro(state.Mobile, serialList);
|
||||
}
|
||||
|
||||
public static void UnequipMacro(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
int count = reader.ReadByte();
|
||||
var layers = new List<Layer>(count);
|
||||
for (var i = 0; i < count; ++i)
|
||||
{
|
||||
layers.Add((Layer)reader.ReadUInt16());
|
||||
}
|
||||
|
||||
EventSink.InvokeUnequipMacro(state.Mobile, layers);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue