From 0f53287c92a4a641524ec8a99abd849dc2612f59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Wed, 29 Dec 2021 22:41:55 +0100 Subject: [PATCH] fix: bugs in packet types repository add packet --- Core/NosSmooth.Packets/Packets/PacketTypesRepository.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Core/NosSmooth.Packets/Packets/PacketTypesRepository.cs b/Core/NosSmooth.Packets/Packets/PacketTypesRepository.cs index 0005141..0c87d76 100644 --- a/Core/NosSmooth.Packets/Packets/PacketTypesRepository.cs +++ b/Core/NosSmooth.Packets/Packets/PacketTypesRepository.cs @@ -43,7 +43,7 @@ public class PacketTypesRepository : IPacketTypesRepository /// A result that may or may not have succeeded. public Result AddPacketType(Type type) { - if (typeof(IPacket).IsAssignableFrom(type)) + if (!typeof(IPacket).IsAssignableFrom(type)) { return new ArgumentInvalidError(nameof(type), "The type has to be assignable to IPacket."); } @@ -74,6 +74,11 @@ public class PacketTypesRepository : IPacketTypesRepository if (header.Identifier is not null) { + if (!_headerToPacket.ContainsKey(header.Source)) + { + _headerToPacket[header.Source] = new Dictionary(); + } + if (_headerToPacket[header.Source].ContainsKey(header.Identifier)) { return new AmbiguousHeaderError -- 2.48.1