From c1b9be1d64b2a2a7eef99af0ffd9127b2b701a59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Tue, 3 Jan 2023 23:30:19 +0100 Subject: [PATCH] feat(samples): add file client logging of failed parsing or missing packets --- Samples/FileClient/FileClient.csproj | 4 -- Samples/FileClient/Program.cs | 2 + .../Responders/PacketNotFoundResponder.cs | 43 +++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 Samples/FileClient/Responders/PacketNotFoundResponder.cs diff --git a/Samples/FileClient/FileClient.csproj b/Samples/FileClient/FileClient.csproj index 6df8332..8bd1a20 100644 --- a/Samples/FileClient/FileClient.csproj +++ b/Samples/FileClient/FileClient.csproj @@ -8,10 +8,6 @@ false - - - - diff --git a/Samples/FileClient/Program.cs b/Samples/FileClient/Program.cs index 790581a..bf35255 100644 --- a/Samples/FileClient/Program.cs +++ b/Samples/FileClient/Program.cs @@ -4,6 +4,7 @@ // 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 FileClient.Responders; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; @@ -48,6 +49,7 @@ public static class Program coll.AddNostaleCore() .AddNostaleGame() .AddNostaleDataFiles() + .AddPacketResponder() .Configure(o => o.Language = Language.Cz) .Configure(o => o.SupportedLanguages = new[] { diff --git a/Samples/FileClient/Responders/PacketNotFoundResponder.cs b/Samples/FileClient/Responders/PacketNotFoundResponder.cs new file mode 100644 index 0000000..94caf5c --- /dev/null +++ b/Samples/FileClient/Responders/PacketNotFoundResponder.cs @@ -0,0 +1,43 @@ +// +// PacketNotFoundResponder.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 Microsoft.Extensions.Logging; +using NosSmooth.Core.Packets; +using NosSmooth.Packets; +using Remora.Results; + +namespace FileClient.Responders; + +/// +/// Responds to packets that were not found. +/// +public class PacketNotFoundResponder : IPacketResponder, IPacketResponder +{ + private readonly ILogger _logger; + + /// + /// Initializes a new instance of the class. + /// + /// The logger. + public PacketNotFoundResponder(ILogger logger) + { + _logger = logger; + } + + /// + public Task Respond(PacketEventArgs packetArgs, CancellationToken ct = default) + { + _logger.LogWarning($"Could not find packet {packetArgs.PacketString}"); + return Task.FromResult(Result.FromSuccess()); + } + + /// + public Task Respond(PacketEventArgs packetArgs, CancellationToken ct = default) + { + _logger.LogWarning($"Could not parse packet {packetArgs.PacketString}"); + return Task.FromResult(Result.FromSuccess()); + } +} \ No newline at end of file -- 2.49.0