diff --git a/Server/Services/PacketDistributorService.cs b/Server/Services/PacketDistributorService.cs index 54c42fc..b1f3ab1 100644 --- a/Server/Services/PacketDistributorService.cs +++ b/Server/Services/PacketDistributorService.cs @@ -42,7 +42,7 @@ public class PacketDistributorService : IHostedService var packetVariable = DeclareVariable(packetsType.Value, "packet"); Assign(packetVariable, newPacket); - Call(packetVariable, packetsType.Value.GetMethod("Deserialize"), arg); + Call(packetVariable, nameof(IPacket.Deserialize), arg); Return(packetVariable); }).Compile(); @@ -119,11 +119,17 @@ public class PacketDistributorService : IHostedService } } - private void InvokePacketHandler(RawPacket? item) + private void InvokePacketHandler(RawPacket item) { this.logger.LogTrace("[{TempId}] Packet with ID: {MessageOperationCode} is being dequeued", item.Session.Id, item.OperationCode); - var packet = this.deserializationMap[item.OperationCode].Invoke(item.MessageBody); + if (!this.deserializationMap.ContainsKey(item.OperationCode)) + { + this.logger.LogInformation("Couldn't find Packet type for Id: {Opcode}", item.OperationCode); + return; + } + + var packet = this.deserializationMap[item.OperationCode](item.MessageBody); var packetHandler = ActivatorUtilities.GetServiceOrCreateInstance(this.serviceProvider, this.packetHandlers[item.OperationCode]);