Skip to content

Commit

Permalink
Use game type to determine lobby mode (#2647)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 committed Apr 10, 2022
1 parent 72abb52 commit e19777b
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 25 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -297,7 +297,7 @@ dependencies {
implementation("org.springframework:spring-websocket")


def commonsVersion = "8d2c15b28593468ae7f33d5a717d855e1d156fa5"
def commonsVersion = "fa3229e48f3f9c83a0c68775ef20ae8dcdfa77f7"

implementation("com.github.FAForever.faf-java-commons:faf-commons-data:${commonsVersion}") {
exclude module: 'guava'
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/faforever/client/config/JsonApiConfig.java
Expand Up @@ -2,7 +2,6 @@

import com.faforever.client.exception.ConfigurationException;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.jasminb.jsonapi.ResourceConverter;
import com.github.jasminb.jsonapi.annotations.Type;
Expand All @@ -21,8 +20,7 @@ public class JsonApiConfig {
@Bean
public ResourceConverter resourceConverter(ObjectMapper objectMapper) {
return new ResourceConverter(objectMapper.copy()
.setSerializationInclusion(Include.NON_NULL)
.enable(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE),
.setSerializationInclusion(Include.NON_NULL),
findJsonApiTypes("com.faforever.commons.api.dto"));
}

Expand Down
23 changes: 10 additions & 13 deletions src/main/java/com/faforever/client/fa/relay/ice/IceAdapterImpl.java
@@ -1,6 +1,5 @@
package com.faforever.client.fa.relay.ice;

import com.faforever.client.config.ClientProperties;
import com.faforever.client.domain.PlayerBean;
import com.faforever.client.fa.relay.event.CloseGameEvent;
import com.faforever.client.fa.relay.event.GameFullEvent;
Expand All @@ -15,12 +14,12 @@
import com.faforever.commons.lobby.ConnectToPeerGpgCommand;
import com.faforever.commons.lobby.DisconnectFromPeerGpgCommand;
import com.faforever.commons.lobby.GameLaunchResponse;
import com.faforever.commons.lobby.GameType;
import com.faforever.commons.lobby.GpgGameOutboundMessage;
import com.faforever.commons.lobby.HostGameGpgCommand;
import com.faforever.commons.lobby.IceMsgGpgCommand;
import com.faforever.commons.lobby.IceServer;
import com.faforever.commons.lobby.JoinGameGpgCommand;
import com.faforever.commons.lobby.LobbyMode;
import com.google.common.collect.Lists;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
Expand All @@ -47,7 +46,6 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

Expand All @@ -65,7 +63,6 @@ public class IceAdapterImpl implements IceAdapter, InitializingBean, DisposableB
private static final Logger advancedLogger = LoggerFactory.getLogger("faf-ice-adapter-advanced");

private final ApplicationContext applicationContext;
private final ClientProperties clientProperties;
private final PlayerService playerService;
private final EventBus eventBus;
private final FafServerAccessor fafServerAccessor;
Expand All @@ -74,7 +71,7 @@ public class IceAdapterImpl implements IceAdapter, InitializingBean, DisposableB
private final IceAdapterApi iceAdapterProxy = newIceAdapterProxy();
private CompletableFuture<Integer> iceAdapterClientFuture;
private Process process;
private LobbyMode lobbyInitMode;
private GameType gameType;
private JJsonPeer peer;

@Override
Expand All @@ -83,7 +80,7 @@ public void afterPropertiesSet() {
fafServerAccessor.addEventListener(JoinGameGpgCommand.class, message -> iceAdapterProxy.joinGame(message.getUsername(), message.getPeerUid()));
fafServerAccessor.addEventListener(HostGameGpgCommand.class, message -> iceAdapterProxy.hostGame(message.getMap()));
fafServerAccessor.addEventListener(ConnectToPeerGpgCommand.class, message -> iceAdapterProxy.connectToPeer(message.getUsername(), message.getPeerUid(), message.isOffer()));
fafServerAccessor.addEventListener(GameLaunchResponse.class, this::updateLobbyModeFromGameInfo);
fafServerAccessor.addEventListener(GameLaunchResponse.class, this::updateGameTypeFromGameInfo);
fafServerAccessor.addEventListener(DisconnectFromPeerGpgCommand.class, message -> iceAdapterProxy.disconnectFromPeer(message.getUid()));
fafServerAccessor.addEventListener(IceMsgGpgCommand.class, message -> iceAdapterProxy.iceMsg(message.getSender(), message.getRecord()));
}
Expand Down Expand Up @@ -264,9 +261,10 @@ private void setIceServers() {
}

private void setLobbyInitMode() {
switch (lobbyInitMode) {
case DEFAULT_LOBBY -> iceAdapterProxy.setLobbyInitMode("normal");
case AUTO_LOBBY -> iceAdapterProxy.setLobbyInitMode("auto");
if (gameType == GameType.MATCHMAKER) {
iceAdapterProxy.setLobbyInitMode("auto");
} else {
iceAdapterProxy.setLobbyInitMode("normal");
}
}

Expand All @@ -293,9 +291,8 @@ private IceAdapterApi newIceAdapterProxy() {
);
}

private void updateLobbyModeFromGameInfo(GameLaunchResponse gameLaunchMessage) {
// TODO: Replace with game type. Needs https://github.com/FAForever/server/issues/685
lobbyInitMode = gameLaunchMessage.getLobbyMode();
private void updateGameTypeFromGameInfo(GameLaunchResponse gameLaunchMessage) {
gameType = gameLaunchMessage.getGameType();
}

@Override
Expand All @@ -304,7 +301,7 @@ public void destroy() {
}

public void stop() {
Optional.ofNullable(iceAdapterProxy).ifPresent(IceAdapterApi::quit);
iceAdapterProxy.quit();
peer = null;
}

Expand Down
@@ -1,13 +1,12 @@
package com.faforever.client.replay;

import com.faforever.client.config.ClientProperties;
import com.faforever.client.i18n.I18n;
import com.faforever.client.preferences.PreferencesService;
import com.faforever.commons.io.Bytes;
import com.faforever.commons.replay.QtCompress;
import com.faforever.commons.replay.ReplayMetadata;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.google.common.io.BaseEncoding;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -33,9 +32,8 @@
public class ReplayFileWriterImpl implements ReplayFileWriter {

private final ObjectMapper objectMapper = new ObjectMapper()
.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);

private final I18n i18n;
private final ClientProperties clientProperties;
private final PreferencesService preferencesService;

Expand Down
Expand Up @@ -32,7 +32,7 @@
import com.faforever.commons.api.elide.ElideNavigatorOnCollection;
import com.faforever.commons.lobby.Faction;
import com.faforever.commons.lobby.GameLaunchResponse;
import com.faforever.commons.lobby.LobbyMode;
import com.faforever.commons.lobby.GameType;
import com.faforever.commons.lobby.MatchmakerInfo;
import com.faforever.commons.lobby.MatchmakerMatchCancelledResponse;
import com.faforever.commons.lobby.MatchmakerMatchFoundResponse;
Expand Down Expand Up @@ -227,7 +227,7 @@ protected void onMatchCancelledMessage(MatchmakerMatchCancelledResponse message)

@VisibleForTesting
protected void onGameLaunchMessage(GameLaunchResponse message) {
if (message.getLobbyMode() != LobbyMode.AUTO_LOBBY) {
if (message.getGameType() != GameType.MATCHMAKER) {
return;
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application.yml
Expand Up @@ -78,6 +78,9 @@ spring:
allow-circular-references: true
codec:
max-in-memory-size: 16MB
jackson:
deserialization:
read-unknown-enum-values-using-default-value: true

logging:
level:
Expand Down
Expand Up @@ -3,6 +3,7 @@
import com.faforever.client.game.KnownFeaturedMod;
import com.faforever.commons.lobby.Faction;
import com.faforever.commons.lobby.GameLaunchResponse;
import com.faforever.commons.lobby.GameType;
import com.faforever.commons.lobby.LobbyMode;

import java.util.ArrayList;
Expand All @@ -21,7 +22,9 @@ public class GameLaunchMessageBuilder {
private Integer mapPosition;
private Map<String, String> gameOptions;
private Faction faction;
@Deprecated
private LobbyMode initMode;
private GameType gameType;
private String ratingType;

public static GameLaunchMessageBuilder create() {
Expand All @@ -33,13 +36,14 @@ public GameLaunchMessageBuilder defaultValues() {
uid(1);
mod(KnownFeaturedMod.DEFAULT.getTechnicalName());
args();
gameType(GameType.CUSTOM);
ratingType("global");
initMode(LobbyMode.DEFAULT_LOBBY);
return this;
}

public GameLaunchResponse get() {
return new GameLaunchResponse(uid, name, mod, initMode, ratingType, args, mapname, expectedPlayers, mapPosition, gameOptions, team, faction);
return new GameLaunchResponse(uid, name, mod, initMode, gameType, ratingType, args, mapname, expectedPlayers, mapPosition, gameOptions, team, faction);
}

public GameLaunchMessageBuilder name(String name) {
Expand Down Expand Up @@ -77,11 +81,17 @@ public GameLaunchMessageBuilder ratingType(String ratingType) {
return this;
}

@Deprecated
public GameLaunchMessageBuilder initMode(LobbyMode initMode) {
this.initMode = initMode;
return this;
}

public GameLaunchMessageBuilder gameType(GameType gameType) {
this.gameType = gameType;
return this;
}

public GameLaunchMessageBuilder mapPosition(int mapPosition) {
this.mapPosition = mapPosition;
return this;
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/com/faforever/client/game/GameServiceTest.java
Expand Up @@ -36,6 +36,7 @@
import com.faforever.client.ui.preferences.event.GameDirectoryChooseEvent;
import com.faforever.commons.lobby.GameInfo;
import com.faforever.commons.lobby.GameLaunchResponse;
import com.faforever.commons.lobby.GameType;
import com.faforever.commons.lobby.LobbyMode;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
Expand Down Expand Up @@ -507,6 +508,7 @@ public void testStartSearchLadder1v1() throws Exception {
.expectedPlayers(2)
.faction(com.faforever.commons.lobby.Faction.CYBRAN)
.initMode(LobbyMode.AUTO_LOBBY)
.gameType(GameType.MATCHMAKER)
.mapPosition(4)
.team(1)
.ratingType(LADDER_1v1_RATING_TYPE)
Expand Down Expand Up @@ -538,6 +540,7 @@ public void testStartSearchLadderTwiceReturnsSameFutureWhenSearching() throws Ex
.uid(uid).mod("FAF").mapname(map)
.expectedPlayers(2)
.faction(com.faforever.commons.lobby.Faction.CYBRAN)
.gameType(GameType.MATCHMAKER)
.initMode(LobbyMode.AUTO_LOBBY)
.mapPosition(4)
.team(1)
Expand Down
Expand Up @@ -27,6 +27,7 @@
import com.faforever.commons.lobby.Faction;
import com.faforever.commons.lobby.GameInfo;
import com.faforever.commons.lobby.GameLaunchResponse;
import com.faforever.commons.lobby.GameType;
import com.faforever.commons.lobby.GpgGameOutboundMessage;
import com.faforever.commons.lobby.HostGameGpgCommand;
import com.faforever.commons.lobby.IceMsgGpgCommand;
Expand Down Expand Up @@ -674,6 +675,7 @@ public void testOnGameLaunch() throws InterruptedException, JsonProcessingExcept
GameLaunchResponse gameLaunchMessage = GameLaunchMessageBuilder.create()
.defaultValues()
.faction(Faction.AEON)
.gameType(GameType.MATCHMAKER)
.initMode(LobbyMode.AUTO_LOBBY)
.get();

Expand All @@ -695,6 +697,7 @@ public void testOnGameLaunch() throws InterruptedException, JsonProcessingExcept
"map_position" : null,
"faction" : "aeon",
"init_mode" : 1,
"game_type" : "matchmaker",
"rating_type" : "global"
}""");

Expand Down
Expand Up @@ -27,6 +27,7 @@
import com.faforever.commons.api.dto.MatchmakerQueue;
import com.faforever.commons.lobby.Faction;
import com.faforever.commons.lobby.GameLaunchResponse;
import com.faforever.commons.lobby.GameType;
import com.faforever.commons.lobby.LobbyMode;
import com.faforever.commons.lobby.MatchmakerInfo;
import com.faforever.commons.lobby.MatchmakerMatchCancelledResponse;
Expand Down Expand Up @@ -270,7 +271,7 @@ public void testOnMatchCancelledMessage() {
@Test
public void testOnGameLaunchMessage() {
testOnMatchFoundMessage();
GameLaunchResponse message = GameLaunchMessageBuilder.create().defaultValues().initMode(LobbyMode.AUTO_LOBBY).get();
GameLaunchResponse message = GameLaunchMessageBuilder.create().defaultValues().gameType(GameType.MATCHMAKER).initMode(LobbyMode.AUTO_LOBBY).get();

instance.onGameLaunchMessage(message);

Expand Down

0 comments on commit e19777b

Please sign in to comment.