fix: Fixes thread guard and cleans up incoming packet reader (#1641)
### Summary * Fixes syntax compile error when THREADGUARD is enabled. * Removes `int packetLength` from incoming packet handles since they aren't needed. ### Developer Notes Incoming packet handler `SpanReader` is now properly scoped to that packet by length.
This commit is contained in:
parent
25a75fdf24
commit
7d9bc9ff0a
31 changed files with 190 additions and 157 deletions
|
|
@ -469,7 +469,9 @@ public partial class NetState : IComparable<NetState>, IValueLinkListNode<NetSta
|
|||
Console.WriteLine("Attempting to get pipe buffer from wrong thread!");
|
||||
Console.WriteLine(new StackTrace());
|
||||
Utility.PopColor();
|
||||
return;
|
||||
|
||||
buffer = Array.Empty<byte>();
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
buffer = SendPipe.Writer.AvailableToWrite();
|
||||
|
|
@ -842,12 +844,16 @@ public partial class NetState : IComparable<NetState>, IValueLinkListNode<NetSta
|
|||
|
||||
UpdatePacketCount(packetId);
|
||||
|
||||
var packetBuffer = packetReader.Buffer[..packetLength];
|
||||
|
||||
if (PacketLogging)
|
||||
{
|
||||
LogPacket(packetReader.Buffer[..packetLength], true);
|
||||
LogPacket(packetBuffer, true);
|
||||
}
|
||||
|
||||
handler.OnReceive(this, packetReader, packetLength);
|
||||
// Make a new SpanReader that is limited to the length of the packet.
|
||||
// This allows us to use reader.Remaining for VendorBuyReply packet
|
||||
handler.OnReceive(this, new SpanReader(packetBuffer));
|
||||
|
||||
prof?.Finish(packetLength);
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ public unsafe class PacketHandler
|
|||
{
|
||||
private readonly int _length;
|
||||
|
||||
public PacketHandler(int packetID, int length, bool ingame, delegate*<NetState, SpanReader, int, void> onReceive)
|
||||
public PacketHandler(int packetID, int length, bool ingame, delegate*<NetState, SpanReader, void> onReceive)
|
||||
{
|
||||
_length = length;
|
||||
PacketID = packetID;
|
||||
|
|
@ -33,7 +33,7 @@ public unsafe class PacketHandler
|
|||
|
||||
public virtual int GetLength(NetState ns) => _length;
|
||||
|
||||
public delegate*<NetState, SpanReader, int, void> OnReceive { get; }
|
||||
public delegate*<NetState, SpanReader, void> OnReceive { get; }
|
||||
|
||||
public delegate*<int, NetState, out bool, bool> ThrottleCallback { get; set; }
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public static class IncomingPackets
|
|||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void Register(int packetID, int length, bool ingame,
|
||||
delegate*<NetState, SpanReader, int, void> onReceive) =>
|
||||
delegate*<NetState, SpanReader, void> onReceive) =>
|
||||
Register(new PacketHandler(packetID, length, ingame, onReceive));
|
||||
|
||||
public static void Register(PacketHandler packetHandler)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue