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
|
|
@ -13,97 +13,160 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
namespace Server.Network
|
||||
namespace Server.Network;
|
||||
|
||||
public static class IncomingEntityPackets
|
||||
{
|
||||
public static class IncomingEntityPackets
|
||||
public static bool SingleClickProps { get; set; }
|
||||
|
||||
public static void Configure()
|
||||
{
|
||||
public static bool SingleClickProps { get; set; }
|
||||
IncomingPackets.Register(0x06, 5, true, UseReq);
|
||||
IncomingPackets.Register(0x09, 5, true, LookReq);
|
||||
IncomingPackets.Register(0xB6, 9, true, ObjectHelpRequest);
|
||||
IncomingPackets.Register(0xD6, 0, true, BatchQueryProperties);
|
||||
}
|
||||
|
||||
public static void Configure()
|
||||
public static void ObjectHelpRequest(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
|
||||
var serial = (Serial)reader.ReadUInt32();
|
||||
int unk = reader.ReadByte();
|
||||
var lang = reader.ReadAscii(3);
|
||||
|
||||
if (serial.IsItem)
|
||||
{
|
||||
IncomingPackets.Register(0x06, 5, true, UseReq);
|
||||
IncomingPackets.Register(0x09, 5, true, LookReq);
|
||||
IncomingPackets.Register(0xB6, 9, true, ObjectHelpRequest);
|
||||
IncomingPackets.Register(0xD6, 0, true, BatchQueryProperties);
|
||||
}
|
||||
var item = World.FindItem(serial);
|
||||
|
||||
public static void ObjectHelpRequest(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
|
||||
var serial = (Serial)reader.ReadUInt32();
|
||||
int unk = reader.ReadByte();
|
||||
var lang = reader.ReadAscii(3);
|
||||
|
||||
if (serial.IsItem)
|
||||
if (item != null && from.Map == item.Map && Utility.InUpdateRange(item.GetWorldLocation(), from.Location) &&
|
||||
from.CanSee(item))
|
||||
{
|
||||
var item = World.FindItem(serial);
|
||||
|
||||
if (item != null && from.Map == item.Map && Utility.InUpdateRange(item.GetWorldLocation(), from.Location) &&
|
||||
from.CanSee(item))
|
||||
{
|
||||
item.OnHelpRequest(from);
|
||||
}
|
||||
}
|
||||
else if (serial.IsMobile)
|
||||
{
|
||||
var m = World.FindMobile(serial);
|
||||
|
||||
if (m != null && from.Map == m.Map && Utility.InUpdateRange(m.Location, from.Location) && from.CanSee(m))
|
||||
{
|
||||
m.OnHelpRequest(m);
|
||||
}
|
||||
item.OnHelpRequest(from);
|
||||
}
|
||||
}
|
||||
|
||||
public static void UseReq(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
else if (serial.IsMobile)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
var m = World.FindMobile(serial);
|
||||
|
||||
if (from.AccessLevel >= AccessLevel.Counselor || Core.TickCount - from.NextActionTime >= 0)
|
||||
if (m != null && from.Map == m.Map && Utility.InUpdateRange(m.Location, from.Location) && from.CanSee(m))
|
||||
{
|
||||
var value = reader.ReadUInt32();
|
||||
m.OnHelpRequest(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((value & ~0x7FFFFFFF) != 0)
|
||||
{
|
||||
from.OnPaperdollRequest();
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial s = (Serial)value;
|
||||
public static void UseReq(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
|
||||
if (s.IsMobile)
|
||||
{
|
||||
var m = World.FindMobile(s);
|
||||
if (from.AccessLevel >= AccessLevel.Counselor || Core.TickCount - from.NextActionTime >= 0)
|
||||
{
|
||||
var value = reader.ReadUInt32();
|
||||
|
||||
if (m?.Deleted == false)
|
||||
{
|
||||
from.Use(m);
|
||||
}
|
||||
}
|
||||
else if (s.IsItem)
|
||||
{
|
||||
var item = World.FindItem(s);
|
||||
|
||||
if (item?.Deleted == false)
|
||||
{
|
||||
from.Use(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
from.NextActionTime = Core.TickCount + Mobile.ActionDelay;
|
||||
if ((value & ~0x7FFFFFFF) != 0)
|
||||
{
|
||||
from.OnPaperdollRequest();
|
||||
}
|
||||
else
|
||||
{
|
||||
from.SendActionMessage();
|
||||
Serial s = (Serial)value;
|
||||
|
||||
if (s.IsMobile)
|
||||
{
|
||||
var m = World.FindMobile(s);
|
||||
|
||||
if (m?.Deleted == false)
|
||||
{
|
||||
from.Use(m);
|
||||
}
|
||||
}
|
||||
else if (s.IsItem)
|
||||
{
|
||||
var item = World.FindItem(s);
|
||||
|
||||
if (item?.Deleted == false)
|
||||
{
|
||||
from.Use(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
from.NextActionTime = Core.TickCount + Mobile.ActionDelay;
|
||||
}
|
||||
else
|
||||
{
|
||||
from.SendActionMessage();
|
||||
}
|
||||
}
|
||||
|
||||
public static void LookReq(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
|
||||
Serial s = (Serial)reader.ReadUInt32();
|
||||
|
||||
if (s.IsMobile)
|
||||
{
|
||||
var m = World.FindMobile(s);
|
||||
|
||||
if (m != null && from.CanSee(m) && Utility.InUpdateRange(from.Location, m.Location))
|
||||
{
|
||||
if (SingleClickProps)
|
||||
{
|
||||
m.OnAosSingleClick(from);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (from.Region.OnSingleClick(from, m))
|
||||
{
|
||||
m.OnSingleClick(from);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void LookReq(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
else if (s.IsItem)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
var item = World.FindItem(s);
|
||||
|
||||
if (item?.Deleted == false && from.CanSee(item) &&
|
||||
Utility.InUpdateRange(from.Location, item.GetWorldLocation()))
|
||||
{
|
||||
if (SingleClickProps)
|
||||
{
|
||||
item.OnAosSingleClick(from);
|
||||
}
|
||||
else if (from.Region.OnSingleClick(from, item))
|
||||
{
|
||||
if (item.Parent is Item parentItem)
|
||||
{
|
||||
parentItem.OnSingleClickContained(from, item);
|
||||
}
|
||||
|
||||
item.OnSingleClick(from);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void BatchQueryProperties(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
if (!ObjectPropertyList.Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var from = state.Mobile;
|
||||
|
||||
var length = reader.Remaining;
|
||||
|
||||
if (length % 4 != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while (reader.Remaining > 0)
|
||||
{
|
||||
Serial s = (Serial)reader.ReadUInt32();
|
||||
|
||||
if (s.IsMobile)
|
||||
|
|
@ -112,17 +175,7 @@ namespace Server.Network
|
|||
|
||||
if (m != null && from.CanSee(m) && Utility.InUpdateRange(from.Location, m.Location))
|
||||
{
|
||||
if (SingleClickProps)
|
||||
{
|
||||
m.OnAosSingleClick(from);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (from.Region.OnSingleClick(from, m))
|
||||
{
|
||||
m.OnSingleClick(from);
|
||||
}
|
||||
}
|
||||
m.SendPropertiesTo(from);
|
||||
}
|
||||
}
|
||||
else if (s.IsItem)
|
||||
|
|
@ -132,61 +185,7 @@ namespace Server.Network
|
|||
if (item?.Deleted == false && from.CanSee(item) &&
|
||||
Utility.InUpdateRange(from.Location, item.GetWorldLocation()))
|
||||
{
|
||||
if (SingleClickProps)
|
||||
{
|
||||
item.OnAosSingleClick(from);
|
||||
}
|
||||
else if (from.Region.OnSingleClick(from, item))
|
||||
{
|
||||
if (item.Parent is Item parentItem)
|
||||
{
|
||||
parentItem.OnSingleClickContained(from, item);
|
||||
}
|
||||
|
||||
item.OnSingleClick(from);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void BatchQueryProperties(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
if (!ObjectPropertyList.Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var from = state.Mobile;
|
||||
|
||||
var length = reader.Remaining;
|
||||
|
||||
if (length % 4 != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while (reader.Remaining > 0)
|
||||
{
|
||||
Serial s = (Serial)reader.ReadUInt32();
|
||||
|
||||
if (s.IsMobile)
|
||||
{
|
||||
var m = World.FindMobile(s);
|
||||
|
||||
if (m != null && from.CanSee(m) && Utility.InUpdateRange(from.Location, m.Location))
|
||||
{
|
||||
m.SendPropertiesTo(from);
|
||||
}
|
||||
}
|
||||
else if (s.IsItem)
|
||||
{
|
||||
var item = World.FindItem(s);
|
||||
|
||||
if (item?.Deleted == false && from.CanSee(item) &&
|
||||
Utility.InUpdateRange(from.Location, item.GetWorldLocation()))
|
||||
{
|
||||
item.SendPropertiesTo(from);
|
||||
}
|
||||
item.SendPropertiesTo(from);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue