Exemplo n.º 1
0
        public async Task StartGame(long lobbyId, string gameName)
        {
            var loggedPlayer = GetLoggedPlayer();
            var lobby        = _lobbyService.FindByIdAndGameName(lobbyId, gameName);

            if (lobby.Owner != loggedPlayer)
            {
                throw new UnauthorizedAccessException("You have to be an owner of lobby to start game");
            }
            var players     = lobby.ConnectedPlayers;
            var gameSession = lobby.StartGameSession();

            _gameSessionService.AddSession(gameName, gameSession);
            var groupName = GenerateGroupName(lobbyId, gameName);
            await Clients.Group(groupName).InvokeAsync("startGame", gameSession.GetJoinUrl());
        }