Search in sources :

Example 1 with GameLaunchMessage

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");
}
Also used : GameLaunchMessage(com.faforever.client.remote.domain.GameLaunchMessage) Test(org.junit.Test) AbstractPlainJavaFxTest(com.faforever.client.test.AbstractPlainJavaFxTest)

Example 2 with GameLaunchMessage

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));
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) GameLaunchMessage(com.faforever.client.remote.domain.GameLaunchMessage) Test(org.junit.Test) AbstractPlainJavaFxTest(com.faforever.client.test.AbstractPlainJavaFxTest)

Example 3 with GameLaunchMessage

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());
}
Also used : GameLaunchMessage(com.faforever.client.remote.domain.GameLaunchMessage) Test(org.junit.Test) AbstractPlainJavaFxTest(com.faforever.client.test.AbstractPlainJavaFxTest)

Example 4 with GameLaunchMessage

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;
    });
}
Also used : Arrays(java.util.Arrays) RehostRequestEvent(com.faforever.client.fa.relay.event.RehostRequestEvent) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) LoggerFactory(org.slf4j.LoggerFactory) ReadOnlyBooleanProperty(javafx.beans.property.ReadOnlyBooleanProperty) ReportingService(com.faforever.client.reporting.ReportingService) ConnectionState(com.faforever.client.net.ConnectionState) GameInfoMessage(com.faforever.client.remote.domain.GameInfoMessage) Collections.singletonList(java.util.Collections.singletonList) ListChangeListener(javafx.collections.ListChangeListener) Map(java.util.Map) GameStatus(com.faforever.client.remote.domain.GameStatus) URI(java.net.URI) PlayerService(com.faforever.client.player.PlayerService) Path(java.nio.file.Path) ClientProperties(com.faforever.client.config.ClientProperties) CancellationException(java.util.concurrent.CancellationException) MethodHandles(java.lang.invoke.MethodHandles) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ObservableMap(javafx.collections.ObservableMap) Observable(javafx.beans.Observable) DismissAction(com.faforever.client.notification.DismissAction) FeaturedMod(com.faforever.client.mod.FeaturedMod) Platform(javafx.application.Platform) Player(com.faforever.client.player.Player) Nullable(org.jetbrains.annotations.Nullable) RatingMode(com.faforever.client.fa.RatingMode) BooleanProperty(javafx.beans.property.BooleanProperty) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ForgedAllianceService(com.faforever.client.fa.ForgedAllianceService) PostConstruct(javax.annotation.PostConstruct) ModService(com.faforever.client.mod.ModService) Lazy(org.springframework.context.annotation.Lazy) ObservableList(javafx.collections.ObservableList) NotNull(org.jetbrains.annotations.NotNull) PreferencesService(com.faforever.client.preferences.PreferencesService) WeakChangeListener(javafx.beans.value.WeakChangeListener) GameLaunchMessage(com.faforever.client.remote.domain.GameLaunchMessage) LoginMessage(com.faforever.client.remote.domain.LoginMessage) FXCollections(javafx.collections.FXCollections) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) IceAdapter(com.faforever.client.fa.relay.ice.IceAdapter) PlatformService(com.faforever.client.fx.PlatformService) GameUpdater(com.faforever.client.patch.GameUpdater) EventBus(com.google.common.eventbus.EventBus) Inject(javax.inject.Inject) HashSet(java.util.HashSet) NotificationService(com.faforever.client.notification.NotificationService) Service(org.springframework.stereotype.Service) ERROR(com.faforever.client.notification.Severity.ERROR) Subscribe(com.google.common.eventbus.Subscribe) ReportAction(com.faforever.client.notification.ReportAction) Collections.emptyMap(java.util.Collections.emptyMap) Logger(org.slf4j.Logger) Collections.emptySet(java.util.Collections.emptySet) Executor(java.util.concurrent.Executor) JavaFxUtil(com.faforever.client.fx.JavaFxUtil) Action(com.faforever.client.notification.Action) ReplayService(com.faforever.client.replay.ReplayService) IOException(java.io.IOException) MatchmakerMessage(com.faforever.client.rankedmatch.MatchmakerMessage) PersistentNotification(com.faforever.client.notification.PersistentNotification) FafService(com.faforever.client.remote.FafService) Consumer(java.util.function.Consumer) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) Severity(com.faforever.client.notification.Severity) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) LADDER_1V1(com.faforever.client.game.KnownFeaturedMod.LADDER_1V1) ImmediateNotification(com.faforever.client.notification.ImmediateNotification) NONE(com.faforever.client.fa.RatingMode.NONE) ExternalReplayInfoGenerator(com.faforever.client.replay.ExternalReplayInfoGenerator) VisibleForTesting(com.google.common.annotations.VisibleForTesting) I18n(com.faforever.client.i18n.I18n) MapService(com.faforever.client.map.MapService) Collections(java.util.Collections) NoCatch.noCatch(com.github.nocatch.NoCatch.noCatch) ImmediateNotification(com.faforever.client.notification.ImmediateNotification) DismissAction(com.faforever.client.notification.DismissAction) ReportAction(com.faforever.client.notification.ReportAction) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ObservableList(javafx.collections.ObservableList) ArrayList(java.util.ArrayList)

Example 5 with GameLaunchMessage

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();
}
Also used : CompletableTask(com.faforever.client.task.CompletableTask) GameLaunchMessage(com.faforever.client.remote.domain.GameLaunchMessage)

Aggregations

GameLaunchMessage (com.faforever.client.remote.domain.GameLaunchMessage)10 AbstractPlainJavaFxTest (com.faforever.client.test.AbstractPlainJavaFxTest)6 Test (org.junit.Test)6 FeaturedMod (com.faforever.client.mod.FeaturedMod)2 CompletableTask (com.faforever.client.task.CompletableTask)2 ClientProperties (com.faforever.client.config.ClientProperties)1 ForgedAllianceService (com.faforever.client.fa.ForgedAllianceService)1 RatingMode (com.faforever.client.fa.RatingMode)1 NONE (com.faforever.client.fa.RatingMode.NONE)1 RehostRequestEvent (com.faforever.client.fa.relay.event.RehostRequestEvent)1 IceAdapter (com.faforever.client.fa.relay.ice.IceAdapter)1 JavaFxUtil (com.faforever.client.fx.JavaFxUtil)1 PlatformService (com.faforever.client.fx.PlatformService)1 LADDER_1V1 (com.faforever.client.game.KnownFeaturedMod.LADDER_1V1)1 I18n (com.faforever.client.i18n.I18n)1 MapService (com.faforever.client.map.MapService)1 ModService (com.faforever.client.mod.ModService)1 ConnectionState (com.faforever.client.net.ConnectionState)1 Action (com.faforever.client.notification.Action)1 DismissAction (com.faforever.client.notification.DismissAction)1