public void Handle(Session session, AMessage message)
 {
     try
     {
         Request request = message as Request;
         if (request == null)
         {
             Log.Error($"消息类型转换错误: {message.GetType().Name} to {typeof (Request).Name}");
         }
         this.Run(session, request, response =>
         {
             // 等回调回来,session可以已经断开了,所以需要判断session id是否为0
             if (session.Id == 0)
             {
                 return;
             }
             response.RpcId = request.RpcId;
             session.Reply(response);
         });
     }
     catch (Exception e)
     {
         throw new Exception($"解释消息失败: {message.GetType().FullName}", e);
     }
 }
示例#2
0
        public void Dispatch(Session session, ushort opcode, int offset, byte[] messageBytes, AMessage message)
        {
            // 如果是帧同步消息,交给ClientFrameComponent处理
            FrameMessage frameMessage = message as FrameMessage;

            if (frameMessage != null)
            {
                Game.Scene.GetComponent <ClientFrameComponent>().Add(frameMessage);
                return;
            }

            // 普通消息或者是Rpc请求消息
            if (message is AMessage || message is ARequest)
            {
                MessageInfo messageInfo = new MessageInfo(opcode, message);
                if (opcode < 2000)
                {
                    Game.Scene.GetComponent <CrossComponent>().Run(CrossIdType.MessageDeserializeFinish, messageInfo);
                }
                else
                {
                    Game.Scene.GetComponent <MessageDispatherComponent>().Handle(messageInfo);
                }
                return;
            }

            throw new Exception($"message type error: {message.GetType().FullName}");
        }
        public async void Dispatch(Session session, ushort opcode, int offset, byte[] messageBytes, AMessage message)
        {
            // gate session收到actor消息直接转发给actor自己去处理
            if (message is AActorMessage)
            {
                long       unitId     = session.GetComponent <SessionPlayerComponent>().Player.UnitId;
                ActorProxy actorProxy = Game.Scene.GetComponent <ActorProxyComponent>().Get(unitId);
                actorProxy.Send(message);
                return;
            }

            // gate session收到actor rpc消息,先向actor 发送rpc请求,再将请求结果返回客户端
            if (message is AActorRequest aActorRequest)
            {
                long       unitId     = session.GetComponent <SessionPlayerComponent>().Player.UnitId;
                ActorProxy actorProxy = Game.Scene.GetComponent <ActorProxyComponent>().Get(unitId);
                uint       rpcId      = aActorRequest.RpcId;
                AResponse  response   = await actorProxy.Call <AResponse>(aActorRequest);

                response.RpcId = rpcId;
                session.Reply(response);
                return;
            }

            if (message != null)
            {
                Game.Scene.GetComponent <MessageDispatherComponent>().Handle(session, message);
                return;
            }

            throw new Exception($"message type error: {message.GetType().FullName}");
        }
示例#4
0
        public void Handle(AMessage msg)
        {
            Message message = msg as Message;

            if (message == null)
            {
                Log.Error($"消息类型转换错误: {msg.GetType().Name} to {typeof(Message).Name}");
            }
            this.Run(message);
        }
        public void Handle(Session session, AMessage message)
        {
            if (!this.handlers.TryGetValue(message.GetType(), out List <IMHandler> actions))
            {
                Log.Error($"消息 {message.GetType().FullName} 没有处理");
                return;
            }

            foreach (IMHandler ev in actions)
            {
                try
                {
                    ev.Handle(session, message);
                }
                catch (Exception e)
                {
                    Log.Error(e.ToString());
                }
            }
        }
示例#6
0
        public void Dispatch(Session session, ushort opcode, int offset, byte[] messageBytes, AMessage message)
        {
            // 收到actor rpc request
            if (message is ActorRpcRequest actorRpcRequest)
            {
                Entity entity = Game.Scene.GetComponent <ActorManagerComponent>().Get(actorRpcRequest.Id);
                if (entity == null)
                {
                    Log.Warning($"not found actor: {actorRpcRequest.Id}");
                    ActorRpcResponse response = new ActorRpcResponse
                    {
                        RpcId = actorRpcRequest.RpcId,
                        Error = ErrorCode.ERR_NotFoundActor
                    };
                    session.Reply(response);
                    return;
                }
                entity.GetComponent <ActorComponent>().Add(new ActorMessageInfo()
                {
                    Session = session, Message = actorRpcRequest
                });
                return;
            }

            // 收到actor消息分发给actor自己去处理
            if (message is ActorRequest actorRequest)
            {
                Entity entity = Game.Scene.GetComponent <ActorManagerComponent>().Get(actorRequest.Id);
                if (entity == null)
                {
                    Log.Warning($"not found actor: {actorRequest.Id}");
                    ActorResponse response = new ActorResponse
                    {
                        RpcId = actorRequest.RpcId,
                        Error = ErrorCode.ERR_NotFoundActor
                    };
                    session.Reply(response);
                    return;
                }
                entity.GetComponent <ActorComponent>().Add(new ActorMessageInfo()
                {
                    Session = session, Message = actorRequest
                });
                return;
            }

            if (message is AMessage || message is ARequest)
            {
                Game.Scene.GetComponent <MessageDispatherComponent>().Handle(session, message);
                return;
            }

            throw new Exception($"message type error: {message.GetType().FullName}");
        }
示例#7
0
        public void Handle(Session session, AMessage msg)
        {
            Message message = msg as Message;

            if (message == null)
            {
                Log.Error($"消息类型转换错误: {msg.GetType().Name} to {typeof(Message).Name}");
                return;
            }
            if (session.Id == 0)
            {
                Log.Error($"session disconnect {msg}");
                return;
            }
            this.Run(session, message);
        }
示例#8
0
        public void Dispatch(Session session, Opcode opcode, int offset, byte[] messageBytes, AMessage message)
        {
            // 如果是帧同步消息,交给ClientFrameComponent处理
            FrameMessage frameMessage = message as FrameMessage;

            if (frameMessage != null)
            {
                Game.Scene.GetComponent <ClientFrameComponent>().Add(session, frameMessage);
                return;
            }

            // 普通消息或者是Rpc请求消息
            if (message is AMessage || message is ARequest)
            {
                MessageInfo messageInfo = new MessageInfo(opcode, message);
                Game.Scene.GetComponent <MessageDispatherComponent>().Handle(session, messageInfo);
                return;
            }

            throw new Exception($"message type error: {message.GetType().FullName}");
        }
示例#9
0
        public void Dispatch(Session session, ushort opcode, int offset, byte[] messageBytes, AMessage message)
        {
            // 收到actor消息分发给actor自己去处理
            if (message is ActorRequest actorRequest)
            {
                Entity entity = Game.Scene.GetComponent <ActorManagerComponent>().Get(actorRequest.Id);
                entity.GetComponent <ActorComponent>().Add(new ActorMessageInfo()
                {
                    Session = session, Message = actorRequest
                });
                return;
            }

            if (message is AMessage || message is ARequest)
            {
                Game.Scene.GetComponent <MessageDispatherComponent>().Handle(session, message);
                return;
            }

            throw new Exception($"message type error: {message.GetType().FullName}");
        }