Пример #1
0
        public void Run(ETModel.Session s, ushort opcode, MemoryStream memoryStream)
        {
            OpcodeTypeComponent opcodeTypeComponent = Game.Scene.GetComponent <OpcodeTypeComponent>();
            object instance = opcodeTypeComponent.GetInstance(opcode);
            object message  = this.session.Network.MessagePacker.DeserializeFrom(instance, memoryStream);

            if (OpcodeHelper.IsNeedDebugLogMessage(opcode))
            {
                Log.Msg(message);
            }

            IResponse response = message as IResponse;

            if (response == null)
            {
                Game.Scene.GetComponent <MessageDispatcherComponent>().Handle(session, new MessageInfo(opcode, message));
                return;
            }

            Action <IResponse> action;

            if (!this.requestCallback.TryGetValue(response.RpcId, out action))
            {
                throw new Exception($"not found rpc, response message: {StringHelper.MessageToStr(response)}");
            }
            this.requestCallback.Remove(response.RpcId);

            action(response);
        }
Пример #2
0
        public void Run(ETModel.Session s, byte flag, ushort opcode, MemoryStream memoryStream)
        {
            OpcodeTypeComponent opcodeTypeComponent = Game.Scene.GetComponent <OpcodeTypeComponent>();
            object instance = opcodeTypeComponent.GetInstance(opcode);
            object message  = this.session.Network.MessagePacker.DeserializeFrom(instance, memoryStream);

            if (OpcodeHelper.IsNeedDebugLogMessage(opcode))
            {
                Log.Msg(message);
            }

            if ((flag & 0x01) > 0)
            {
                IResponse response = message as IResponse;
                if (response == null)
                {
                    throw new Exception($"flag is response, but hotfix message is not! {opcode}");
                }

                Action <IResponse> action;
                if (!this.requestCallback.TryGetValue(response.RpcId, out action))
                {
                    return;
                }
                this.requestCallback.Remove(response.RpcId);

                action(response);
                return;
            }

            Game.Scene.GetComponent <MessageDispatherComponent>().Handle(session, new MessageInfo(opcode, message));
        }
Пример #3
0
        public void Run(ETModel.Session s, ushort opcode, MemoryStream memoryStream)
        {
            OpcodeTypeComponent opcodeTypeComponent = Game.Scene.GetComponent <OpcodeTypeComponent>();
            object instance = opcodeTypeComponent.GetInstance(opcode);
            object message  = this.session.Network.MessagePacker.DeserializeFrom(instance, memoryStream);

            //屏蔽心跳日志输出 10009,和广播玩家下注日志 10044  && opcode!= 10044
            if (OpcodeHelper.IsNeedDebugLogMessage(opcode) && opcode != 10009 && opcode != 10044)
            {
                Log.Msg(message, 1);
            }

            IResponse response = message as IResponse;

            //临时解决斗地主,没法收到消息的问题
            if (response != null && response.Error == 200225)
            {
                Game.EventSystem.Run(EventIdType.DDZOutCardError, response.Message);
            }

            if (response == null)
            {
                Game.Scene.GetComponent <MessageDispatcherComponent>().Handle(session, new MessageInfo(opcode, message));
                return;
            }

            Action <IResponse> action;

            if (!this.requestCallback.TryGetValue(response.RpcId, out action))
            {
                throw new Exception($"not found rpc, response message: {StringHelper.MessageToStr(response)}");
            }
            this.requestCallback.Remove(response.RpcId);

            action(response);
        }
Пример #4
0
        public async void Dispatch(Session session, Packet packet)
        {
            object message;

            try
            {
                OpcodeTypeComponent opcodeTypeComponent = session.Network.Entity.GetComponent <OpcodeTypeComponent>();
                object instance = opcodeTypeComponent.GetInstance(packet.Opcode);
                message = session.Network.MessagePacker.DeserializeFrom(instance, packet.Stream);
            }
            catch (Exception e)
            {
                // 出现任何异常都要断开Session,防止客户端伪造消息
                Log.Error(e);
                session.Error = ErrorCode.ERR_PacketParserError;
                session.Network.Remove(session.Id);
                return;
            }

            //Log.Debug($"recv: {JsonHelper.ToJson(message)}");

            switch (message)
            {
            case IFrameMessage iFrameMessage:                     // 如果是帧消息,构造成OneFrameMessage发给对应的unit
            {
                long unitId = session.GetComponent <SessionPlayerComponent>().Player.UnitId;
                ActorMessageSender actorMessageSender = Game.Scene.GetComponent <ActorMessageSenderComponent>().Get(unitId);

                // 这里设置了帧消息的id,防止客户端伪造
                iFrameMessage.Id = unitId;

                OneFrameMessage oneFrameMessage = new OneFrameMessage
                {
                    Op       = packet.Opcode,
                    AMessage = ByteString.CopyFrom(session.Network.MessagePacker.SerializeTo(iFrameMessage))
                };
                actorMessageSender.Send(oneFrameMessage);
                return;
            }

            case IActorRequest iActorRequest:                     // gate session收到actor rpc消息,先向actor 发送rpc请求,再将请求结果返回客户端
            {
                long unitId = session.GetComponent <SessionPlayerComponent>().Player.UnitId;
                ActorMessageSender actorMessageSender = Game.Scene.GetComponent <ActorMessageSenderComponent>().Get(unitId);

                int       rpcId    = iActorRequest.RpcId;                // 这里要保存客户端的rpcId
                IResponse response = await actorMessageSender.Call(iActorRequest);

                response.RpcId = rpcId;

                session.Reply(response);
                return;
            }

            case IActorMessage iActorMessage:                     // gate session收到actor消息直接转发给actor自己去处理
            {
                long unitId = session.GetComponent <SessionPlayerComponent>().Player.UnitId;
                ActorMessageSender actorMessageSender = Game.Scene.GetComponent <ActorMessageSenderComponent>().Get(unitId);
                actorMessageSender.Send(iActorMessage);
                return;
            }
            }

            Game.Scene.GetComponent <MessageDispatherComponent>().Handle(session, new MessageInfo(packet.Opcode, message));
        }