Пример #1
0
        public async Task Handle(Session session, Entity entity, IActorLanuch actorLaunch)
        {
            Message msg = actorLaunch as Message;

            if (msg == null)
            {
                Log.Error($"消息类型转换错误: {actorLaunch.GetType().FullName} to {typeof (Message).Name}");
                return;
            }
            E e = entity as E;

            if (e == null)
            {
                Log.Error($"Actor类型转换错误: {entity.GetType().Name} to {typeof(E).Name}");
                return;
            }

            int           rpcId    = actorLaunch.RpcId;
            ActorResponse response = new ActorResponse
            {
                RpcId = rpcId
            };

            session.Reply(response);

            await this.Run(e, msg);
        }
Пример #2
0
        public async Task Handle(Session session, Entity entity, IActorLanuch actorLaunch)
        {
            ActorResponse actorResponse = new ActorResponse
            {
                RpcId = actorLaunch.RpcId
            };

            try
            {
                // 发送给客户端
                Session clientSession = entity as Session;
                actorLaunch.ActorId = 0;
                clientSession.Send(actorLaunch);

                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 async Task Handle(Session session, Entity entity, IActorLanuch actorLaunch)
        {
            try
            {
                Request request = actorLaunch as Request;
                if (request == null)
                {
                    Log.Error($"消息类型转换错误: {actorLaunch.GetType().FullName} to {typeof (Request).Name}");
                    return;
                }
                E e = entity as E;
                if (e == null)
                {
                    Log.Error($"Actor类型转换错误: {entity.GetType().Name} to {typeof(E).Name}");
                    return;
                }

                int rpcId = request.RpcId;

                long instanceId = session.InstanceId;

                await this.Run(e, request, response =>
                {
                    // 等回调回来,session可以已经断开了,所以需要判断session InstanceId是否一样
                    if (session.InstanceId != instanceId)
                    {
                        return;
                    }
                    response.RpcId = rpcId;

                    session.Reply(response);
                });
            }
            catch (Exception e)
            {
                throw new Exception($"解释消息失败: {actorLaunch.GetType().FullName}", e);
            }
        }
Пример #4
0
 public async Task Handle(Session session, Entity entity, IActorLanuch actorMessage)
 {
     await Game.Scene.GetComponent <ActorMessageDispatherComponent>().Handle(session, entity, actorMessage);
 }
Пример #5
0
        /// <summary>
        /// 根据actor消息分发给ActorMessageHandler处理
        /// </summary>
        public static async Task Handle(this ActorMessageDispatherComponent self, Session session, Entity entity, IActorLanuch actorLaunch)
        {
            if (!self.ActorMessageHandlers.TryGetValue(actorLaunch.GetType(), out IMActorHandler handler))
            {
                throw new Exception($"not found message handler: {MongoHelper.ToJson(actorLaunch)}");
            }

            await handler.Handle(session, entity, actorLaunch);
        }
Пример #6
0
 public ActorTask(IActorLanuch actorLaunch, TaskCompletionSource <IResponse> tcs)
 {
     this.ActorLaunch = actorLaunch;
     this.Tcs         = tcs;
 }
Пример #7
0
 public ActorTask(IActorLanuch actorLaunch)
 {
     this.ActorLaunch = actorLaunch;
     this.Tcs         = null;
 }