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);
}
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"));
}
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)));
}
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))));
}
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;
});
});
}
Aggregations