コード例 #1
0
        public async Task <IActionResult> JoinGame([FromBody] PlayerGameDto playerGame)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var user = await playerRepository.GetPlayerById(playerGame.PlayerId);

            var game = lobbyHelper.GetGameDto(playerGame.GameId);

            if (user == null || game == null)
            {
                return(BadRequest());
            }

            var response = lobbyHelper.AddPlayerToGame(game.Id, user);

            if (response.Item1)
            {
                await logUserActivity.GameLogin(user, game);

                return(Ok(game));
            }
            return(BadRequest());
        }
コード例 #2
0
        public static PlayerGameDto ToPlayerGameDto(this Player player, Game game)
        {
            var tempDto = new PlayerGameDto();

            tempDto.PlayerId = player.Id;
            tempDto.GameId   = game.GameKey;

            return(tempDto);
        }
コード例 #3
0
        public async Task <IActionResult> LeaveGame([FromBody] PlayerGameDto playerGame)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var user = await playerRepository.GetPlayerById(playerGame.PlayerId);

            var game = lobbyHelper.GetGameDto(playerGame.GameId);

            var response = lobbyHelper.RemovePlayerFromGame(game.Id, user);

            if (response.Item1)
            {
                var result = await logUserActivity.GameLogout(user, game);

                if (result)
                {
                    return(Ok());
                }
            }
            return(BadRequest());
        }