Пример #1
0
        public void Run(ETModel.Session s, Packet packet)
        {
            ushort opcode = packet.Opcode;
            byte   flag   = packet.Flag;

            OpcodeTypeComponent opcodeTypeComponent = Game.Scene.GetComponent <OpcodeTypeComponent>();
            Type   responseType = opcodeTypeComponent.GetType(opcode);
            object message      = this.session.Network.MessagePacker.DeserializeFrom(responseType, packet.Stream);

            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));
        }
Пример #2
0
        public async Task Handle(Session session, Entity entity, ActorRequest actorRequest)
        {
            ActorResponse actorResponse = new ActorResponse();

            actorResponse.RpcId = actorRequest.RpcId;

            try
            {
                OpcodeTypeComponent opcodeTypeComponent = session.Network.Entity.GetComponent <OpcodeTypeComponent>();
                Type     type    = opcodeTypeComponent.GetType(actorRequest.Op);
                IMessage message = (IMessage)session.Network.MessagePacker.DeserializeFrom(type, actorRequest.AMessage);

                // 发送给客户端
                Session clientSession = entity as Session;
                clientSession.Send(actorResponse.Flag, message);

                session.Reply(actorResponse);
                await Task.CompletedTask;
            }
            catch (Exception e)
            {
                actorResponse.Error   = ErrorCode.ERR_SessionActorError;
                actorResponse.Message = $"session actor error {e}";
                session.Reply(actorResponse);
                throw;
            }
        }
Пример #3
0
        public void Run(Session s, Packet p)
        {
            ushort opcode = p.Opcode();
            byte   flag   = p.Flag();

            OpcodeTypeComponent opcodeTypeComponent = Game.Scene.GetComponent <OpcodeTypeComponent>();
            Type   responseType = opcodeTypeComponent.GetType(opcode);
            object message      = ProtobufHelper.FromBytes(responseType, p.Bytes, Packet.Index, p.Length - Packet.Index);

            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));
        }
 public async Task Handle(Session session, Entity entity, ActorRequest actorRequest)
 {
     OpcodeTypeComponent opcodeTypeComponent = session.Network.Entity.GetComponent <OpcodeTypeComponent>();
     Type     type    = opcodeTypeComponent.GetType(actorRequest.Op);
     IMessage message = (IMessage)session.Network.MessagePacker.DeserializeFrom(type, actorRequest.AMessage);
     await Game.Scene.GetComponent <ActorMessageDispatherComponent>().Handle(session, entity, actorRequest, message);
 }
Пример #5
0
        public static async Task <IResponse> Call(this Session session, IRequest request)
        {
            OpcodeTypeComponent opcodeTypeComponent = Game.Scene.GetComponent <OpcodeTypeComponent>();

            byte[]     bytes      = ProtobufHelper.ToBytes(request);
            ushort     opcode     = opcodeTypeComponent.GetOpcode(request.GetType());
            PacketInfo packetInfo = await session.Call(opcode, bytes);

            ushort    responseOpcode = packetInfo.Opcode;
            Type      t        = opcodeTypeComponent.GetType(responseOpcode);
            object    aa       = ProtobufHelper.FromBytes(t, packetInfo.Bytes, packetInfo.Index, packetInfo.Length);
            IResponse response = (IResponse)aa;

            return(response);
        }
        public async Task Handle(Session session, Entity entity, ActorRequest actorRequest)
        {
            OpcodeTypeComponent opcodeTypeComponent = session.Network.Entity.GetComponent <OpcodeTypeComponent>();
            Type     type    = opcodeTypeComponent.GetType(actorRequest.Op);
            IMessage message = (IMessage)session.Network.MessagePacker.DeserializeFrom(type, actorRequest.AMessage);

            if (message is OneFrameMessage aFrameMessage)
            {
                Game.Scene.GetComponent <ServerFrameComponent>().Add(aFrameMessage);

                ActorResponse actorResponse = new ActorResponse();
                actorResponse.RpcId = actorRequest.RpcId;
                session.Reply(actorResponse);
                return;
            }
            await Game.Scene.GetComponent <ActorMessageDispatherComponent>().Handle(session, entity, actorRequest, message);
        }