From 81560d81a5d98a213d4e01870ccd3a720ccef88d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Tue, 1 Mar 2022 20:08:42 +0100 Subject: [PATCH] feat!(core): make some classes internal --- .../Control/ControlCommandPacketResponders.cs | 2 +- .../Control/TakeControlCommandHandler.cs | 2 +- .../Commands/Walking/WalkCommandHandler.cs | 2 +- .../Extensions/ServiceCollectionExtensions.cs | 2 +- Core/NosSmooth.Core/Packets/IPacketHandler.cs | 39 ------------- Core/NosSmooth.Core/Packets/PacketHandler.cs | 55 ++++++++++++++++--- .../Stateful/StatefulInjector.cs | 2 +- .../Stateful/StatefulPreExecutionEvent.cs | 2 +- .../Stateful/StatefulRepository.cs | 2 +- .../Packets/InPacketSerializerTest.cs | 1 - 10 files changed, 53 insertions(+), 56 deletions(-) delete mode 100644 Core/NosSmooth.Core/Packets/IPacketHandler.cs delete mode 100644 Tests/NosSmooth.Core.Tests/Packets/InPacketSerializerTest.cs diff --git a/Core/NosSmooth.Core/Commands/Control/ControlCommandPacketResponders.cs b/Core/NosSmooth.Core/Commands/Control/ControlCommandPacketResponders.cs index 2540e12..b1fdfc6 100644 --- a/Core/NosSmooth.Core/Commands/Control/ControlCommandPacketResponders.cs +++ b/Core/NosSmooth.Core/Commands/Control/ControlCommandPacketResponders.cs @@ -17,7 +17,7 @@ namespace NosSmooth.Core.Commands.Control; /// /// Packet responder for cancellation of . /// -public class ControlCommandPacketResponders : IPacketResponder +internal class ControlCommandPacketResponders : IPacketResponder { private readonly ControlCommands _controlCommands; diff --git a/Core/NosSmooth.Core/Commands/Control/TakeControlCommandHandler.cs b/Core/NosSmooth.Core/Commands/Control/TakeControlCommandHandler.cs index 10ca2fd..7b0f5f6 100644 --- a/Core/NosSmooth.Core/Commands/Control/TakeControlCommandHandler.cs +++ b/Core/NosSmooth.Core/Commands/Control/TakeControlCommandHandler.cs @@ -14,7 +14,7 @@ namespace NosSmooth.Core.Commands.Control; /// /// Handles . /// -public class TakeControlCommandHandler : ICommandHandler +internal class TakeControlCommandHandler : ICommandHandler { private readonly ControlCommands _commands; diff --git a/Core/NosSmooth.Core/Commands/Walking/WalkCommandHandler.cs b/Core/NosSmooth.Core/Commands/Walking/WalkCommandHandler.cs index 10f2aac..a498141 100644 --- a/Core/NosSmooth.Core/Commands/Walking/WalkCommandHandler.cs +++ b/Core/NosSmooth.Core/Commands/Walking/WalkCommandHandler.cs @@ -18,7 +18,7 @@ namespace NosSmooth.Core.Commands.Walking; /// /// Handles . /// -public class WalkCommandHandler : ICommandHandler +internal class WalkCommandHandler : ICommandHandler { private readonly INostaleClient _nostaleClient; diff --git a/Core/NosSmooth.Core/Extensions/ServiceCollectionExtensions.cs b/Core/NosSmooth.Core/Extensions/ServiceCollectionExtensions.cs index 745ed66..2d1e7d5 100644 --- a/Core/NosSmooth.Core/Extensions/ServiceCollectionExtensions.cs +++ b/Core/NosSmooth.Core/Extensions/ServiceCollectionExtensions.cs @@ -34,7 +34,7 @@ public static class ServiceCollectionExtensions ) { serviceCollection - .TryAddSingleton(); + .TryAddSingleton(); serviceCollection.AddPacketSerialization(); serviceCollection.AddSingleton(); diff --git a/Core/NosSmooth.Core/Packets/IPacketHandler.cs b/Core/NosSmooth.Core/Packets/IPacketHandler.cs deleted file mode 100644 index 424757a..0000000 --- a/Core/NosSmooth.Core/Packets/IPacketHandler.cs +++ /dev/null @@ -1,39 +0,0 @@ -// -// IPacketHandler.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 System.Threading; -using System.Threading.Tasks; -using NosSmooth.Core.Client; -using NosSmooth.Packets; -using Remora.Results; - -namespace NosSmooth.Core.Packets; - -/// -/// Calls registered responders for the packet that should be handled. -/// -public interface IPacketHandler -{ - /// - /// Calls a responder for the given packet. - /// - /// The current NosTale client. - /// The packet. - /// The string of the packet. - /// The cancellation token for cancelling the operation. - /// A result that may or may not have succeeded. - public Task HandleReceivedPacketAsync(INostaleClient client, IPacket packet, string packetString, CancellationToken ct = default); - - /// - /// Calls a responder for the given packet. - /// - /// The current NosTale client. - /// The packet. - /// The string of the packet. - /// The cancellation token for cancelling the operation. - /// A result that may or may not have succeeded. - public Task HandleSentPacketAsync(INostaleClient client, IPacket packet, string packetString, CancellationToken ct = default); -} diff --git a/Core/NosSmooth.Core/Packets/PacketHandler.cs b/Core/NosSmooth.Core/Packets/PacketHandler.cs index 4df1b68..a7a69b2 100644 --- a/Core/NosSmooth.Core/Packets/PacketHandler.cs +++ b/Core/NosSmooth.Core/Packets/PacketHandler.cs @@ -18,8 +18,10 @@ using Remora.Results; namespace NosSmooth.Core.Packets; -/// -public class PacketHandler : IPacketHandler +/// +/// Calls registered responders for the packet that should be handled. +/// +public class PacketHandler { private readonly IServiceProvider _provider; @@ -32,25 +34,53 @@ public class PacketHandler : IPacketHandler _provider = provider; } - /// + /// + /// Calls a responder for the given packet. + /// + /// The current NosTale client. + /// The packet. + /// The string of the packet. + /// The cancellation token for cancelling the operation. + /// A result that may or may not have succeeded. public Task HandleReceivedPacketAsync ( INostaleClient client, IPacket packet, string packetString, - CancellationToken ct + CancellationToken ct = default ) - => HandlePacketAsync(client, PacketSource.Server, packet, packetString, ct); + => HandlePacketAsync + ( + client, + PacketSource.Server, + packet, + packetString, + ct + ); - /// + /// + /// Calls a responder for the given packet. + /// + /// The current NosTale client. + /// The packet. + /// The string of the packet. + /// The cancellation token for cancelling the operation. + /// A result that may or may not have succeeded. public Task HandleSentPacketAsync ( INostaleClient client, IPacket packet, string packetString, - CancellationToken ct + CancellationToken ct = default ) - => HandlePacketAsync(client, PacketSource.Client, packet, packetString, ct); + => HandlePacketAsync + ( + client, + PacketSource.Client, + packet, + packetString, + ct + ); private Task HandlePacketAsync ( @@ -131,7 +161,14 @@ public class PacketHandler : IPacketHandler } } - var postExecutionResult = await ExecuteAfterExecutionAsync(scope.ServiceProvider, client, packetEventArgs, results, ct); + var postExecutionResult = await ExecuteAfterExecutionAsync + ( + scope.ServiceProvider, + client, + packetEventArgs, + results, + ct + ); if (!postExecutionResult.IsSuccess) { errors.Add(postExecutionResult); diff --git a/Core/NosSmooth.Core/Stateful/StatefulInjector.cs b/Core/NosSmooth.Core/Stateful/StatefulInjector.cs index 4f81355..5d16964 100644 --- a/Core/NosSmooth.Core/Stateful/StatefulInjector.cs +++ b/Core/NosSmooth.Core/Stateful/StatefulInjector.cs @@ -12,7 +12,7 @@ namespace NosSmooth.Core.Stateful; /// /// The scoped injector of stateful entities. /// -public class StatefulInjector +internal class StatefulInjector { private readonly StatefulRepository _repository; diff --git a/Core/NosSmooth.Core/Stateful/StatefulPreExecutionEvent.cs b/Core/NosSmooth.Core/Stateful/StatefulPreExecutionEvent.cs index 4975bcf..cbd2826 100644 --- a/Core/NosSmooth.Core/Stateful/StatefulPreExecutionEvent.cs +++ b/Core/NosSmooth.Core/Stateful/StatefulPreExecutionEvent.cs @@ -19,7 +19,7 @@ namespace NosSmooth.Core.Stateful; /// /// Event that injects stateful entities into the scope. /// -public class StatefulPreExecutionEvent : IPreExecutionEvent, IPreCommandExecutionEvent +internal class StatefulPreExecutionEvent : IPreExecutionEvent, IPreCommandExecutionEvent { private readonly StatefulInjector _injector; diff --git a/Core/NosSmooth.Core/Stateful/StatefulRepository.cs b/Core/NosSmooth.Core/Stateful/StatefulRepository.cs index e4f215b..f5df603 100644 --- a/Core/NosSmooth.Core/Stateful/StatefulRepository.cs +++ b/Core/NosSmooth.Core/Stateful/StatefulRepository.cs @@ -15,7 +15,7 @@ namespace NosSmooth.Core.Stateful; /// /// Repository holding all the stateful entities for various NosTale clients. /// -public class StatefulRepository +internal class StatefulRepository { private readonly Dictionary> _statefulEntities; diff --git a/Tests/NosSmooth.Core.Tests/Packets/InPacketSerializerTest.cs b/Tests/NosSmooth.Core.Tests/Packets/InPacketSerializerTest.cs deleted file mode 100644 index 5f28270..0000000 --- a/Tests/NosSmooth.Core.Tests/Packets/InPacketSerializerTest.cs +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file -- 2.48.1