From c99d5280420cdf81763877cb74dcda8da69bd547 Mon Sep 17 00:00:00 2001 From: Brutus5000 Date: Sat, 3 Nov 2018 14:27:32 +0100 Subject: [PATCH] Allow setting team presets for external matchmaking (fixes #97) --- .../server/client/ClientService.java | 6 +++- .../java/com/faforever/server/game/Game.java | 5 +++ .../GameParticipant.java} | 7 +++-- .../faforever/server/game/GameService.java | 4 ++- .../server/game/StartGameProcessResponse.java | 2 ++ .../integration/GameServiceActivators.java | 3 +- .../server/matchmaker/CreateMatchRequest.java | 1 - .../server/matchmaker/MatchMakerMapper.java | 5 +-- .../server/matchmaker/MatchMakerService.java | 31 ++++++++++--------- .../server/game/GameServiceTest.java | 10 +++--- .../GameServiceActivatorsTest.java | 3 +- .../LaunchGameResponseTransformerTest.java | 4 +++ .../V2ServerMessageTransformerTest.java | 7 +++-- .../matchmaker/MatchMakerServiceTest.java | 20 +++++++----- 14 files changed, 69 insertions(+), 39 deletions(-) rename faf-java-server-app/src/main/java/com/faforever/server/{matchmaker/MatchParticipant.java => game/GameParticipant.java} (72%) diff --git a/faf-java-server-app/src/main/java/com/faforever/server/client/ClientService.java b/faf-java-server-app/src/main/java/com/faforever/server/client/ClientService.java index 09018d7..d824739 100644 --- a/faf-java-server-app/src/main/java/com/faforever/server/client/ClientService.java +++ b/faf-java-server-app/src/main/java/com/faforever/server/client/ClientService.java @@ -92,7 +92,11 @@ public ClientService(ClientGateway clientGateway, CoopService coopService, Serve public void startGameProcess(Game game, Player player) { log.debug("Telling '{}' to start game process for game '{}'", game.getHost(), game); - send(new StartGameProcessResponse(game.getFeaturedMod().getTechnicalName(), game.getId(), game.getMapFolderName(), game.getLobbyMode(), getCommandLineArgs(player)), player); + + Optional team = game.getPresetParticipants() + .map(gameParticipants -> gameParticipants.get(player.getId()).getTeam()); + + send(new StartGameProcessResponse(game.getFeaturedMod().getTechnicalName(), game.getId(), game.getMapFolderName(), game.getLobbyMode(), team, getCommandLineArgs(player)), player); } /** diff --git a/faf-java-server-app/src/main/java/com/faforever/server/game/Game.java b/faf-java-server-app/src/main/java/com/faforever/server/game/Game.java index 9668aab..4d75ffa 100644 --- a/faf-java-server-app/src/main/java/com/faforever/server/game/Game.java +++ b/faf-java-server-app/src/main/java/com/faforever/server/game/Game.java @@ -33,6 +33,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicInteger; @@ -46,6 +47,9 @@ @KeySpace("game") public class Game { + @Transient + private Optional> presetParticipants; + /** * A key-value map of gamespecific options, like {@code "PrebuiltUnits" -> "Off"}. */ @@ -197,6 +201,7 @@ public Game(int id) { public Game() { state = GameState.INITIALIZING; + presetParticipants = Optional.empty(); playerOptions = new HashMap<>(); options = new HashMap<>(); aiOptions = new HashMap<>(); diff --git a/faf-java-server-app/src/main/java/com/faforever/server/matchmaker/MatchParticipant.java b/faf-java-server-app/src/main/java/com/faforever/server/game/GameParticipant.java similarity index 72% rename from faf-java-server-app/src/main/java/com/faforever/server/matchmaker/MatchParticipant.java rename to faf-java-server-app/src/main/java/com/faforever/server/game/GameParticipant.java index d53a4ee..4e5ec38 100644 --- a/faf-java-server-app/src/main/java/com/faforever/server/matchmaker/MatchParticipant.java +++ b/faf-java-server-app/src/main/java/com/faforever/server/game/GameParticipant.java @@ -1,7 +1,7 @@ -package com.faforever.server.matchmaker; +package com.faforever.server.game; -import com.faforever.server.game.Faction; import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -12,7 +12,8 @@ @Getter @Setter @ToString(of = {"id", "name"}) -class MatchParticipant { +@EqualsAndHashCode(of = "id") +public class GameParticipant { private int id; private Faction faction; private int team; diff --git a/faf-java-server-app/src/main/java/com/faforever/server/game/GameService.java b/faf-java-server-app/src/main/java/com/faforever/server/game/GameService.java index 34aba49..f1b0a8d 100644 --- a/faf-java-server-app/src/main/java/com/faforever/server/game/GameService.java +++ b/faf-java-server-app/src/main/java/com/faforever/server/game/GameService.java @@ -226,7 +226,8 @@ public void onApplicationEvent(ContextRefreshedEvent event) { @Transactional(readOnly = true) public CompletableFuture createGame(String title, String featuredModName, String mapFileName, String password, GameVisibility visibility, - Integer minRating, Integer maxRating, Player player, LobbyMode lobbyMode) { + Integer minRating, Integer maxRating, Player player, LobbyMode lobbyMode, + Optional> presetParticipants) { Game currentGame = player.getCurrentGame(); if (currentGame != null && currentGame.getState() == GameState.INITIALIZING) { @@ -241,6 +242,7 @@ public CompletableFuture createGame(String title, String featuredModName, int gameId = this.lastGameId.incrementAndGet(); Game game = new Game(gameId); + game.setPresetParticipants(presetParticipants); game.setHost(player); modService.getFeaturedMod(featuredModName) .map(game::setFeaturedMod) diff --git a/faf-java-server-app/src/main/java/com/faforever/server/game/StartGameProcessResponse.java b/faf-java-server-app/src/main/java/com/faforever/server/game/StartGameProcessResponse.java index 6d44334..1878727 100644 --- a/faf-java-server-app/src/main/java/com/faforever/server/game/StartGameProcessResponse.java +++ b/faf-java-server-app/src/main/java/com/faforever/server/game/StartGameProcessResponse.java @@ -5,6 +5,7 @@ import lombok.Getter; import java.util.List; +import java.util.Optional; /** * Tells the Client to start a game process. @@ -20,6 +21,7 @@ public class StartGameProcessResponse implements ServerMessage { /** Only set if the server decides which map will be played, e.g. in leaderboard games. */ private final String mapFolderName; private final LobbyMode lobbyMode; + private final Optional team; /** * @deprecated the server should never send command line arguments. They should always be generated on client side. diff --git a/faf-java-server-app/src/main/java/com/faforever/server/integration/GameServiceActivators.java b/faf-java-server-app/src/main/java/com/faforever/server/integration/GameServiceActivators.java index 66e16aa..6e45135 100644 --- a/faf-java-server-app/src/main/java/com/faforever/server/integration/GameServiceActivators.java +++ b/faf-java-server-app/src/main/java/com/faforever/server/integration/GameServiceActivators.java @@ -45,7 +45,8 @@ public GameServiceActivators(GameService gameService) { @ServiceActivator(inputChannel = ChannelNames.HOST_GAME_REQUEST) public void hostGameRequest(HostGameRequest request, @Header(USER_HEADER) Authentication authentication) { gameService.createGame(request.getTitle(), request.getMod(), request.getMapName(), request.getPassword(), - request.getVisibility(), request.getMinRating(), request.getMaxRating(), getPlayer(authentication), LobbyMode.DEFAULT); + request.getVisibility(), request.getMinRating(), request.getMaxRating(), getPlayer(authentication), + LobbyMode.DEFAULT, Optional.empty()); } @ServiceActivator(inputChannel = ChannelNames.JOIN_GAME_REQUEST) diff --git a/faf-java-server-app/src/main/java/com/faforever/server/matchmaker/CreateMatchRequest.java b/faf-java-server-app/src/main/java/com/faforever/server/matchmaker/CreateMatchRequest.java index d011574..7fb0072 100644 --- a/faf-java-server-app/src/main/java/com/faforever/server/matchmaker/CreateMatchRequest.java +++ b/faf-java-server-app/src/main/java/com/faforever/server/matchmaker/CreateMatchRequest.java @@ -32,7 +32,6 @@ public enum LobbyMode { public static class Participant { private int id; private Faction faction; - private int slot; private int team; private String name; private int startSpot; diff --git a/faf-java-server-app/src/main/java/com/faforever/server/matchmaker/MatchMakerMapper.java b/faf-java-server-app/src/main/java/com/faforever/server/matchmaker/MatchMakerMapper.java index 7bfca68..b40d417 100644 --- a/faf-java-server-app/src/main/java/com/faforever/server/matchmaker/MatchMakerMapper.java +++ b/faf-java-server-app/src/main/java/com/faforever/server/matchmaker/MatchMakerMapper.java @@ -1,5 +1,6 @@ package com.faforever.server.matchmaker; +import com.faforever.server.game.GameParticipant; import com.faforever.server.matchmaker.CreateMatchRequest.Participant; import org.mapstruct.Mapper; @@ -7,7 +8,7 @@ @Mapper(componentModel = "spring") public interface MatchMakerMapper { - List map(List participants); + List map(List participants); - MatchParticipant map(Participant participants); + GameParticipant map(Participant participants); } diff --git a/faf-java-server-app/src/main/java/com/faforever/server/matchmaker/MatchMakerService.java b/faf-java-server-app/src/main/java/com/faforever/server/matchmaker/MatchMakerService.java index b8ba6e7..02dea84 100644 --- a/faf-java-server-app/src/main/java/com/faforever/server/matchmaker/MatchMakerService.java +++ b/faf-java-server-app/src/main/java/com/faforever/server/matchmaker/MatchMakerService.java @@ -8,6 +8,7 @@ import com.faforever.server.error.Requests; import com.faforever.server.game.Faction; import com.faforever.server.game.Game; +import com.faforever.server.game.GameParticipant; import com.faforever.server.game.GameService; import com.faforever.server.game.GameVisibility; import com.faforever.server.game.LobbyMode; @@ -163,15 +164,15 @@ public void removePlayer(Player player) { * @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 participants, int mapVersionId) { + public void createMatch(ConnectionAware requester, UUID requestId, String title, String featuredMod, List participants, int mapVersionId) { MapVersion mapVersion = mapService.findMap(mapVersionId) .orElseThrow(() -> new RequestException(requestId, ErrorCode.UNKNOWN_MAP, mapVersionId)); createMatchInternal(title, participants, mapVersion, featuredMod, requestId, requester); } - private void setPlayerOptionsForMatchParticipant(List participants, Player host, AtomicInteger counter, Integer playerId) { - MatchParticipant participant = getMatchParticipant(participants, playerId); + private void setPlayerOptionsForMatchParticipant(List participants, Player host, AtomicInteger counter, Integer playerId) { + GameParticipant participant = getMatchParticipant(participants, playerId); gameService.updatePlayerOption(host, playerId, GameService.OPTION_TEAM, participant.getTeam()); gameService.updatePlayerOption(host, playerId, GameService.OPTION_FACTION, participant.getFaction().toFaValue()); gameService.updatePlayerOption(host, playerId, GameService.OPTION_START_SPOT, participant.getStartSpot()); @@ -181,9 +182,9 @@ private void setPlayerOptionsForMatchParticipant(List particip } @NotNull - private MatchParticipant getMatchParticipant(List participants, int playerId) { + private GameParticipant getMatchParticipant(List participants, int playerId) { return participants.stream() - .filter(matchParticipant -> matchParticipant.getId() == playerId) + .filter(gameParticipant -> gameParticipant.getId() == playerId) .findFirst() .orElseThrow(() -> new IllegalStateException("No match participant for player: " + playerId)); } @@ -215,8 +216,8 @@ private void processPool(String poolName, Map pool) { String title = createMatchTitle(poolName, players); AtomicInteger startSpot = new AtomicInteger(); - List participants = match.searches.stream() - .map(search -> new MatchParticipant(search.player.getId(), search.faction, GameService.NO_TEAM_ID, search.player.getLogin(), startSpot.get())) + List participants = match.searches.stream() + .map(search -> new GameParticipant(search.player.getId(), search.faction, GameService.NO_TEAM_ID, search.player.getLogin(), startSpot.get())) .collect(Collectors.toList()); MapVersion map = randomMap(players); @@ -281,13 +282,13 @@ private void notifyPlayers(MatchMakerSearch search) { .forEach(match -> clientService.sendMatchmakerNotification(match.poolName, match.rightPlayer)); } - private void createMatchInternal(String title, List participants, MapVersion map, String featuredMod, + private void createMatchInternal(String title, List presetParticipants, MapVersion map, String featuredMod, @Nullable UUID requestId, @Nullable ConnectionAware requester) { - log.debug("Creating match '{}' with '{}' participants on map '{}'", title, participants.size(), map); + log.debug("Creating match '{}' with '{}' presetParticipants on map '{}'", title, presetParticipants.size(), map); - List players = participants.stream() - .map(matchParticipant -> playerService.getOnlinePlayer(matchParticipant.getId()) - .orElseThrow(() -> new RequestException(requestId, ErrorCode.PLAYER_NOT_AVAILABLE_FOR_MATCHMAKING_OFFLINE, matchParticipant.getId()))) + List players = presetParticipants.stream() + .map(gameParticipant -> playerService.getOnlinePlayer(gameParticipant.getId()) + .orElseThrow(() -> new RequestException(requestId, ErrorCode.PLAYER_NOT_AVAILABLE_FOR_MATCHMAKING_OFFLINE, gameParticipant.getId()))) .peek(player -> Requests.verify(player.getCurrentGame() == null, requestId, ErrorCode.PLAYER_NOT_AVAILABLE_FOR_MATCHMAKING_OFFLINE, player)) .peek(this::removePlayer) .collect(Collectors.toList()); @@ -298,7 +299,7 @@ private void createMatchInternal(String title, List participan Player host = players.get(0); List guests = players.subList(1, players.size()); - gameService.createGame(title, featuredMod, mapFileName, null, GameVisibility.PRIVATE, null, null, host, LobbyMode.NONE) + gameService.createGame(title, featuredMod, mapFileName, null, GameVisibility.PRIVATE, null, null, host, LobbyMode.NONE, Optional.of(presetParticipants)) .handle((game, throwable) -> { if (throwable != null) { log.debug("The host of match '{}' failed to start his game", title, throwable); @@ -308,7 +309,7 @@ private void createMatchInternal(String title, List participan AtomicInteger counter = new AtomicInteger(); Integer hostId = host.getId(); - setPlayerOptionsForMatchParticipant(participants, host, counter, hostId); + setPlayerOptionsForMatchParticipant(presetParticipants, host, counter, hostId); log.trace("Host '{}' for match '{}' is ready", host, title); if (requester != null) { @@ -319,7 +320,7 @@ private void createMatchInternal(String title, List participan .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()); + setPlayerOptionsForMatchParticipant(presetParticipants, host, counter, player.getId()); return gameStartedFuture; }) ) diff --git a/faf-java-server-app/src/test/java/com/faforever/server/game/GameServiceTest.java b/faf-java-server-app/src/test/java/com/faforever/server/game/GameServiceTest.java index 5f61572..0871f56 100644 --- a/faf-java-server-app/src/test/java/com/faforever/server/game/GameServiceTest.java +++ b/faf-java-server-app/src/test/java/com/faforever/server/game/GameServiceTest.java @@ -247,7 +247,7 @@ public void joinGameWrongPassword() throws Exception { @Test public void updateGameStateIdle() { instance.createGame("Game title", FAF_TECHNICAL_NAME, MAP_NAME, "secret", - GameVisibility.PUBLIC, GAME_MIN_RATING, GAME_MAX_RATING, player1, LobbyMode.DEFAULT); + GameVisibility.PUBLIC, GAME_MIN_RATING, GAME_MAX_RATING, player1, LobbyMode.DEFAULT, Optional.empty()); instance.updatePlayerGameState(PlayerGameState.IDLE, player1); Game game = instance.getActiveGame(1).get(); @@ -1159,7 +1159,8 @@ public void updateGameValiditySinglePlayer() throws Exception { @SuppressWarnings("unchecked") public void onAuthenticationSuccess() { player1.setCurrentGame(null); - instance.createGame("Test game", FAF_TECHNICAL_NAME, MAP_NAME, null, GameVisibility.PUBLIC, GAME_MIN_RATING, GAME_MAX_RATING, player1, LobbyMode.DEFAULT); + instance.createGame("Test game", FAF_TECHNICAL_NAME, MAP_NAME, null, GameVisibility.PUBLIC, + GAME_MIN_RATING, GAME_MAX_RATING, player1, LobbyMode.DEFAULT, Optional.empty()); TestingAuthenticationToken authentication = new TestingAuthenticationToken("JUnit", "foo"); authentication.setDetails(new TestingAuthenticationToken(new FafUserDetails((User) new User().setPlayer(player2).setPassword("pw").setLogin("JUnit")), null)); @@ -1267,7 +1268,8 @@ public void disconnectFromGameIgnoredWhenPlayerNotInGame() { @Test public void mutualDrawRequestedByPlayerInNonPlayingGameState() { player1.setCurrentGame(null); - instance.createGame("Game title", FAF_TECHNICAL_NAME, MAP_NAME, "secret", GameVisibility.PUBLIC, GAME_MIN_RATING, GAME_MAX_RATING, player1, LobbyMode.DEFAULT); + instance.createGame("Game title", FAF_TECHNICAL_NAME, MAP_NAME, "secret", GameVisibility.PUBLIC, + GAME_MIN_RATING, GAME_MAX_RATING, player1, LobbyMode.DEFAULT, Optional.empty()); instance.updatePlayerGameState(PlayerGameState.LOBBY, player1); expectedException.expect(requestExceptionWithCode(ErrorCode.INVALID_GAME_STATE)); @@ -1513,7 +1515,7 @@ private Game hostGame(Player host, int gameId) throws Exception { host.setCurrentGame(null); CompletableFuture joinable = instance.createGame("Game title", FAF_TECHNICAL_NAME, MAP_NAME, "secret", - GameVisibility.PUBLIC, GAME_MIN_RATING, GAME_MAX_RATING, host, LobbyMode.DEFAULT); + GameVisibility.PUBLIC, GAME_MIN_RATING, GAME_MAX_RATING, host, LobbyMode.DEFAULT, Optional.empty()); assertThat(joinable.isDone(), is(false)); assertThat(joinable.isCancelled(), is(false)); diff --git a/faf-java-server-app/src/test/java/com/faforever/server/integration/GameServiceActivatorsTest.java b/faf-java-server-app/src/test/java/com/faforever/server/integration/GameServiceActivatorsTest.java index 1d90a42..16aba4d 100644 --- a/faf-java-server-app/src/test/java/com/faforever/server/integration/GameServiceActivatorsTest.java +++ b/faf-java-server-app/src/test/java/com/faforever/server/integration/GameServiceActivatorsTest.java @@ -37,6 +37,7 @@ import java.net.InetAddress; import java.util.Arrays; import java.util.Collections; +import java.util.Optional; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -76,7 +77,7 @@ public void restoreGameSession() { @Test public void hostGameRequest() { instance.hostGameRequest(new HostGameRequest("scmp01", "Title", "mod", "pw", GameVisibility.PUBLIC, 600, 900), clientConnection.getAuthentication()); - verify(gameService).createGame("Title", "mod", "scmp01", "pw", GameVisibility.PUBLIC, 600, 900, player, LobbyMode.DEFAULT); + verify(gameService).createGame("Title", "mod", "scmp01", "pw", GameVisibility.PUBLIC, 600, 900, player, LobbyMode.DEFAULT, Optional.empty()); } @Test diff --git a/faf-java-server-app/src/test/java/com/faforever/server/integration/legacy/transformer/LaunchGameResponseTransformerTest.java b/faf-java-server-app/src/test/java/com/faforever/server/integration/legacy/transformer/LaunchGameResponseTransformerTest.java index a161499..52f238f 100644 --- a/faf-java-server-app/src/test/java/com/faforever/server/integration/legacy/transformer/LaunchGameResponseTransformerTest.java +++ b/faf-java-server-app/src/test/java/com/faforever/server/integration/legacy/transformer/LaunchGameResponseTransformerTest.java @@ -7,6 +7,7 @@ import java.io.Serializable; import java.util.Arrays; import java.util.Map; +import java.util.Optional; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; @@ -21,6 +22,7 @@ public void transformWithoutMap() throws Exception { 4, null, LobbyMode.DEFAULT, + Optional.empty(), Arrays.asList("/numgames", "4") )); @@ -39,6 +41,7 @@ public void transformWithMap() throws Exception { 4, "scmp01", LobbyMode.DEFAULT, + Optional.empty(), Arrays.asList("/numgames", "4") )); @@ -57,6 +60,7 @@ public void transformOnlyAllowsTwoArgs() throws Exception { 4, null, LobbyMode.DEFAULT, + Optional.empty(), Arrays.asList("/numgames", "4", "/mean", "1500", "/deviation", "500") )); } diff --git a/faf-java-server-app/src/test/java/com/faforever/server/integration/v2/server/V2ServerMessageTransformerTest.java b/faf-java-server-app/src/test/java/com/faforever/server/integration/v2/server/V2ServerMessageTransformerTest.java index 2ab9e3d..91d1ee7 100644 --- a/faf-java-server-app/src/test/java/com/faforever/server/integration/v2/server/V2ServerMessageTransformerTest.java +++ b/faf-java-server-app/src/test/java/com/faforever/server/integration/v2/server/V2ServerMessageTransformerTest.java @@ -43,6 +43,7 @@ import java.time.Instant; import java.util.Arrays; import java.util.Collections; +import java.util.Optional; import java.util.TimeZone; import java.util.UUID; @@ -173,13 +174,15 @@ public void socialRelationList() { @Test public void startGameProcessWithoutMap() { - String response = instance.transform(new StartGameProcessResponse("faf", 1, null, LobbyMode.DEFAULT, Arrays.asList("/foo", "/bar"))); + String response = instance.transform(new StartGameProcessResponse("faf", 1, null, + LobbyMode.DEFAULT, Optional.empty(), Arrays.asList("/foo", "/bar"))); assertThat(response, is("{\"data\":{\"mod\":\"faf\",\"gameId\":1,\"lobbyMode\":\"DEFAULT\",\"commandLineArguments\":[\"/foo\",\"/bar\"]},\"type\":\"startGameProcess\"}")); } @Test public void startGameProcessWithMap() { - String response = instance.transform(new StartGameProcessResponse("faf", 1, "scmp01", LobbyMode.DEFAULT, Arrays.asList("/foo", "/bar"))); + String response = instance.transform(new StartGameProcessResponse("faf", 1, "scmp01", + LobbyMode.DEFAULT, Optional.empty(), Arrays.asList("/foo", "/bar"))); assertThat(response, is("{\"data\":{\"mod\":\"faf\",\"gameId\":1,\"map\":\"scmp01\",\"lobbyMode\":\"DEFAULT\",\"commandLineArguments\":[\"/foo\",\"/bar\"]},\"type\":\"startGameProcess\"}")); } diff --git a/faf-java-server-app/src/test/java/com/faforever/server/matchmaker/MatchMakerServiceTest.java b/faf-java-server-app/src/test/java/com/faforever/server/matchmaker/MatchMakerServiceTest.java index 3eeb817..23a401c 100644 --- a/faf-java-server-app/src/test/java/com/faforever/server/matchmaker/MatchMakerServiceTest.java +++ b/faf-java-server-app/src/test/java/com/faforever/server/matchmaker/MatchMakerServiceTest.java @@ -6,6 +6,7 @@ import com.faforever.server.error.ErrorCode; import com.faforever.server.game.Faction; import com.faforever.server.game.Game; +import com.faforever.server.game.GameParticipant; import com.faforever.server.game.GameService; import com.faforever.server.game.GameVisibility; import com.faforever.server.game.LobbyMode; @@ -127,7 +128,7 @@ public void submitSearchTwoFreshPlayersDontMatchImmediately() { instance.submitSearch(player2, Faction.AEON, QUEUE_NAME); instance.processPools(); - verify(gameService, never()).createGame(any(), any(), any(), any(), any(), anyInt(), anyInt(), any(), any()); + verify(gameService, never()).createGame(any(), any(), any(), any(), any(), anyInt(), anyInt(), any(), any(), any()); verify(gameService, never()).joinGame(anyInt(), eq(null), any()); } @@ -140,7 +141,10 @@ public void submitSearchTwoFreshPlayersMatch() { Player player2 = (Player) new Player().setLogin(LOGIN_PLAYER_2).setId(2); Game game = new Game(1); - when(gameService.createGame(any(), any(), any(), any(), any(), any(), any(), any(), any())) + GameParticipant gameParticipant1 = new GameParticipant(1, Faction.CYBRAN, 1, LOGIN_PLAYER_1, 0); + GameParticipant gameParticipant2 = new GameParticipant(2, Faction.AEON, 1, LOGIN_PLAYER_2, 0); + + when(gameService.createGame(any(), any(), any(), any(), any(), any(), any(), any(), any(), any())) .thenReturn(CompletableFuture.completedFuture(game)); when(gameService.joinGame(1, null, player2)) .thenReturn(CompletableFuture.completedFuture(game)); @@ -153,7 +157,7 @@ public void submitSearchTwoFreshPlayersMatch() { instance.processPools(); verify(gameService).createGame(LOGIN_PLAYER_1 + " vs. " + LOGIN_PLAYER_2, "ladder1v1", "SCMP_001", - null, GameVisibility.PRIVATE, null, null, player1, LobbyMode.NONE); + null, GameVisibility.PRIVATE, null, null, player1, LobbyMode.NONE, Optional.of(List.of(gameParticipant1, gameParticipant2))); verify(gameService).joinGame(1, null, player2); verify(gameService, times(10)).updatePlayerOption(any(), anyInt(), any(), any()); @@ -177,7 +181,7 @@ public void submitSearchTwoPlayersDontMatchIfRatingsTooFarApart() { instance.submitSearch(player2, Faction.AEON, QUEUE_NAME); instance.processPools(); - verify(gameService, never()).createGame(any(), any(), any(), any(), any(), anyInt(), anyInt(), any(), any()); + verify(gameService, never()).createGame(any(), any(), any(), any(), any(), anyInt(), anyInt(), any(), any(), any()); verify(gameService, never()).joinGame(anyInt(), eq(null), any()); } @@ -218,12 +222,12 @@ public void onClientDisconnect() { @Test public void createMatch() { - MatchParticipant participant1 = new MatchParticipant().setId(1).setFaction(Faction.UEF).setTeam(1).setStartSpot(1); - MatchParticipant participant2 = new MatchParticipant().setId(2).setFaction(Faction.AEON).setTeam(2).setStartSpot(2); + GameParticipant participant1 = new GameParticipant().setId(1).setFaction(Faction.UEF).setTeam(1).setStartSpot(1); + GameParticipant participant2 = new GameParticipant().setId(2).setFaction(Faction.AEON).setTeam(2).setStartSpot(2); ConnectionAware requester = mock(ConnectionAware.class); UUID requestId = UUID.randomUUID(); - List participants = Arrays.asList( + List participants = Arrays.asList( participant1, participant2 ); int mapVersionId = 1; @@ -236,7 +240,7 @@ public void createMatch() { when(mapService.findMap(mapVersionId)).thenReturn(Optional.of(new MapVersion().setFilename("maps/foo.zip"))); Game game = new Game().setId(1); - when(gameService.createGame("Test match", "faf", "foo", null, GameVisibility.PRIVATE, null, null, player1, LobbyMode.NONE)) + when(gameService.createGame("Test match", "faf", "foo", null, GameVisibility.PRIVATE, null, null, player1, LobbyMode.NONE, Optional.of(participants))) .thenReturn(CompletableFuture.completedFuture(game)); when(gameService.joinGame(1, null, player2)).thenReturn(CompletableFuture.completedFuture(game));