Skip to content

Commit

Permalink
Improve compatibility for kotlin-ice-adapter
Browse files Browse the repository at this point in the history
Use access token and ice breaker
  • Loading branch information
Sheikah45 authored and Brutus5000 committed May 17, 2024
1 parent eec7e20 commit 3d0ab73
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.faforever.client.fa.relay.ice;

import com.faforever.client.api.TokenRetriever;
import com.faforever.client.config.ClientProperties;
import com.faforever.client.domain.server.PlayerInfo;
import com.faforever.client.fa.GameFullNotifier;
import com.faforever.client.mapstruct.IceServerMapper;
Expand Down Expand Up @@ -64,9 +66,11 @@ public class IceAdapterImpl implements IceAdapter, InitializingBean, DisposableB
private final IceServerMapper iceServerMapper;
private final Preferences preferences;
private final ForgedAlliancePrefs forgedAlliancePrefs;
private final TokenRetriever tokenRetriever;
private final ObjectFactory<IceAdapterCallbacks> iceAdapterCallbacksFactory;
@Lazy
private final GameFullNotifier gameFullNotifier;
private final ClientProperties clientProperties;

private final IceAdapterApi iceAdapterProxy = newIceAdapterProxy();
private GameType gameType;
Expand Down Expand Up @@ -231,8 +235,9 @@ List<String> buildCommand(Path workDirectory, int adapterPort, int gpgPort, int
"--id", String.valueOf(currentPlayer.getId()),
"--game-id", String.valueOf(gameId),
"--login", currentPlayer.getUsername(),
"--rpc-port", String.valueOf(adapterPort),
"--gpgnet-port", String.valueOf(gpgPort));
"--rpc-port", String.valueOf(adapterPort), "--gpgnet-port", String.valueOf(gpgPort), "--access-token",
tokenRetriever.getRefreshedTokenValue().block(), "--icebreaker-base-url",
clientProperties.getApi().getBaseUrl() + "/ice");

cmd.addAll(standardIceOptions);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.faforever.client.fa.relay.ice;

import com.faforever.client.api.TokenRetriever;
import com.faforever.client.builders.GameLaunchMessageBuilder;
import com.faforever.client.builders.PlayerInfoBuilder;
import com.faforever.client.config.ClientProperties;
Expand All @@ -21,12 +22,14 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mapstruct.factory.Mappers;
import org.mockito.Answers;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.test.util.ReflectionTestUtils;
import reactor.core.publisher.Mono;

import java.net.URI;
import java.nio.file.Path;
Expand All @@ -47,7 +50,7 @@ public class IceAdapterImplTest extends ServiceTest {
private IceAdapterImpl instance;
@Spy
private OperatingSystem operatingSystem = new OsPosix();
@Mock
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ClientProperties clientProperties;
@Mock
private PlayerService playerService;
Expand All @@ -58,6 +61,8 @@ public class IceAdapterImplTest extends ServiceTest {
@Mock
private GameService gameService;
@Mock
private TokenRetriever tokenRetriever;
@Mock
private ObjectFactory<IceAdapterCallbacks> iceAdapterCallbacksFactory;

@Mock
Expand Down Expand Up @@ -111,6 +116,8 @@ public void testBuildCommand() throws Exception {
when(operatingSystem.getJavaExecutablePath()).thenReturn(javaExecutablePath);
PlayerInfo currentPlayer = PlayerInfoBuilder.create().defaultValues().get();
when(playerService.getCurrentPlayer()).thenReturn(currentPlayer);
when(clientProperties.getApi().getBaseUrl()).thenReturn("http://faf-api");
when(tokenRetriever.getRefreshedTokenValue()).thenReturn(Mono.just("someToken"));
forgedAlliancePrefs.setShowIceAdapterDebugWindow(true);

List<String> command = instance.buildCommand(Path.of("."), 0, 0, 4711);
Expand All @@ -131,8 +138,12 @@ public void testBuildCommand() throws Exception {
assertEquals(String.valueOf(0), command.get(12));
assertEquals("--gpgnet-port", command.get(13));
assertEquals(String.valueOf(0), command.get(14));
assertEquals("--debug-window", command.get(15));
assertEquals("--info-window", command.get(16));
assertEquals("--access-token", command.get(15));
assertEquals("someToken", command.get(16));
assertEquals("--icebreaker-base-url", command.get(17));
assertEquals("http://faf-api/ice", command.get(18));
assertEquals("--debug-window", command.get(19));
assertEquals("--info-window", command.get(20));
}

@Test
Expand All @@ -144,6 +155,8 @@ public void testAllowIpv6() throws Exception {
forgedAlliancePrefs.setShowIceAdapterDebugWindow(true);
PlayerInfo currentPlayer = PlayerInfoBuilder.create().defaultValues().get();
when(playerService.getCurrentPlayer()).thenReturn(currentPlayer);
when(clientProperties.getApi().getBaseUrl()).thenReturn("http://faf-api");
when(tokenRetriever.getRefreshedTokenValue()).thenReturn(Mono.just("someToken"));

List<String> command = instance.buildCommand(Path.of("."), 0, 0, 4711);

Expand Down

0 comments on commit 3d0ab73

Please sign in to comment.