Exemple #1
0
        private void GenerateHandlerReferences(Type type, bool isWorldServer)
        {
            IEnumerable <Type> handlerTypes = !isWorldServer?type.Assembly.GetTypes().Where(t => t.Name.Equals("LoginPacketHandler"))  // shitty but it works
                                                  : type.Assembly.GetTypes().Where(p => !p.IsInterface && type.GetInterfaces().FirstOrDefault().IsAssignableFrom(p));

            // iterate thru each type in the given assembly
            foreach (Type handlerType in handlerTypes)
            {
                IPacketHandler handler = (IPacketHandler)Activator.CreateInstance(handlerType, new object[] { this });

                // include PacketDefinition
                foreach (MethodInfo methodInfo in handlerType.GetMethods().Where(x => x.GetCustomAttributes(false).OfType <PacketAttribute>().Any() || x.GetParameters().FirstOrDefault()?.ParameterType?.BaseType == typeof(PacketDefinition)))
                {
                    PacketAttribute packetAttribute = methodInfo.GetCustomAttributes(false).OfType <PacketAttribute>().FirstOrDefault();

                    // assume PacketDefinition based handler method
                    if (packetAttribute == null)
                    {
                        HandlerMethodReference methodReference = new HandlerMethodReference(DelegateBuilder.BuildDelegate <Action <object, object> >(methodInfo), handler, methodInfo.GetParameters().FirstOrDefault()?.ParameterType);
                        HandlerMethods.Add(methodReference.Identification, methodReference);
                    }
                    else
                    {
                        // assume string based handler method
                        HandlerMethodReference methodReference = new HandlerMethodReference(DelegateBuilder.BuildDelegate <Action <object, object> >(methodInfo), handler, packetAttribute);
                        HandlerMethods.Add(methodReference.Identification, methodReference);
                    }
                }
            }
        }
Exemple #2
0
        private void GenerateHandlerReferences(IEnumerable <IPacketHandler> packetDictionary)
        {
            // iterate thru each type in the given assembly
            foreach (IPacketHandler handlerType in packetDictionary)
            {
                IPacketHandler handler = (IPacketHandler)Activator.CreateInstance(handlerType.GetType(), this);

                // include PacketDefinition
                foreach (MethodInfo methodInfo in handlerType.GetType().GetMethods().Where(x => x.GetParameters().FirstOrDefault()?.ParameterType.BaseType == typeof(PacketDefinition)))
                {
                    HandlerMethodReference methodReference = new HandlerMethodReference(DelegateBuilder.BuildDelegate <Action <object, object> >(methodInfo), handler, methodInfo.GetParameters().FirstOrDefault()?.ParameterType);
                    HandlerMethods.Add(methodReference.Identification, methodReference);
                }
            }
        }
Exemple #3
0
        private bool GenerateHandlerReferences(Type handlerType)
        {
            object handler = Activator.CreateInstance(handlerType, new object[] { this });

            foreach (MethodInfo methodInfo in handlerType.GetMethods().Where(x => x.GetCustomAttributes(false).OfType <Packet>().Any()))
            {
                Packet packetAttribute = methodInfo.GetCustomAttributes(false).OfType <Packet>().SingleOrDefault();

                if (packetAttribute != null)
                {
                    HandlerMethods.Add(packetAttribute, new Tuple <MethodInfo, object>(methodInfo, handler));
                }
            }

            return(false);
        }
        private void GenerateHandlerReferences(Type type)
        {
            //iterate thru each type in the given assembly, the IPacketHandler is expected in the same dll
            foreach (Type handlerType in type.Assembly.GetTypes().Where(p => !p.IsInterface && type.GetInterfaces().FirstOrDefault().IsAssignableFrom(p)))
            {
                object handler = Activator.CreateInstance(handlerType, new object[] { this });

                foreach (MethodInfo methodInfo in handlerType.GetMethods().Where(x => x.GetCustomAttributes(false).OfType <Packet>().Any()))
                {
                    Packet packetAttribute = methodInfo.GetCustomAttributes(false).OfType <Packet>().FirstOrDefault();

                    if (packetAttribute != null)
                    {
                        HandlerMethods.Add(packetAttribute, new Tuple <Action <object, string>, object>(DelegateBuilder.BuildDelegate <Action <object, string> >(methodInfo), handler));
                    }
                }
            }
        }
Exemple #5
0
        private void GenerateHandlerReferences(Type type, bool isWorldServer)
        {
            IEnumerable <Type> handlerTypes = !isWorldServer?type.Assembly.GetTypes().Where(t => t.Name.Equals("LoginPacketHandler"))  //shitty but it works
                                                  : type.Assembly.GetTypes().Where(p => !p.IsInterface && type.GetInterfaces().FirstOrDefault().IsAssignableFrom(p));

            //iterate thru each type in the given assembly, the IPacketHandler is expected in the same dll
            foreach (Type handlerType in handlerTypes)
            {
                object handler = Activator.CreateInstance(handlerType, new object[] { this });

                foreach (MethodInfo methodInfo in handlerType.GetMethods().Where(x => x.GetCustomAttributes(false).OfType <PacketAttribute>().Any()))
                {
                    PacketAttribute Packet = methodInfo.GetCustomAttributes(false).OfType <PacketAttribute>().FirstOrDefault();

                    if (Packet != null)
                    {
                        HandlerMethods.Add(Packet, new Tuple <Action <object, string>, object>(DelegateBuilder.BuildDelegate <Action <object, string> >(methodInfo), handler));
                    }
                }
            }
        }