Ejemplo n.º 1
0
        protected override async ETTask Run(Session session, C2G_EnterRoomRequest request, G2C_EnterRoomResponse response, Action reply)
        {
            // 获取房间Id
            long locationInstanceId             = StartSceneConfigCategory.Instance.LocationConfig.SceneId;
            L2A_RoomGetResponse roomGetResponse =
                (L2A_RoomGetResponse)await ActorMessageHelper.CallActor(locationInstanceId,
                                                                        new A2L_RoomGetRequest { RoomNum = request.RoomNum });

            if (roomGetResponse.Error != ErrorCode.ERR_Success)
            {
                response.Error   = roomGetResponse.Error;
                response.Message = roomGetResponse.Message;
                reply();
                return;
            }

            // 向房间请求加入
            long uid = session.GetComponent <UserInfo>().UId;
            M2G_EnterRoomResponse joinRoomResponse =
                (M2G_EnterRoomResponse)await ActorMessageHelper.CallLocationActor(roomGetResponse.RoomId,
                                                                                  new G2M_EnterRoomRequest { UId = uid, GateSessionId = session.InstanceId });

            response.SeatIndex  = joinRoomResponse.SeatIndex;
            response.Error      = joinRoomResponse.Error;
            response.Message    = joinRoomResponse.Message;
            response.RoomMaster = joinRoomResponse.RoomMaster;
            if (response.Error == ErrorCode.ERR_Success)
            {
                GateSessionActorId gateSessionActorId = session.GetComponent <GateSessionActorId>() ?? session.AddComponent <GateSessionActorId>();
                gateSessionActorId.ActorId = joinRoomResponse.PlayerActorId;
            }

            reply();
        }
Ejemplo n.º 2
0
        protected override async ETTask Run(Session session, C2G_ExitRoomRequest request, G2C_ExitRoomResponse response, Action reply)
        {
            var id = session.GetComponent <GateSessionActorId>();

            if (id == null)
            {
                reply();
                return;
            }

            var actorId = id.ActorId;
            var resp    = (M2G_ExitRoomResponse)await ActorMessageHelper.CallLocationActor(actorId,
                                                                                           new G2M_ExitRoomRequest { IsDestroyRoom = request.IsDestroyRoom });

            response.Error   = resp.Error;
            response.Message = resp.Message;

            // 已经离开房间
            session.GetComponent <GateSessionActorId>().ActorId = 0;

            reply();
        }