use of com.faforever.client.remote.domain.GameLaunchMessage in project downlords-faf-client by FAForever.
the class GameServiceImplTest method testModEnabling.
@Test
@SuppressWarnings("unchecked")
public void testModEnabling() throws Exception {
Game game = GameBuilder.create().defaultValues().get();
ObservableMap<String, String> simMods = FXCollections.observableHashMap();
simMods.put("123-456-789", "Fake mod name");
game.setSimMods(simMods);
game.setMapFolderName("map");
GameLaunchMessage gameLaunchMessage = GameLaunchMessageBuilder.create().defaultValues().get();
when(mapService.isInstalled("map")).thenReturn(true);
when(fafService.requestJoinGame(game.getId(), null)).thenReturn(completedFuture(gameLaunchMessage));
when(gameUpdater.update(any(), any(), any(), any())).thenReturn(completedFuture(null));
when(modService.getFeaturedMod(game.getFeaturedMod())).thenReturn(CompletableFuture.completedFuture(FeaturedModBeanBuilder.create().defaultValues().get()));
instance.joinGame(game, null).toCompletableFuture().get();
verify(modService).enableSimMods(simModsCaptor.capture());
assertEquals(simModsCaptor.getValue().iterator().next(), "123-456-789");
}
use of com.faforever.client.remote.domain.GameLaunchMessage in project downlords-faf-client by FAForever.
the class GameServiceImplTest method testStartSearchLadder1v1GameRunningDoesNothing.
@Test
public void testStartSearchLadder1v1GameRunningDoesNothing() throws Exception {
Process process = mock(Process.class);
when(process.isAlive()).thenReturn(true);
NewGameInfo newGameInfo = NewGameInfoBuilder.create().defaultValues().get();
GameLaunchMessage gameLaunchMessage = GameLaunchMessageBuilder.create().defaultValues().get();
when(forgedAllianceService.startGame(anyInt(), any(), any(), any(), anyInt(), eq(LOCAL_REPLAY_PORT), eq(false), eq(junitPlayer))).thenReturn(process);
when(gameUpdater.update(any(), any(), any(), any())).thenReturn(completedFuture(null));
when(fafService.requestHostGame(newGameInfo)).thenReturn(completedFuture(gameLaunchMessage));
when(mapService.download(newGameInfo.getMap())).thenReturn(CompletableFuture.completedFuture(null));
CountDownLatch gameRunningLatch = new CountDownLatch(1);
instance.gameRunningProperty().addListener((observable, oldValue, newValue) -> {
if (newValue) {
gameRunningLatch.countDown();
}
});
instance.hostGame(newGameInfo);
gameRunningLatch.await(TIMEOUT, TIME_UNIT);
instance.startSearchLadder1v1(AEON);
assertThat(instance.searching1v1Property().get(), is(false));
}
use of com.faforever.client.remote.domain.GameLaunchMessage in project downlords-faf-client by FAForever.
the class GameServiceImplTest method testJoinGameMapIsAvailable.
@Test
@SuppressWarnings("unchecked")
public void testJoinGameMapIsAvailable() throws Exception {
Game game = GameBuilder.create().defaultValues().get();
ObservableMap<String, String> simMods = FXCollections.observableHashMap();
simMods.put("123-456-789", "Fake mod name");
game.setSimMods(simMods);
game.setMapFolderName("map");
GameLaunchMessage gameLaunchMessage = GameLaunchMessageBuilder.create().defaultValues().get();
when(mapService.isInstalled("map")).thenReturn(true);
when(fafService.requestJoinGame(game.getId(), null)).thenReturn(completedFuture(gameLaunchMessage));
when(gameUpdater.update(any(), any(), any(), any())).thenReturn(completedFuture(null));
when(modService.getFeaturedMod(game.getFeaturedMod())).thenReturn(CompletableFuture.completedFuture(FeaturedModBeanBuilder.create().defaultValues().get()));
CompletableFuture<Void> future = instance.joinGame(game, null).toCompletableFuture();
assertThat(future.get(TIMEOUT, TIME_UNIT), is(nullValue()));
verify(mapService, never()).download(any());
verify(replayService).startReplayServer(game.getId());
}
use of com.faforever.client.remote.domain.GameLaunchMessage in project downlords-faf-client by FAForever.
the class GameServiceImpl method startGame.
/**
* Actually starts the game, including relay and replay server. Call this method when everything else is prepared
* (mod/map download, connectivity check etc.)
*/
private void startGame(GameLaunchMessage gameLaunchMessage, Faction faction, RatingMode ratingMode) {
if (isRunning()) {
logger.warn("Forged Alliance is already running, not starting game");
return;
}
stopSearchLadder1v1();
replayService.startReplayServer(gameLaunchMessage.getUid()).thenCompose(aVoid -> iceAdapter.start()).thenAccept(adapterPort -> {
List<String> args = fixMalformedArgs(gameLaunchMessage.getArgs());
process = noCatch(() -> forgedAllianceService.startGame(gameLaunchMessage.getUid(), faction, args, ratingMode, adapterPort, clientProperties.getReplay().getLocalServerPort(), rehostRequested, getCurrentPlayer()));
setGameRunning(true);
this.ratingMode = ratingMode;
spawnTerminationListener(process);
}).exceptionally(throwable -> {
logger.warn("Game could not be started", throwable);
notificationService.addNotification(new ImmediateNotification(i18n.get("errorTitle"), i18n.get("game.start.couldNotStart"), ERROR, throwable, Arrays.asList(new ReportAction(i18n, reportingService, throwable), new DismissAction(i18n))));
setGameRunning(false);
return null;
});
}
use of com.faforever.client.remote.domain.GameLaunchMessage in project downlords-faf-client by FAForever.
the class MockFafServerAccessor method requestHostGame.
@Override
public CompletableFuture<GameLaunchMessage> requestHostGame(NewGameInfo newGameInfo) {
return taskService.submitTask(new CompletableTask<GameLaunchMessage>(HIGH) {
@Override
protected GameLaunchMessage call() throws Exception {
updateTitle("Hosting game");
GameLaunchMessage gameLaunchMessage = new GameLaunchMessage();
gameLaunchMessage.setArgs(Arrays.asList("/ratingcolor d8d8d8d8", "/numgames 1234"));
gameLaunchMessage.setMod("faf");
gameLaunchMessage.setUid(1234);
return gameLaunchMessage;
}
}).getFuture();
}
Aggregations