public async Task <ActionResult <string> > GetMatchData([FromForm] string playerId, [FromForm] int warshipId)
        {
            if (string.IsNullOrEmpty(playerId))
            {
                return(BadRequest());
            }

            MatchmakerResponse matcherResponse = await matchmakerFacadeService.GetMatchDataAsync(playerId, warshipId);

            return(matcherResponse.SerializeToBase64String());
        }
Exemple #2
0
        public async Task GetMatchData_PlayerIdIsNormal_OkResult()
        {
            //Arrange
            var stubResponse         = new MatchmakerResponse();
            var matchmakerFacadeStub = new Mock <IMatchmakerFacadeService>();

            matchmakerFacadeStub.Setup(s => s.GetMatchDataAsync(It.IsNotNull <string>(), It.IsAny <int>())).ReturnsAsync(stubResponse);

            var controller = new PlayerController(new Mock <IBattleRoyaleQueueSingletonService>().Object,
                                                  matchmakerFacadeStub.Object);

            //Act
            var result = await controller.GetMatchData("NotNullPlayerId", 0);

            //Assert
            Assert.AreEqual(stubResponse.SerializeToBase64String(), result.Value);
        }
Exemple #3
0
        public async Task <MatchmakerResponse> GetMatchDataAsync(string playerServiceId, int warshipId)
        {
            //Данные для окна ожидания боя
            MatchmakerResponse response = new MatchmakerResponse
            {
                NumberOfPlayersInQueue   = queueSingletonService.GetNumberOfPlayers(),
                NumberOfPlayersInBattles = unfinishedMatchesService.GetNumberOfPlayersInBattles()
            };

            //Игрок в очереди?
            if (queueSingletonService.Contains(playerServiceId))
            {
                Console.WriteLine("PlayerInQueue");
                response.PlayerInQueue = true;
                return(response);
            }
            //Игрок в бою?
            else if (unfinishedMatchesService.IsPlayerInMatch(playerServiceId))
            {
                Console.WriteLine("IsPlayerInMatch");
                BattleRoyaleMatchModel matchModel = unfinishedMatchesService.GetMatchModel(playerServiceId);
                response.PlayerInBattle = true;
                response.MatchModel     = new BattleRoyaleClientMatchModel(matchModel, playerServiceId);
                return(response);
            }
            //Добавить в очередь
            else
            {
                Console.WriteLine("TryEnqueuePlayerAsync");
                bool success = await queueExtenderService.TryEnqueuePlayerAsync(playerServiceId, warshipId);

                if (!success)
                {
                    throw new Exception("Не удалось добавить игрока в очередь.");
                }
                response.PlayerHasJustBeenRegistered = true;
                return(response);
            }
        }