private void Cache(Type type) { if (!typeof(IPacket).IsAssignableFrom(type)) { return; } PacketHeaderAttribute packetHeaderAttribute = type.GetCustomAttribute <PacketHeaderAttribute>(); var typeCreator = new CachedType { PacketHeaderAttribute = packetHeaderAttribute, PacketType = type, Constructor = Expression.Lambda(Expression.New(type)).Compile(), Properties = GetProperties(type) }; if (packetHeaderAttribute != null) { _cacheByHeader[packetHeaderAttribute.Header] = typeCreator; } _cacheByType[type] = typeCreator; foreach (PropertyInfo propertyInfo in type.GetProperties()) { Cache(propertyInfo.PropertyType); } }
public HandlerMethodReference(Action <object, object> handlerMethod, IPacketHandler parentHandler, Type packetBaseParameterType) { HandlerMethod = handlerMethod; ParentHandler = parentHandler; PacketDefinitionParameterType = packetBaseParameterType; PacketHeaderAttribute headerAttribute = (PacketHeaderAttribute)PacketDefinitionParameterType.GetCustomAttributes(true).FirstOrDefault(ca => ca.GetType().Equals(typeof(PacketHeaderAttribute))); Identification = headerAttribute?.Identification; PassNonParseablePacket = headerAttribute?.PassNonParseablePacket ?? false; Authority = headerAttribute?.Authority ?? AuthorityType.User; }
public HandlerMethodReference(Type packetBaseParameterType) { PacketDefinitionParameterType = packetBaseParameterType; PacketHeaderAttribute headerAttribute = (PacketHeaderAttribute)Array.Find(PacketDefinitionParameterType.GetCustomAttributes(true), ca => ca.GetType().Equals(typeof(PacketHeaderAttribute))); Amount = headerAttribute?.Amount ?? 1; Identification = headerAttribute?.Identification; PassNonParseablePacket = headerAttribute?.PassNonParseablePacket ?? false; CharacterRequired = headerAttribute?.CharacterRequired ?? true; Authority = headerAttribute?.Authority ?? AuthorityType.User; }
public ClientSession(IChannel channel, bool isWorldClient) : base(channel) { // set last received lastPacketReceive = DateTime.Now.Ticks; _random = new Random((int)ClientId); _isWorldClient = isWorldClient; foreach (var controller in PacketControllerFactory.GenerateControllers()) { controller.RegisterSession(this); foreach (MethodInfo methodInfo in controller.GetType().GetMethods().Where(x => x.GetParameters().FirstOrDefault()?.ParameterType.BaseType == typeof(PacketDefinition))) { var type = methodInfo.GetParameters().FirstOrDefault()?.ParameterType; PacketHeaderAttribute packetheader = (PacketHeaderAttribute)Array.Find(type.GetCustomAttributes(true), ca => ca.GetType().Equals(typeof(PacketHeaderAttribute))); HeaderMethod.Add(packetheader, new Tuple <IPacketController, Type>(controller, type)); ControllerMethods.Add(packetheader, DelegateBuilder.BuildDelegate <Action <object, object> >(methodInfo)); } } }