Exemplo n.º 1
0
        public static async ETTask Handle(this MailBoxComponent self, Session session, IActorMessage message)
        {
            using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Mailbox, message.ActorId))
            {
                switch (self.MailboxType)
                {
                case MailboxType.GateSession:
                    IActorMessage iActorMessage = message as IActorMessage;
                    // 发送给客户端
                    Session clientSession = self.Parent as Session;
                    iActorMessage.ActorId = 0;
                    clientSession.Send(iActorMessage);
                    break;

                case MailboxType.MessageDispatcher:
                    await ActorMessageDispatcherComponent.Instance.Handle(self.Parent, session, message);

                    break;

                case MailboxType.UnOrderMessageDispatcher:
                    self.HandleInner(session, message).Coroutine();
                    break;
                }
            }
        }
Exemplo n.º 2
0
        public static void HandleIActorMessage(ushort opcode, long actorId, IActorMessage iActorMessage)
        {
            OpcodeHelper.LogMsg(opcode, actorId, iActorMessage);

            Entity entity = Game.EventSystem.Get(actorId);

            if (entity == null)
            {
                Log.Error($"not found actor: {actorId} {iActorMessage}");
                return;
            }

            MailBoxComponent mailBoxComponent = entity.GetComponent <MailBoxComponent>();

            if (mailBoxComponent == null)
            {
                Log.Error($"actor not found mailbox: {entity.GetType().Name} {actorId} {iActorMessage}");
                return;
            }

            switch (mailBoxComponent.MailboxType)
            {
            case MailboxType.MessageDispatcher:
            {
                async ETTask MessageDispatcherHandler()
                {
                    long instanceId = entity.InstanceId;

                    using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Mailbox, actorId))
                    {
                        if (entity.InstanceId != instanceId)
                        {
                            return;
                        }

                        await ActorMessageDispatcherComponent.Instance.Handle(entity, iActorMessage, null);
                    }
                }

                MessageDispatcherHandler().Coroutine();
                break;
            }

            case MailboxType.UnOrderMessageDispatcher:
            {
                ActorMessageDispatcherComponent.Instance.Handle(entity, iActorMessage, null).Coroutine();
                break;
            }
            }
        }
Exemplo n.º 3
0
        public static void HandleIActorRequest(ushort opcode, long actorId, IActorRequest iActorRequest, Action <IActorResponse> reply)
        {
            Entity entity = Game.EventSystem.Get(actorId);

            if (entity == null)
            {
                FailResponse(iActorRequest, ErrorCore.ERR_NotFoundActor, reply);
                return;
            }

            MailBoxComponent mailBoxComponent = entity.GetComponent <MailBoxComponent>();

            if (mailBoxComponent == null)
            {
                Log.Warning($"actor not found mailbox: {entity.GetType().Name} {actorId} {iActorRequest}");
                FailResponse(iActorRequest, ErrorCore.ERR_NotFoundActor, reply);
                return;
            }

            switch (mailBoxComponent.MailboxType)
            {
            case MailboxType.MessageDispatcher:
            {
                async ETTask MessageDispatcherHandler()
                {
                    long instanceId = entity.InstanceId;

                    using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Mailbox, actorId))
                    {
                        if (entity.InstanceId != instanceId)
                        {
                            FailResponse(iActorRequest, ErrorCore.ERR_NotFoundActor, reply);
                            return;
                        }

                        await ActorMessageDispatcherComponent.Instance.Handle(entity, iActorRequest, reply);
                    }
                }

                MessageDispatcherHandler().Coroutine();
                break;
            }

            case MailboxType.UnOrderMessageDispatcher:
            {
                ActorMessageDispatcherComponent.Instance.Handle(entity, iActorRequest, reply).Coroutine();
                break;
            }
            }
        }
Exemplo n.º 4
0
 private static async ETVoid HandleInner(this MailBoxComponent self, Session session, IActorMessage message)
 {
     await ActorMessageDispatcherComponent.Instance.Handle(self.Parent, session, message);
 }