fix: Updates encoded packet handler to use function pointers (#1066)
This commit is contained in:
parent
f24b98f8e2
commit
057cf87e60
6 changed files with 79 additions and 54 deletions
|
|
@ -1,20 +1,32 @@
|
|||
namespace Server.Network
|
||||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2022 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: EncodedPacketHandler.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/>. *
|
||||
*************************************************************************/
|
||||
|
||||
namespace Server.Network;
|
||||
|
||||
public unsafe class EncodedPacketHandler
|
||||
{
|
||||
public delegate void OnEncodedPacketReceive(NetState state, IEntity ent, EncodedReader reader);
|
||||
|
||||
public class EncodedPacketHandler
|
||||
public EncodedPacketHandler(int packetID, bool ingame, delegate*<NetState, IEntity, EncodedReader, void> onReceive)
|
||||
{
|
||||
public EncodedPacketHandler(int packetID, bool ingame, OnEncodedPacketReceive onReceive)
|
||||
{
|
||||
PacketID = packetID;
|
||||
Ingame = ingame;
|
||||
OnReceive = onReceive;
|
||||
}
|
||||
|
||||
public int PacketID { get; }
|
||||
|
||||
public OnEncodedPacketReceive OnReceive { get; }
|
||||
|
||||
public bool Ingame { get; }
|
||||
PacketID = packetID;
|
||||
Ingame = ingame;
|
||||
OnReceive = onReceive;
|
||||
}
|
||||
|
||||
public int PacketID { get; }
|
||||
|
||||
public delegate*<NetState, IEntity, EncodedReader, void> OnReceive { get; }
|
||||
|
||||
public bool Ingame { get; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +1,37 @@
|
|||
namespace Server.Network
|
||||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2022 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: EncodedReader.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/>. *
|
||||
*************************************************************************/
|
||||
|
||||
namespace Server.Network;
|
||||
|
||||
public ref struct EncodedReader
|
||||
{
|
||||
public ref struct EncodedReader
|
||||
{
|
||||
private CircularBufferReader m_Reader;
|
||||
private CircularBufferReader _reader;
|
||||
|
||||
public EncodedReader(CircularBufferReader reader) => m_Reader = reader;
|
||||
public EncodedReader(CircularBufferReader reader) => _reader = reader;
|
||||
|
||||
public void Trace(NetState state)
|
||||
{
|
||||
m_Reader.Trace(state);
|
||||
}
|
||||
public void Trace(NetState state) => _reader.Trace(state);
|
||||
|
||||
public int ReadInt32() => m_Reader.ReadByte() != 0 ? 0 : m_Reader.ReadInt32();
|
||||
public int ReadInt32() => _reader.ReadByte() != 0 ? 0 : _reader.ReadInt32();
|
||||
|
||||
public Point3D ReadPoint3D() => m_Reader.ReadByte() != 3
|
||||
? Point3D.Zero
|
||||
: new Point3D(m_Reader.ReadInt16(), m_Reader.ReadInt16(), m_Reader.ReadByte());
|
||||
public Point3D ReadPoint3D() => _reader.ReadByte() != 3
|
||||
? Point3D.Zero
|
||||
: new Point3D(_reader.ReadInt16(), _reader.ReadInt16(), _reader.ReadByte());
|
||||
|
||||
public string ReadUnicodeStringSafe() =>
|
||||
m_Reader.ReadByte() != 2 ? string.Empty : m_Reader.ReadBigUniSafe(m_Reader.ReadUInt16());
|
||||
public string ReadUnicodeStringSafe() =>
|
||||
_reader.ReadByte() != 2 ? string.Empty : _reader.ReadBigUniSafe(_reader.ReadUInt16());
|
||||
|
||||
public string ReadUnicodeString() =>
|
||||
m_Reader.ReadByte() != 2 ? string.Empty : m_Reader.ReadBigUni(m_Reader.ReadUInt16());
|
||||
}
|
||||
public string ReadUnicodeString() =>
|
||||
_reader.ReadByte() != 2 ? string.Empty : _reader.ReadBigUni(_reader.ReadUInt16());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,9 @@ public static class IncomingPackets
|
|||
|
||||
public static PacketHandler GetHandler(int packetID) => Handlers[packetID];
|
||||
|
||||
public static void RegisterEncoded(int packetID, bool ingame, OnEncodedPacketReceive onReceive)
|
||||
public static unsafe void RegisterEncoded(
|
||||
int packetID, bool ingame, delegate*<NetState, IEntity, EncodedReader, void> onReceive
|
||||
)
|
||||
{
|
||||
if (packetID is >= 0 and < 0x100)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -48,8 +48,8 @@ public static class IncomingPlayerPackets
|
|||
IncomingPackets.Register(0xD7, 0, true, &EncodedCommand);
|
||||
IncomingPackets.Register(0xF4, 0, false, &CrashReport);
|
||||
|
||||
IncomingPackets.RegisterEncoded(0x28, true, GuildGumpRequest);
|
||||
IncomingPackets.RegisterEncoded(0x32, true, QuestGumpRequest);
|
||||
IncomingPackets.RegisterEncoded(0x28, true, &GuildGumpRequest);
|
||||
IncomingPackets.RegisterEncoded(0x32, true, &QuestGumpRequest);
|
||||
}
|
||||
|
||||
public static void DeathStatusResponse(NetState state, CircularBufferReader reader, int packetLength)
|
||||
|
|
@ -593,7 +593,7 @@ public static class IncomingPlayerPackets
|
|||
EventSink.InvokeQuestGumpRequest(state.Mobile);
|
||||
}
|
||||
|
||||
public static void EncodedCommand(NetState state, CircularBufferReader reader, int packetLength)
|
||||
public static unsafe void EncodedCommand(NetState state, CircularBufferReader reader, int packetLength)
|
||||
{
|
||||
var e = World.FindEntity((Serial)reader.ReadUInt32());
|
||||
int packetId = reader.ReadUInt16();
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ namespace Server.Items
|
|||
{
|
||||
public static class WeaponAbilityPackets
|
||||
{
|
||||
public static void Configure()
|
||||
public static unsafe void Configure()
|
||||
{
|
||||
IncomingPackets.RegisterEncoded(0x19, true, SetAbility);
|
||||
IncomingPackets.RegisterEncoded(0x19, true, &SetAbility);
|
||||
}
|
||||
|
||||
public static void SetAbility(NetState state, IEntity e, EncodedReader reader)
|
||||
public static unsafe void SetAbility(NetState state, IEntity e, EncodedReader reader)
|
||||
{
|
||||
var m = state.Mobile;
|
||||
var index = reader.ReadInt32();
|
||||
|
|
|
|||
|
|
@ -976,21 +976,21 @@ namespace Server.Multis
|
|||
{
|
||||
IncomingExtendedCommandPackets.RegisterExtended(0x1E, true, &QueryDesignDetails);
|
||||
|
||||
IncomingPackets.RegisterEncoded(0x02, true, Designer_Backup);
|
||||
IncomingPackets.RegisterEncoded(0x03, true, Designer_Restore);
|
||||
IncomingPackets.RegisterEncoded(0x04, true, Designer_Commit);
|
||||
IncomingPackets.RegisterEncoded(0x05, true, Designer_Delete);
|
||||
IncomingPackets.RegisterEncoded(0x06, true, Designer_Build);
|
||||
IncomingPackets.RegisterEncoded(0x0C, true, Designer_Close);
|
||||
IncomingPackets.RegisterEncoded(0x0D, true, Designer_Stairs);
|
||||
IncomingPackets.RegisterEncoded(0x0E, true, Designer_Sync);
|
||||
IncomingPackets.RegisterEncoded(0x10, true, Designer_Clear);
|
||||
IncomingPackets.RegisterEncoded(0x12, true, Designer_Level);
|
||||
IncomingPackets.RegisterEncoded(0x02, true, &Designer_Backup);
|
||||
IncomingPackets.RegisterEncoded(0x03, true, &Designer_Restore);
|
||||
IncomingPackets.RegisterEncoded(0x04, true, &Designer_Commit);
|
||||
IncomingPackets.RegisterEncoded(0x05, true, &Designer_Delete);
|
||||
IncomingPackets.RegisterEncoded(0x06, true, &Designer_Build);
|
||||
IncomingPackets.RegisterEncoded(0x0C, true, &Designer_Close);
|
||||
IncomingPackets.RegisterEncoded(0x0D, true, &Designer_Stairs);
|
||||
IncomingPackets.RegisterEncoded(0x0E, true, &Designer_Sync);
|
||||
IncomingPackets.RegisterEncoded(0x10, true, &Designer_Clear);
|
||||
IncomingPackets.RegisterEncoded(0x12, true, &Designer_Level);
|
||||
|
||||
IncomingPackets.RegisterEncoded(0x13, true, Designer_Roof); // Samurai Empire roof
|
||||
IncomingPackets.RegisterEncoded(0x14, true, Designer_RoofDelete); // Samurai Empire roof
|
||||
IncomingPackets.RegisterEncoded(0x13, true, &Designer_Roof); // Samurai Empire roof
|
||||
IncomingPackets.RegisterEncoded(0x14, true, &Designer_RoofDelete); // Samurai Empire roof
|
||||
|
||||
IncomingPackets.RegisterEncoded(0x1A, true, Designer_Revert);
|
||||
IncomingPackets.RegisterEncoded(0x1A, true, &Designer_Revert);
|
||||
|
||||
EventSink.Speech += EventSink_Speech;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue