public void RegisterClientPacketHandler <T>(ClientPacketId packetId, GenericClientPacketHandler <T> packetHandler) where T : IPacketData { if (_clientPacketHandlers.ContainsKey(packetId)) { Logger.Get().Error(this, $"Tried to register already existing client packet handler: {packetId}"); return; } // We can't store these kinds of generic delegates in a dictionary, // so we wrap it in a function that casts it _clientPacketHandlers[packetId] = iPacket => { packetHandler((T)iPacket); }; }
/// <summary> /// Register a packet handler for the given ID. /// </summary> /// <param name="packetId">The client packet ID.</param> /// <param name="handler">The handler for the data.</param> /// <typeparam name="T">The type of the packet data passed as parameter to the handler.</typeparam> public void RegisterClientPacketHandler <T>( ClientPacketId packetId, GenericClientPacketHandler <T> handler ) where T : IPacketData => RegisterClientPacketHandler(packetId, iPacket => handler((T)iPacket));