Search in sources :

Example 1 with FeaturedMod

use of com.faforever.server.entity.FeaturedMod in project faf-java-server by FAForever.

the class MatchMakerServiceTest method startSearchEmptyQueue.

@Test
public void startSearchEmptyQueue() throws Exception {
    FeaturedMod featuredMod = new FeaturedMod();
    when(modService.getFeaturedMod(1)).thenReturn(Optional.of(featuredMod));
    when(modService.isLadder1v1(featuredMod)).thenReturn(true);
    instance.submitSearch(new Player(), Faction.CYBRAN, QUEUE_NAME);
    instance.processPools();
    verifyZeroInteractions(gameService);
}
Also used : Player(com.faforever.server.entity.Player) FeaturedMod(com.faforever.server.entity.FeaturedMod) Test(org.junit.Test)

Example 2 with FeaturedMod

use of com.faforever.server.entity.FeaturedMod in project faf-java-server by FAForever.

the class ClientServiceTest method sendModList.

@Test
public void sendModList() throws Exception {
    instance.sendModList(Collections.singletonList(new FeaturedMod().setDisplayName("Mod").setTechnicalName("mod").setDisplayOrder(4).setDescription("Description")), player);
    ArgumentCaptor<FeaturedModResponse> captor = ArgumentCaptor.forClass(FeaturedModResponse.class);
    verify(clientGateway).send(captor.capture(), eq(clientConnection));
    FeaturedModResponse response = captor.getValue();
    assertThat(response.getDisplayName(), is("Mod"));
    assertThat(response.getTechnicalName(), is("mod"));
    assertThat(response.getDisplayOrder(), is(4));
    assertThat(response.getDescription(), is("Description"));
}
Also used : FeaturedMod(com.faforever.server.entity.FeaturedMod) FeaturedModResponse(com.faforever.server.mod.FeaturedModResponse) Test(org.junit.Test)

Example 3 with FeaturedMod

use of com.faforever.server.entity.FeaturedMod in project faf-java-server by FAForever.

the class ArmyStatisticsServiceTest method testProcessGameWonLadder1v1.

@Test
public void testProcessGameWonLadder1v1() throws Exception {
    FeaturedMod ladder1v1FeaturedMod = new FeaturedMod();
    when(modService.isLadder1v1(ladder1v1FeaturedMod)).thenReturn(true);
    game.setFeaturedMod(ladder1v1FeaturedMod);
    game.getReportedArmyResults().put(player.getId(), ImmutableMap.of(1, ArmyResult.of(1, Outcome.VICTORY, null)));
    game.setStartTime(Instant.now().minus(Duration.ofMinutes(90)));
    game.setEndTime(Instant.now());
    List<ArmyStatistics> stats = readStats("/stats/game_stats_simple_win.json");
    instance.process(player, game, stats);
    assertThat(this.achievementUpdates, hasItem(new AchievementUpdate(42, AchievementId.ACH_FIRST_SUCCESS, AchievementUpdate.UpdateType.UNLOCK, 0)));
}
Also used : AchievementUpdate(com.faforever.server.stats.achievements.AchievementUpdate) FeaturedMod(com.faforever.server.entity.FeaturedMod) Test(org.junit.Test)

Example 4 with FeaturedMod

use of com.faforever.server.entity.FeaturedMod in project faf-java-server by FAForever.

the class ArmyStatisticsServiceTest method testWin1v1After10Minutes.

/**
 * Tests {@link AchievementId#ACH_RUSHER} negatively.
 */
@Test
public void testWin1v1After10Minutes() throws Exception {
    FeaturedMod ladder1v1FeaturedMod = new FeaturedMod();
    when(modService.isLadder1v1(ladder1v1FeaturedMod)).thenReturn(true);
    game.setFeaturedMod(ladder1v1FeaturedMod);
    game.getReportedArmyResults().put(player.getId(), ImmutableMap.of(1, ArmyResult.of(1, Outcome.VICTORY, null)));
    game.setStartTime(Instant.now().minus(Duration.ofMinutes(11)));
    game.setEndTime(Instant.now());
    List<ArmyStatistics> stats = readStats("/stats/game_stats_simple_win.json");
    instance.process(player, game, stats);
    assertThat(this.achievementUpdates, not(hasItem(new AchievementUpdate(42, AchievementId.ACH_RUSHER, AchievementUpdate.UpdateType.UNLOCK, 0))));
}
Also used : AchievementUpdate(com.faforever.server.stats.achievements.AchievementUpdate) FeaturedMod(com.faforever.server.entity.FeaturedMod) Test(org.junit.Test)

Example 5 with FeaturedMod

use of com.faforever.server.entity.FeaturedMod in project faf-java-server by FAForever.

the class MatchMakerService method createMatch.

/**
 * <p>Creates a new match with the specified options and participants. All participants must be online and available
 * for matchmaking. A player can be unavailable for matchmaking if, for instance, he's currently playing a game or
 * offline. In this case, a {@link ErrorCode#PLAYER_NOT_AVAILABLE_FOR_MATCHMAKING} is thrown.</p>
 *
 * @throws RequestException if a player is not available for matchmaking or the map to be played is unknown by the
 * server.
 */
public void createMatch(ConnectionAware requester, UUID requestId, String title, String featuredMod, List<MatchParticipant> participants, int mapVersionId) {
    log.debug("Creating match '{}' with '{}' participants on map '{}'", title, participants.size(), mapVersionId);
    Requests.verify(participants.size() > 1, ErrorCode.INSUFFICIENT_MATCH_PARTICIPANTS, participants.size(), 2);
    List<Player> players = participants.stream().map(matchParticipant -> playerService.getOnlinePlayer(matchParticipant.getId()).orElseThrow(() -> new RequestException(requestId, ErrorCode.PLAYER_NOT_AVAILABLE_FOR_MATCHMAKING, matchParticipant.getId()))).peek(player -> Requests.verify(player.getCurrentGame() == null, requestId, ErrorCode.PLAYER_NOT_AVAILABLE_FOR_MATCHMAKING, player)).peek(this::removePlayer).collect(Collectors.toList());
    String mapFileName = mapService.findMap(mapVersionId).map(MapVersion::getFilename).orElseThrow(() -> new RequestException(requestId, ErrorCode.UNKNOWN_MAP, mapVersionId));
    Player host = players.get(0);
    List<Player> guests = players.subList(1, players.size());
    gameService.createGame(title, featuredMod, mapFileName, null, GameVisibility.PRIVATE, null, null, host).handle((game, throwable) -> {
        if (throwable != null) {
            log.debug("The host of match '{}' failed to start his game", title, throwable);
            throw new RequestException(requestId, ErrorCode.HOST_FAILED_TO_START_GAME, title, host);
        }
        AtomicInteger counter = new AtomicInteger();
        Integer hostId = host.getId();
        setPlayerOptionsForMatchParticipant(participants, host, counter, hostId);
        log.trace("Host '{}' for match '{}' is ready", host, title);
        clientService.sendMatchCreatedNotification(requestId, game.getId(), requester);
        List<CompletableFuture<Game>> guestGameFutures = guests.stream().peek(player -> log.trace("Telling player '{}' to start the game process for match '{}'", player, title)).map(player -> gameService.joinGame(game.getId(), null, player).thenApply(gameStartedFuture -> {
            setPlayerOptionsForMatchParticipant(participants, host, counter, player.getId());
            return gameStartedFuture;
        })).collect(Collectors.toList());
        return CompletableFuture.allOf(guestGameFutures.toArray(new CompletableFuture[guests.size()])).thenAccept(aVoid -> log.debug("All players launched their game for match '{}'", title)).exceptionally(throwable1 -> {
            log.debug("At least one player failed to launch their game for match '{}'", title, throwable1);
            return null;
        });
    });
}
Also used : ModService(com.faforever.server.mod.ModService) PlayerService(com.faforever.server.player.PlayerService) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) GameVisibility(com.faforever.server.game.GameVisibility) Scheduled(org.springframework.scheduling.annotation.Scheduled) FeaturedMod(com.faforever.server.entity.FeaturedMod) Value(lombok.Value) Player(com.faforever.server.entity.Player) HashSet(java.util.HashSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Service(org.springframework.stereotype.Service) Duration(java.time.Duration) Map(java.util.Map) ServerProperties(com.faforever.server.config.ServerProperties) ClientService(com.faforever.server.client.ClientService) ConnectionAware(com.faforever.server.client.ConnectionAware) RatingService(com.faforever.server.rating.RatingService) Set(java.util.Set) ErrorCode(com.faforever.server.error.ErrorCode) Faction(com.faforever.server.game.Faction) GameService(com.faforever.server.game.GameService) UUID(java.util.UUID) EqualsAndHashCode(lombok.EqualsAndHashCode) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) MapService(com.faforever.server.map.MapService) Ladder1v1Rating(com.faforever.server.entity.Ladder1v1Rating) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Requests(com.faforever.server.error.Requests) Game(com.faforever.server.entity.Game) MapVersion(com.faforever.server.entity.MapVersion) Optional(java.util.Optional) RequestException(com.faforever.server.error.RequestException) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AllArgsConstructor(lombok.AllArgsConstructor) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Player(com.faforever.server.entity.Player) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RequestException(com.faforever.server.error.RequestException)

Aggregations

FeaturedMod (com.faforever.server.entity.FeaturedMod)9 Test (org.junit.Test)6 ServerProperties (com.faforever.server.config.ServerProperties)3 Game (com.faforever.server.entity.Game)3 MapVersion (com.faforever.server.entity.MapVersion)3 Player (com.faforever.server.entity.Player)3 AchievementUpdate (com.faforever.server.stats.achievements.AchievementUpdate)3 RatingService (com.faforever.server.rating.RatingService)2 Before (org.junit.Before)2 ClientService (com.faforever.server.client.ClientService)1 ConnectionAware (com.faforever.server.client.ConnectionAware)1 GlobalRating (com.faforever.server.entity.GlobalRating)1 Ladder1v1Rating (com.faforever.server.entity.Ladder1v1Rating)1 ErrorCode (com.faforever.server.error.ErrorCode)1 RequestException (com.faforever.server.error.RequestException)1 Requests (com.faforever.server.error.Requests)1 Faction (com.faforever.server.game.Faction)1 GameService (com.faforever.server.game.GameService)1 GameVisibility (com.faforever.server.game.GameVisibility)1 StartGameProcessResponse (com.faforever.server.game.StartGameProcessResponse)1