Inheritance: System.Attribute
Esempio n. 1
0
        private void Load()
        {
            this.handlers      = new Dictionary <ushort, List <IMHandler> >();
            this.messageOpcode = new Dictionary <Type, MessageAttribute>();

            Assembly[] assemblies = Game.EntityEventManager.GetAssemblies();

            foreach (Assembly assembly in assemblies)
            {
                Type[] types = assembly.GetTypes();
                foreach (Type type in types)
                {
                    object[] attrs = type.GetCustomAttributes(typeof(MessageAttribute), false);
                    if (attrs.Length == 0)
                    {
                        continue;
                    }

                    MessageAttribute messageAttribute = (MessageAttribute)attrs[0];
                    this.messageOpcode[type] = messageAttribute;
                }
            }

            foreach (Assembly assembly in assemblies)
            {
                Type[] types = assembly.GetTypes();
                foreach (Type type in types)
                {
                    object[] attrs = type.GetCustomAttributes(typeof(MessageHandlerAttribute), false);
                    if (attrs.Length == 0)
                    {
                        continue;
                    }

                    MessageHandlerAttribute messageHandlerAttribute = (MessageHandlerAttribute)attrs[0];
                    if (!messageHandlerAttribute.Type.Is(this.AppType))
                    {
                        continue;
                    }

                    object obj = Activator.CreateInstance(type);

                    IMHandler imHandler = obj as IMHandler;
                    if (imHandler == null)
                    {
                        throw new Exception($"message handler not inherit AMEvent or AMRpcEvent abstract class: {obj.GetType().FullName}");
                    }

                    Type             messageType = imHandler.GetMessageType();
                    ushort           opcode      = this.GetOpcode(messageType);
                    List <IMHandler> list;
                    if (!this.handlers.TryGetValue(opcode, out list))
                    {
                        list = new List <IMHandler>();
                        this.handlers.Add(opcode, list);
                    }
                    list.Add(imHandler);
                }
            }
        }
Esempio n. 2
0
        public void Load(Assembly assembly)
        {
            this.events      = new Dictionary <Opcode, Func <byte[], byte[]> >();
            this.eventsAsync = new Dictionary <Opcode, Func <byte[], Task <byte[]> > >();

            ServerType serverType = World.Instance.Options.ServerType;

            Type[] types = assembly.GetTypes();
            foreach (Type t in types)
            {
                object[] attrs = t.GetCustomAttributes(typeof(MessageAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }

                MessageAttribute messageAttribute = (MessageAttribute)attrs[0];
                if (!messageAttribute.Contains(serverType))
                {
                    continue;
                }

                object obj = Activator.CreateInstance(t);

                IRegister iRegister = obj as IRegister;
                iRegister?.Register();

                throw new Exception($"message handler not inherit IRegister interface: {obj.GetType().FullName}");
            }
        }
        private void Load()
        {
            this.handlers    = new Dictionary <ushort, List <IInstanceMethod> >();
            this.opcodeTypes = new DoubleMap <ushort, Type>();

            Type[] monoTypes = DllHelper.GetMonoTypes();
            foreach (Type monoType in monoTypes)
            {
                object[] attrs = monoType.GetCustomAttributes(typeof(MessageAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }

                MessageAttribute messageAttribute = attrs[0] as MessageAttribute;
                if (messageAttribute == null)
                {
                    continue;
                }

                this.opcodeTypes.Add(messageAttribute.Opcode, monoType);
            }

#if ILRuntime
            Type[] types = DllHelper.GetHotfixTypes();
#else
            Type[] types = DllHelper.GetMonoTypes();
#endif
            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(MessageHandlerAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }
                MessageHandlerAttribute messageHandlerAttribute = (MessageHandlerAttribute)attrs[0];
#if ILRuntime
                IInstanceMethod method = new ILInstanceMethod(type, "Handle");
#else
                IInstanceMethod method = new MonoInstanceMethod(type, "Handle");
#endif
                if (!this.handlers.ContainsKey(messageHandlerAttribute.Opcode))
                {
                    this.handlers.Add(messageHandlerAttribute.Opcode, new List <IInstanceMethod>());
                }
                this.handlers[messageHandlerAttribute.Opcode].Add(method);
            }
        }
 public void Initialize()
 {
     Type[] monoTypes = DllHelper.GetMonoTypes();
     foreach (Type monoType in monoTypes)
     {
         object[] attrs = monoType.GetCustomAttributes(typeof(MessageAttribute), false);
         if (attrs.Length == 0)
         {
             continue;
         }
         MessageAttribute messageAttribute = attrs[0] as MessageAttribute;
         if (messageAttribute == null)
         {
             continue;
         }
         this.mOpcodeTypes.Add(messageAttribute.Opcode, monoType);
     }
 }
Esempio n. 5
0
        public void Load()
        {
            this.opcodeType    = new Dictionary <Opcode, Type>();
            this.messageOpcode = new Dictionary <Type, MessageAttribute>();

            Type[] types = DllHelper.GetMonoTypes();
            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(MessageAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }

                MessageAttribute messageAttribute = (MessageAttribute)attrs[0];
                this.messageOpcode[type] = messageAttribute;
                this.opcodeType[messageAttribute.Opcode] = type;
            }
        }
Esempio n. 6
0
        public void Awake()
        {
            Type[] types = DllHelper.GetAllTypes();
            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(MessageAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }

                MessageAttribute messageAttribute = attrs[0] as MessageAttribute;
                if (messageAttribute == null)
                {
                    continue;
                }

                this.opcodeTypes.Add(messageAttribute.Opcode, type);
            }
        }