ModernUO/Projects/Server/Network/Packets/IncomingEntityPackets.cs
Kamron Batman 5882b1ab3f
fix(core): Fixes OPL packets (#395)
- [X] Fixes an issue with OPL packets using the wrong endianness and not updating the position properly.
- [X] Fixes an issue with SpanWriter not updating bytes written when it is used adhoc.
- [X] Moves packet creation for OPL inside the SendInfoTo function.

Bumps release version
2021-01-08 23:55:23 -08:00

196 lines
6.3 KiB
C#

/*************************************************************************
* ModernUO *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: IncomingEntityPackets.cs *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
using System;
namespace Server.Network
{
public static class IncomingEntityPackets
{
public static bool SingleClickProps { get; set; }
public static void Configure()
{
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 ObjectHelpRequest(NetState state, CircularBufferReader reader)
{
var from = state.Mobile;
Serial serial = reader.ReadUInt32();
int unk = reader.ReadByte();
var lang = reader.ReadAscii(3);
if (serial.IsItem)
{
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);
}
}
}
public static void UseReq(NetState state, CircularBufferReader reader)
{
var from = state.Mobile;
if (from.AccessLevel >= AccessLevel.Counselor || Core.TickCount - from.NextActionTime >= 0)
{
var value = reader.ReadUInt32();
if ((value & ~0x7FFFFFFF) != 0)
{
from.OnPaperdollRequest();
}
else
{
Serial s = 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)
{
var from = state.Mobile;
Serial s = reader.ReadUInt32();
if (s.IsMobile)
{
var m = World.FindMobile(s);
if (m != null && from.CanSee(m) && Utility.InUpdateRange(from, m))
{
if (SingleClickProps)
{
m.OnAosSingleClick(from);
}
else
{
if (from.Region.OnSingleClick(from, m))
{
m.OnSingleClick(from);
}
}
}
}
else if (s.IsItem)
{
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)
{
if (!ObjectPropertyList.Enabled)
{
return;
}
var from = state.Mobile;
var length = reader.Remaining;
if (length % 4 != 0)
{
return;
}
while (reader.Remaining > 0)
{
Serial s = reader.ReadUInt32();
if (s.IsMobile)
{
var m = World.FindMobile(s);
if (m != null && from.CanSee(m) && Utility.InUpdateRange(from, m))
{
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);
}
}
}
}
}
}