feat: do not crash on unkown packet id

This commit is contained in:
Timothy Schenk 2023-08-13 18:29:39 +02:00
parent 2a4e5ed118
commit 2705715e8c

View file

@ -42,7 +42,7 @@ public class PacketDistributorService : IHostedService
var packetVariable = DeclareVariable(packetsType.Value, "packet"); var packetVariable = DeclareVariable(packetsType.Value, "packet");
Assign(packetVariable, newPacket); Assign(packetVariable, newPacket);
Call(packetVariable, packetsType.Value.GetMethod("Deserialize"), arg); Call(packetVariable, nameof(IPacket.Deserialize), arg);
Return(packetVariable); Return(packetVariable);
}).Compile(); }).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", this.logger.LogTrace("[{TempId}] Packet with ID: {MessageOperationCode} is being dequeued",
item.Session.Id, item.OperationCode); 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 = var packetHandler =
ActivatorUtilities.GetServiceOrCreateInstance(this.serviceProvider, ActivatorUtilities.GetServiceOrCreateInstance(this.serviceProvider,
this.packetHandlers[item.OperationCode]); this.packetHandlers[item.OperationCode]);