From f39daa88d90c8afb6bc792aa3c0c8a38d6094a91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Thu, 23 Dec 2021 16:08:09 +0100 Subject: [PATCH] feat: call parsing failed packet if parsing failed --- .../Packets/ParsingFailedPacket.cs | 37 +++++++++++++++++++ .../NostaleLocalClient.cs | 9 +++-- 2 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 Core/NosSmooth.Core/Packets/ParsingFailedPacket.cs diff --git a/Core/NosSmooth.Core/Packets/ParsingFailedPacket.cs b/Core/NosSmooth.Core/Packets/ParsingFailedPacket.cs new file mode 100644 index 0000000..eeaaa73 --- /dev/null +++ b/Core/NosSmooth.Core/Packets/ParsingFailedPacket.cs @@ -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; + +/// +/// Represents packet that failed to parse correctly. +/// +public class ParsingFailedPacket : PacketBase +{ + /// + /// Initializes a new instance of the class. + /// + /// The result from the serializer. + /// The full text of the packet. + public ParsingFailedPacket(IResult serializerResult, string packet) + { + SerializerResult = serializerResult; + Packet = packet; + } + + /// + /// Gets the result from the serializer. + /// + public IResult SerializerResult { get; } + + /// + /// Gets he full packet string. + /// + public string Packet { get; } +} \ No newline at end of file diff --git a/Local/NosSmooth.LocalClient/NostaleLocalClient.cs b/Local/NosSmooth.LocalClient/NostaleLocalClient.cs index 369c412..89f5b91 100644 --- a/Local/NosSmooth.LocalClient/NostaleLocalClient.cs +++ b/Local/NosSmooth.LocalClient/NostaleLocalClient.cs @@ -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) -- 2.48.1