use of com.faforever.server.entity.MapVersion in project faf-java-server by FAForever.
the class MapServiceTest method setUp.
@Before
public void setUp() {
mapVersion = new MapVersion().setId(1).setFilename(MAP_NAME);
when(mapVersionRepository.findByFilenameIgnoreCase(MAP_NAME)).thenReturn(Optional.of(mapVersion));
when(mapVersionRepository.findOne(1)).thenReturn(mapVersion);
MapStats features = new MapStats().setId(1).setTimesPlayed(41);
when(mapStatsRepository.findOne(1)).thenReturn(features);
when(mapStatsRepository.save(any(MapStats.class))).thenAnswer(context -> context.getArguments()[0]);
instance = new MapService(mapVersionRepository, ladder1v1MapRepository, mapStatsRepository);
}
use of com.faforever.server.entity.MapVersion 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;
});
});
}
use of com.faforever.server.entity.MapVersion in project faf-java-server by FAForever.
the class MapServiceTest method getRandomLadderMap.
@Test
public void getRandomLadderMap() {
MapVersion oneMap = new MapVersion().setId(2).setRanked(true);
MapVersion otherMap = new MapVersion().setId(3).setRanked(true);
when(ladder1v1MapRepository.findAll()).thenReturn(Arrays.asList(oneMap, otherMap));
assertThat(instance.getRandomLadderMap(), isOneOf(oneMap, otherMap));
}
use of com.faforever.server.entity.MapVersion in project faf-java-server by FAForever.
the class MatchMakerServiceTest method createMatch.
@Test
public void createMatch() throws Exception {
MatchParticipant participant1 = new MatchParticipant().setId(1).setFaction(Faction.UEF).setTeam(1).setSlot(1).setStartSpot(1);
MatchParticipant participant2 = new MatchParticipant().setId(2).setFaction(Faction.AEON).setTeam(2).setSlot(2).setStartSpot(2);
ConnectionAware requester = mock(ConnectionAware.class);
UUID requestId = UUID.randomUUID();
List<MatchParticipant> participants = Arrays.asList(participant1, participant2);
int mapVersionId = 1;
Player player1 = (Player) new Player().setId(1);
Player player2 = (Player) new Player().setId(2);
when(playerService.getOnlinePlayer(participant1.getId())).thenReturn(Optional.of(player1));
when(playerService.getOnlinePlayer(participant2.getId())).thenReturn(Optional.of(player2));
when(mapService.findMap(mapVersionId)).thenReturn(Optional.of(new MapVersion().setFilename("maps/foo.zip")));
Game game = new Game();
when(gameService.createGame("Test match", "faf", "null", null, GameVisibility.PRIVATE, null, null, player1)).thenReturn(CompletableFuture.completedFuture(game));
when(gameService.joinGame(1, null, player2)).thenReturn(CompletableFuture.completedFuture(game));
instance.createMatch(requester, requestId, "Test match", "faf", participants, mapVersionId);
verify(clientService, timeout(5000)).sendMatchCreatedNotification(requestId, 1, requester);
verify(gameService, timeout(1000)).updatePlayerOption(player1, player1.getId(), GameService.OPTION_TEAM, participant1.getTeam());
verify(gameService, timeout(1000)).updatePlayerOption(player1, player1.getId(), GameService.OPTION_FACTION, participant1.getFaction().toFaValue());
verify(gameService, timeout(1000)).updatePlayerOption(player1, player1.getId(), GameService.OPTION_START_SPOT, participant1.getStartSpot());
verify(gameService, timeout(1000)).updatePlayerOption(player1, player1.getId(), GameService.OPTION_COLOR, 1);
verify(gameService, timeout(1000)).updatePlayerOption(player1, player1.getId(), GameService.OPTION_ARMY, 1);
verify(gameService, timeout(1000)).updatePlayerOption(player1, player2.getId(), GameService.OPTION_TEAM, participant2.getTeam());
verify(gameService, timeout(1000)).updatePlayerOption(player1, player2.getId(), GameService.OPTION_FACTION, participant2.getFaction().toFaValue());
verify(gameService, timeout(1000)).updatePlayerOption(player1, player2.getId(), GameService.OPTION_START_SPOT, participant2.getStartSpot());
verify(gameService, timeout(1000)).updatePlayerOption(player1, player2.getId(), GameService.OPTION_COLOR, 2);
verify(gameService, timeout(1000)).updatePlayerOption(player1, player2.getId(), GameService.OPTION_ARMY, 2);
}
use of com.faforever.server.entity.MapVersion in project faf-java-server by FAForever.
the class MatchMakerServiceTest method setUp.
@Before
public void setUp() throws Exception {
properties = new ServerProperties();
FeaturedMod ladder1v1Mod = new FeaturedMod().setTechnicalName("faf");
when(modService.getFeaturedMod(ladder1v1Mod.getTechnicalName())).thenReturn(Optional.of(ladder1v1Mod));
when(modService.getLadder1v1()).thenReturn(Optional.of(ladder1v1Mod));
when(modService.isLadder1v1(ladder1v1Mod)).thenReturn(true);
when(mapService.getRandomLadderMap()).thenReturn(new MapVersion().setFilename("maps/SCMP_001.zip"));
when(gameService.createGame(any(), any(), any(), any(), any(), anyInt(), anyInt(), any())).thenReturn(CompletableFuture.completedFuture(new Game().setId(1)));
RatingService ratingService = new RatingService(properties);
instance = new MatchMakerService(modService, properties, ratingService, clientService, gameService, mapService, playerService);
}
Aggregations