예제 #1
0
        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}");
        }
예제 #2
0
        public override void Dispose()
        {
            if (this.Id == 0)
            {
                return;
            }

            base.Dispose();

            //向登录服务器发送玩家断开消息
            IPEndPoint realmAddress = Game.Scene.GetComponent <StartConfigComponent>().RealmConfig.GetComponent <InnerConfig>().IPEndPoint;
            Session    realmSession = Game.Scene.GetComponent <NetInnerComponent>().Get(realmAddress);

            realmSession.Send(new PlayerDisconnect()
            {
                UserId = Player.UserId
            });

            //如果在匹配中或游戏中发送退出消息
            if (Player.ActorId != 0)
            {
                ActorProxy actorProxy = Game.Scene.GetComponent <ActorProxyComponent>().Get(Player.ActorId);
                actorProxy.Send(new PlayerQuitDdz()
                {
                    PlayerId = Player.Id
                });
            }

            Game.Scene.GetComponent <PlayerComponent>()?.Remove(this.Player.Id);
        }
예제 #3
0
 public void Broadcast(AMessage message)
 {
     foreach (var gamer in gamers.Values)
     {
         if (gamer.isOffline)
         {
             continue;
         }
         ActorProxy actorProxy = gamer.GetComponent <UnitGateComponent>().GetActorProxy();
         actorProxy.Send(message);
     }
 }