public CityGameController(IHttpContextAccessor httpContextAccessor_, IPlayerService playerService) : base(httpContextAccessor_, playerService)
        {
            string gameCityId_;
            string roomId_;

            if (session.Keys.Contains("RoomId") && session.Keys.Contains("CityId"))
            {
                gameCityId_ = session.GetString("CityId");
                roomId_     = session.GetString("RoomId");
            }
            else
            {
                gameCityId_ = httpContextAccessor.HttpContext.Request.Query["gameCityId"];
                roomId_     = httpContextAccessor.HttpContext.Request.Query["roomId"];
            }


            if (gameCityId_ != null && gameCityId_.Length > 0)
            {
                _gameCity = CityGameController.GameCityList.FindGameCityById(gameCityId_);
            }
            if (roomId_ != null && roomId_.Length > 0)
            {
                _room = _gameCity.FindRoomById(roomId_);
                if (_room == null)
                {
                    throw new RoomIsNotExistException(player.Id, "房间已经不存在了");
                }
                _inngeGame   = _room.InningGame;
                _gameProject = _inngeGame.IGameProject;
            }
        }
Beispiel #2
0
        /// <summary>
        /// 检查玩家session保存的房间Id等,初始化房间信息
        /// </summary>
        private void LoadRoomInfo()
        {
            string gameCityId_;
            string roomId_;

            #region session中保存有房间信息就读取,没有就从Request.Query中读取
            if (session.Keys.Contains("RoomId") && session.Keys.Contains("CityId"))
            {
                gameCityId_ = session.GetString("CityId");
                roomId_     = session.GetString("RoomId");
            }
            else
            {
                gameCityId_ = httpContextAccessor.HttpContext.Request.Query["gameCityId"];
                roomId_     = httpContextAccessor.HttpContext.Request.Query["roomId"];
            }
            #endregion
            #region sesson或Request.Query中有房间信息就使用
            if (gameCityId_ != null && gameCityId_.Length > 0)
            {
                _gameCity = CityGameController.GameCityList.FindGameCityById(gameCityId_);
            }
            if (roomId_ != null && roomId_.Length > 0)
            {
                _room = _gameCity.FindRoomById(roomId_);
                if (_room == null)
                {
                    throw new RoomIsNotExistException(player.Id, "房间已经不存在了");
                }
                _inngeGame   = _room.InningGame;
                _gameProject = _inngeGame.IGameProject;
                #endregion
                #region 保存玩家websocket对象
                IPlayerJoinRoom roomPlayer = _room.Players.FirstOrDefault(p => p.Id == player.Id);
                if (null != roomPlayer)
                {
                    roomPlayer.WebSocketLink = ClientWebsocketsManager.FindClientWebSocketByPlayerId(player.Id);
                }
                #endregion
            }
        }