A Core/NosSmooth.Core/Packets/ParsingFailedPacket.cs => Core/NosSmooth.Core/Packets/ParsingFailedPacket.cs +37 -0
@@ 0,0 1,37 @@
+//
+// ParsingFailedPacket.cs
+//
+// Copyright (c) František Boháček. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using NosCore.Packets;
+using Remora.Results;
+
+namespace NosSmooth.Core.Packets;
+
+/// <summary>
+/// Represents packet that failed to parse correctly.
+/// </summary>
+public class ParsingFailedPacket : PacketBase
+{
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ParsingFailedPacket"/> class.
+ /// </summary>
+ /// <param name="serializerResult">The result from the serializer.</param>
+ /// <param name="packet">The full text of the packet.</param>
+ public ParsingFailedPacket(IResult serializerResult, string packet)
+ {
+ SerializerResult = serializerResult;
+ Packet = packet;
+ }
+
+ /// <summary>
+ /// Gets the result from the serializer.
+ /// </summary>
+ public IResult SerializerResult { get; }
+
+ /// <summary>
+ /// Gets he full packet string.
+ /// </summary>
+ public string Packet { get; }
+}<
\ No newline at end of file
M Local/NosSmooth.LocalClient/NostaleLocalClient.cs => Local/NosSmooth.LocalClient/NostaleLocalClient.cs +5 -4
@@ 164,18 164,19 @@ public class NostaleLocalClient : BaseNostaleClient
var packet = serializer.Deserialize(packetString);
if (!packet.IsSuccess)
{
- _logger.LogWarning($"Could not parse {packetString}. Reason: {packet.Error.Message}");
- return;
+ _logger.LogWarning("Could not parse {Packet}. Reason:", packetString);
+ _logger.LogResultError(packet);
+ packet = new ParsingFailedPacket(packet, packetString);
}
Result result;
if (type == PacketType.Received)
{
- result = await _packetHandler.HandleReceivedPacketAsync(packet.Entity, packetString);
+ result = await _packetHandler.HandleReceivedPacketAsync(packet.Entity, packetString, _stopRequested ?? default);
}
else
{
- result = await _packetHandler.HandleSentPacketAsync(packet.Entity, packetString);
+ result = await _packetHandler.HandleSentPacketAsync(packet.Entity, packetString, _stopRequested ?? default);
}
if (!result.IsSuccess)