public void RegisterPacket(Type PacketType) { var isFromClient = false; var header = -1; var attributes = PacketType.GetCustomAttributes(typeof(PacketInformation), false); if (attributes.Length == 1) { isFromClient = ((PacketInformation)attributes[0]).IsIncoming; header = ((PacketInformation)attributes[0]).Header; } if (!typeof(IPacket).IsAssignableFrom(PacketType)) { return; } var packet = (IPacket)Activator.CreateInstance(PacketType); if (typeof(IPacket).IsAssignableFrom(packet.GetType())) { if (header >= 0 && header <= 65535) { if (isFromClient) { PacketIn.Add(Convert.ToUInt16(header), packet); } else { PacketOut.Add(Convert.ToUInt16(header), packet); } } else { Console.WriteLine("Invalid packet header in class " + packet.GetType().Name); } } }