コード例 #1
0
        public static void Load(this MessageDispatcherComponent self)
        {
            self.Handlers.Clear();

            HashSet <Type> types = Game.EventSystem.GetTypes(typeof(MessageHandlerAttribute));

            foreach (Type type in types)
            {
                IMHandler iMHandler = Activator.CreateInstance(type) as IMHandler;
                if (iMHandler == null)
                {
                    Log.Error($"message handle {type.Name} 需要继承 IMHandler");
                    continue;
                }

                Type   messageType = iMHandler.GetMessageType();
                ushort opcode      = OpcodeTypeComponent.Instance.GetOpcode(messageType);
                if (opcode == 0)
                {
                    Log.Error($"消息opcode为0: {messageType.Name}");
                    continue;
                }
                self.RegisterHandler(opcode, iMHandler);
            }
        }
コード例 #2
0
        public void Load()
        {
            this.handlers.Clear();

            List <Type> types = Game.EventSystem.GetTypes(typeof(MessageHandlerAttribute));

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

                IMHandler iMHandler = Activator.CreateInstance(type) as IMHandler;
                if (iMHandler == null)
                {
                    Log.Error($"message handle {type.Name} 需要继承 IMHandler");
                    continue;
                }

                Type messageType = iMHandler.GetMessageType();
                MessageHandlerAttribute attribute = attrs[0] as MessageHandlerAttribute;
                int opcode = attribute.Opcode;

                if (opcode == 0)
                {
                    Log.Error($"消息opcode为0: {messageType.Name}");
                    continue;
                }
                this.RegisterHandler(opcode, iMHandler);
                this.typeMessages.Add(opcode, Activator.CreateInstance(messageType));
            }
        }
コード例 #3
0
        public void Load()
        {
            this.handlers.Clear();

            HashSet <Type> types = Game.EventSystem.GetTypes(typeof(MessageHandlerAttribute));

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

                IMHandler iMHandler = Activator.CreateInstance(type) as IMHandler;
                if (iMHandler == null)
                {
                    Log.Error($"message handle {type.Name} 需要继承 IMHandler");
                    continue;
                }

                Type   messageType = iMHandler.GetMessageType();
                ushort opcode      = this.Entity.GetComponent <OpcodeTypeComponent>().GetOpcode(messageType);
                if (opcode == 0)
                {
                    Log.Error($"消息opcode为0: {messageType.Name}");
                    continue;
                }
                this.RegisterHandler(opcode, iMHandler);
            }
        }
コード例 #4
0
        public void Load(Assembly assembly)
        {
            var types       = AssemblyManager.Instance.GetAllTypesByAttribute(assembly, typeof(MessageHandlerAttribute));
            var iopCodeType = GetParent <NetWorkBs>().IOpCodeType;

            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(MessageHandlerAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }
                MessageHandlerAttribute messageHandlerAttribute = attrs[0] as MessageHandlerAttribute;
                if (messageHandlerAttribute == null)
                {
                    continue;
                }
                IMHandler iMHandler = Activator.CreateInstance(type) as IMHandler;
                if (iMHandler == null)
                {
                    Log.Error($"message handle {type.Name} 需要继承 IMHandler");
                    continue;
                }
                Type   messageType = iMHandler.GetMessageType();
                ushort opcode      = iopCodeType.GetOpcode(messageType);
                if (opcode == 0)
                {
                    Log.Error($"消息opcode为0: {messageType.Name}");
                    continue;
                }

                RegisterHandler(opcode, iMHandler);
            }
        }
コード例 #5
0
        private static void Load(this MessageDispatcherComponent self)
        {
            self.Handlers.Clear();

            HashSet <Type> types = Game.EventSystem.GetTypes(typeof(MessageHandlerAttribute));

            foreach (Type type in types)
            {
                IMHandler iMHandler = Activator.CreateInstance(type) as IMHandler;
                if (iMHandler == null)
                {
                    Log.Error($"message handle {type.Name} 需要继承 IMHandler");
                    continue;
                }

                object[] attrs = type.GetCustomAttributes(typeof(MessageHandlerAttribute), false);

                foreach (object attr in attrs)
                {
                    MessageHandlerAttribute messageHandlerAttribute = attr as MessageHandlerAttribute;

                    Type messageType = iMHandler.GetMessageType();

                    ushort opcode = OpcodeTypeComponent.Instance.GetOpcode(messageType);
                    if (opcode == 0)
                    {
                        Log.Error($"消息opcode为0: {messageType.Name}");
                        continue;
                    }

                    MessageDispatcherInfo messageDispatcherInfo = new (messageHandlerAttribute.SceneType, iMHandler);
                    self.RegisterHandler(opcode, messageDispatcherInfo);
                }
            }
        }
コード例 #6
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);
                }
            }
        }
コード例 #7
0
        public static void Load(this MessageDispatherComponent self)
        {
            self.Handlers.Clear();


            Type[] types = DllHelper.GetMonoTypes();

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


                IMHandler iMHandler = Activator.CreateInstance(type) as IMHandler;
                if (iMHandler == null)
                {
                    Log.Error($"message handle {type.Name} 需要继承 IMHandler");
                    continue;
                }

                Type   messageType = iMHandler.GetMessageType();
                ushort opcode      = Game.Scene.GetComponent <OpcodeTypeComponent>().GetOpcode(messageType);
                if (opcode == 0)
                {
                    Log.Error($"消息opcode为0: {messageType.Name}");
                    continue;
                }
                self.RegisterHandler(opcode, iMHandler);
            }
        }
コード例 #8
0
        public void Load()
        {
            this.handlers.Clear();

            List <Type> types = NetWork.AttributeSystem.GetTypes(typeof(MessageHandlerAttribute));

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

                IMHandler iMHandler = Activator.CreateInstance(type) as IMHandler;
                if (iMHandler == null)
                {
                    Debug.Fail($"message handle {type.Name} 需要继承 IMHandler");
                    continue;
                }

                Type messageType = iMHandler.GetMessageType();


                uint opcode = netWork.opcodeTypeComponent.GetOpcode(messageType);
                if (opcode == 0)
                {
                    Debug.Fail($"消息opcode为0: {messageType.Name}");
                    continue;
                }
                this.RegisterHandler(opcode, iMHandler);
            }
        }
コード例 #9
0
        public void Load()
        {
            this.handlers.Clear();

            //ETModel.MessageDispatcherComponent messageDispatcherComponent = ETModel.Game.Scene.GetComponent<ETModel.MessageDispatcherComponent>();
            //ETModel.OpcodeTypeComponent opcodeTypeComponent = ETModel.Game.Scene.GetComponent<ETModel.OpcodeTypeComponent>();


            List <Type> types = Game.EventSystem.GetTypes();

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

                IMHandler iMHandler = Activator.CreateInstance(type) as IMHandler;
                if (iMHandler == null)
                {
                    Log.Error($"message handle {type.Name} 需要继承 IMHandler");
                    continue;
                }

                Type messageType = iMHandler.GetMessageType();
                //ushort opcode = this.Entity.GetComponent<OpcodeTypeComponent>().GetOpcode(messageType);

                MessageHandlerAttribute attribute = attrs[0] as MessageHandlerAttribute;
                int opcode = attribute.Opcode;
                if (opcode != 0)
                {
                    this.RegisterHandler(opcode, iMHandler);
                    this.typeMessages.Add(opcode, Activator.CreateInstance(messageType));
                }

                // 尝试注册到mono层
                //if (messageDispatcherComponent != null && opcodeTypeComponent != null)
                //{
                //	ushort monoOpcode = opcodeTypeComponent.GetOpcode(messageType);
                //	if (monoOpcode == 0)
                //	{
                //		continue;
                //	}

                //	MessageProxy messageProxy = new MessageProxy(messageType, (session, o) => { iMHandler.Handle(session, o); });
                //	messageDispatcherComponent.RegisterHandler(monoOpcode, messageProxy);
                //}
            }
        }
コード例 #10
0
        public void Load()
        {
            this.handlers.Clear();

            Model.MessageDispatherComponent messageDispatherComponent = Game.Scene.GetComponent <Model.MessageDispatherComponent>();
            Model.OpcodeTypeComponent       opcodeTypeComponent       = Game.Scene.GetComponent <Model.OpcodeTypeComponent>();

            Type[] types = DllHelper.GetHotfixTypes();

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

                IMHandler iMHandler = Activator.CreateInstance(type) as IMHandler;
                if (iMHandler == null)
                {
                    Log.Error($"message handle {type.Name} 需要继承 IMHandler");
                    continue;
                }

                Type   messageType = iMHandler.GetMessageType();
                ushort opcode      = this.Entity.GetComponent <OpcodeTypeComponent>().GetOpcode(messageType);
                if (opcode != 0)
                {
                    this.RegisterHandler(opcode, iMHandler);
                }

                // 尝试注册到mono层
                if (messageDispatherComponent != null && opcodeTypeComponent != null)
                {
                    ushort monoOpcode = opcodeTypeComponent.GetOpcode(messageType);
                    if (monoOpcode == 0)
                    {
                        continue;
                    }

                    MessageProxy messageProxy = new MessageProxy(messageType, (session, o) => { iMHandler.Handle(session, o); });
                    messageDispatherComponent.RegisterHandler(monoOpcode, messageProxy);
                }
            }
        }
コード例 #11
0
        public static void Load(this MessageDispatcherComponent self)
        {
            self.Handlers.Clear();
            //获取到配置的appType 在服务器启动的时候有缓存
            AppType appType = StartConfigComponent.Instance.StartConfig.AppType;
            //获取到所有加了MessageHandler特性的类型
            List <Type> types = Game.EventSystem.GetTypes(typeof(MessageHandlerAttribute));

            //对获取到的类型进行遍历
            foreach (Type type in types)
            {            //获取该类型自定义的属性
                object[] attrs = type.GetCustomAttributes(typeof(MessageHandlerAttribute), false);
                if (attrs.Length == 0)
                {                //如果属性的个数是0 遍历下一个元素
                    continue;
                }
                //如果第一个属性是MessageHandler
                MessageHandlerAttribute messageHandlerAttribute = attrs[0] as MessageHandlerAttribute;
                if (!messageHandlerAttribute.Type.Is(appType))
                {                //判断它的type参数,如果不等于当前的appType 继续遍历下一个元素 如果类型一致 下面要对其进行缓存的
                    continue;
                }
                //根据类型,创建实例实例 判断实例如果继承了IMHandler的接口
                IMHandler iMHandler = Activator.CreateInstance(type) as IMHandler;
                if (iMHandler == null)
                {
                    Log.Error($"message handle {type.Name} 需要继承 IMHandler");
                    continue;
                }
                //通过接口内部的GetMessageType方法 获取到要处理的proto类型 因为我们是继承自AMHanlde 所以实际是获取AMHanlde里的GetMessageType
                Type messageType = iMHandler.GetMessageType();
                //通过类型获取协议号
                ushort opcode = Game.Scene.GetComponent <OpcodeTypeComponent>().GetOpcode(messageType);
                if (opcode == 0)
                {                //异常 协议号都是自动生成的 不可能为0
                    Log.Error($"消息opcode为0: {messageType.Name}");
                    continue;
                }
                //注册 也就是缓存起来 同时将协议ID与处理的实例关联起来 .... 说简单点就是创建个字典 添加到字典内部去
                self.RegisterHandler(opcode, iMHandler);
            }
        }
コード例 #12
0
        public static void Load(this MessageDispatcherComponent self)
        {
            self.Handlers.Clear();

            AppType appType = StartConfigComponent.Instance.StartConfig.AppType;

            List <Type> types = Game.EventSystem.GetTypes(typeof(MessageHandlerAttribute));

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

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

                IMHandler iMHandler = Activator.CreateInstance(type) as IMHandler;
                if (iMHandler == null)
                {
                    Log.Error($"message handle {type.Name} 需要继承 IMHandler");
                    continue;
                }

                Type   messageType = iMHandler.GetMessageType();
                ushort opcode      = Game.Scene.GetComponent <OpcodeTypeComponent>().GetOpcode(messageType);
                if (opcode == 0)
                {
                    Log.Error($"消息opcode为0: {messageType.Name}");
                    continue;
                }
                self.RegisterHandler(opcode, iMHandler);
            }
        }
コード例 #13
0
        public void Load()
        {
            AppType appType = this.Parent.GetComponent <StartConfigComponent>().StartConfig.AppType;

            this.handlers = new Dictionary <Type, List <IMHandler> >();

            Type[] types = DllHelper.GetMonoTypes();
            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(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();
                if (!this.handlers.TryGetValue(messageType, out List <IMHandler> list))
                {
                    list = new List <IMHandler>();
                    this.handlers.Add(messageType, list);
                }
                list.Add(imHandler);
            }
        }
コード例 #14
0
        //加载
        public void Load()
        {
            this.handlers.Clear();
            //先获取开发时候写的 所有用于处理网络消息的类
            //加了MessageHandlerAttribute特性的
            List <Type> types = Game.EventSystem.GetTypes(typeof(MessageHandlerAttribute));

            foreach (Type type in types)
            {
                //找到非继承的
                object[] attrs = type.GetCustomAttributes(typeof(MessageHandlerAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }
                //并且是直接或间接继承自IMHandler接口的
                //其中AMHanlde就是继承自IMHandle,所以继承自AMHandler的类也可以转化为IMHandler
                //那么iMHandler就不会等于null了.
                IMHandler iMHandler = Activator.CreateInstance(type) as IMHandler;
                if (iMHandler == null)
                {
                    Log.Error($"message handle {type.Name} 需要继承 IMHandler");
                    continue;
                }
                //获取消息类型
                Type messageType = iMHandler.GetMessageType();
                //根据类型获取到操作码/协议号 opcode
                ushort opcode = this.Entity.GetComponent <OpcodeTypeComponent>().GetOpcode(messageType);
                if (opcode == 0)
                {
                    Log.Error($"消息opcode为0: {messageType.Name}");
                    continue;
                }
                //注册存储处理的方法,key:操作码 value:实例
                //后面调用Handle的时候就可以通过key找到实例,然后进行调用
                this.RegisterHandler(opcode, iMHandler);
            }
        }
コード例 #15
0
        public void Awake(AppType appType)
        {
            this.AppType = appType;
            this.handlers.Clear();

            var types = Game.EventSystem.GetTypes();// DllHelper.GetMonoTypes(DllHelper.GetLogicAssembly());

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

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

                IMHandler iMHandler = Activator.CreateInstance(type) as IMHandler;
                if (iMHandler == null)
                {
                    continue;
                }

                Type   messageType = iMHandler.GetMessageType();
                ushort opcode      = (this.Parent as Entity).GetComponent <OpcodeTypeComponent>().GetOpcode(messageType);
                if (opcode == 0)
                {
                    continue;
                }

                this.RegisterHandler(opcode, iMHandler);
            }
        }