Example #1
0
        /// <summary>
        /// Создать игру
        /// </summary>
        /// <param name="createGameRequest">Описание создаваемой игры</param>
        public async Task CreateGame(CreateGameRequestViewModel createGameRequest)
        {
            var game = gameService.FindById(createGameRequest.ScenarioId);

            if (game == null)
            {
                await Clients.Caller.SendAsync(nameof(CreateGame), RequestResult.Err("Invalid scenario id"));

                return;
            }

            var userName    = (string)Context.Items[CLIENT_USERNAME_FIELD];
            var gameSession = gameSessionService.Create(game, userName, createGameRequest.Name);

            await Clients.Caller.SendAsync(nameof(CreateGame), RequestResult.Ok(gameSession.Id));

            await Clients.All.SendAsync("GameCreated", RequestResult.Ok(gameSession));
        }