diff --git a/ice-adapter/src/main/java/com/faforever/iceadapter/IceAdapter.java b/ice-adapter/src/main/java/com/faforever/iceadapter/IceAdapter.java index 9a5cd74..1c5959f 100644 --- a/ice-adapter/src/main/java/com/faforever/iceadapter/IceAdapter.java +++ b/ice-adapter/src/main/java/com/faforever/iceadapter/IceAdapter.java @@ -6,6 +6,7 @@ import com.faforever.iceadapter.gpgnet.GPGNetServer; import com.faforever.iceadapter.gpgnet.GameState; import com.faforever.iceadapter.ice.GameSession; +import com.faforever.iceadapter.ice.PeerIceModule; import com.faforever.iceadapter.rpc.RPCService; import com.faforever.iceadapter.util.Executor; import com.faforever.iceadapter.util.TrayIcon; @@ -20,30 +21,14 @@ description = "An ice (RFC 5245) based network bridge between FAF client and ForgedAlliance.exe") @Slf4j public class IceAdapter implements Callable { - @CommandLine.ArgGroup(exclusive = false) - private IceOptions iceOptions; - - public static String TELEMETRY_SERVER; - - public static boolean ALLOW_HOST = true; - public static boolean ALLOW_REFLEXIVE = true; - public static boolean ALLOW_RELAY = true; - - public static volatile boolean running = true; - + private static IceAdapter INSTANCE; public static String VERSION = "SNAPSHOT"; + public static volatile GameSession gameSession; - public static int id = -1; - public static int gameId = -1; - public static String login; - public static int RPC_PORT; - public static int GPGNET_PORT = 0; - public static int LOBBY_PORT = 0; + @CommandLine.ArgGroup(exclusive = false) + private IceOptions iceOptions; - public static int PING_COUNT = 1; - public static double ACCEPTABLE_LATENCY = 250.0; - - public static volatile GameSession gameSession; + public volatile boolean running = true; public static void main(String[] args) { new CommandLine(new IceAdapter()).setUnmatchedArgumentsAllowed(true).execute(args); @@ -51,31 +36,26 @@ public static void main(String[] args) { @Override public Integer call() { - IceAdapter.start(iceOptions); + INSTANCE = this; + + start(); return 0; } - public static void start(IceOptions iceOptions) { + public void start() { determineVersion(); + log.info("Version: {}", VERSION); - loadOptions(iceOptions); + Debug.DELAY_UI_MS = iceOptions.getDelayUi(); + Debug.ENABLE_DEBUG_WINDOW = iceOptions.isDebugWindow(); + Debug.ENABLE_INFO_WINDOW = iceOptions.isInfoWindow(); + Debug.init(); TrayIcon.create(); - // Configure file appender - // RollingFileAppender fileAppender = - // (ch.qos.logback.core.rolling.RollingFileAppender)((ch.qos.logback.classic.Logger)log).getAppender("FILE"); - // if (logDirectory != null) { - // Util.mkdir(Paths.get(logDirectory).toFile()); - // //TODO: set log dir - // } else { - //// fileAppender.stop(); - // } - - log.info("Version: {}", VERSION); - - GPGNetServer.init(); - RPCService.init(); + PeerIceModule.setForceRelay(iceOptions.isForceRelay()); + GPGNetServer.init(iceOptions.getGpgnetPort(), iceOptions.getLobbyPort()); + RPCService.init(iceOptions.getRpcPort()); debug().startupComplete(); } @@ -171,36 +151,36 @@ public static void close() { System.exit(0); } - /** - * Read command line arguments and set global, constant values - * @param iceOptions The arguments to be read - */ - public static void loadOptions(IceOptions iceOptions) { - TELEMETRY_SERVER = iceOptions.getTelemetryServer(); - id = iceOptions.getId(); - gameId = iceOptions.getGameId(); - login = iceOptions.getLogin(); - RPC_PORT = iceOptions.getRpcPort(); - GPGNET_PORT = iceOptions.getGpgnetPort(); - LOBBY_PORT = iceOptions.getLobbyPort(); - - if (iceOptions.isForceRelay()) { - ALLOW_HOST = false; - ALLOW_REFLEXIVE = false; - ALLOW_RELAY = true; - } + public static int getId() { + return INSTANCE.iceOptions.getId(); + } - Debug.DELAY_UI_MS = iceOptions.getDelayUi(); - PING_COUNT = iceOptions.getPingCount(); - ACCEPTABLE_LATENCY = iceOptions.getAcceptableLatency(); + public static int getGameId() { + return INSTANCE.iceOptions.getGameId(); + } - Debug.ENABLE_DEBUG_WINDOW = iceOptions.isDebugWindow(); - Debug.ENABLE_INFO_WINDOW = iceOptions.isInfoWindow(); - Debug.init(); + public static String getLogin() { + return INSTANCE.iceOptions.getLogin(); + } + + public static String getTelemetryServer() { + return INSTANCE.iceOptions.getTelemetryServer(); + } + + public static int getPingCount() { + return INSTANCE.iceOptions.getPingCount(); + } + + public static double getAcceptableLatency() { + return INSTANCE.iceOptions.getAcceptableLatency(); + } + + public static boolean isRunning() { + return INSTANCE.running; } - private static void determineVersion() { - String versionFromGradle = IceAdapter.class.getPackage().getImplementationVersion(); + private void determineVersion() { + String versionFromGradle = getClass().getPackage().getImplementationVersion(); if (versionFromGradle != null) { VERSION = versionFromGradle; } diff --git a/ice-adapter/src/main/java/com/faforever/iceadapter/debug/Debug.java b/ice-adapter/src/main/java/com/faforever/iceadapter/debug/Debug.java index 835cc58..bcdbb88 100644 --- a/ice-adapter/src/main/java/com/faforever/iceadapter/debug/Debug.java +++ b/ice-adapter/src/main/java/com/faforever/iceadapter/debug/Debug.java @@ -15,6 +15,8 @@ public class Debug { public static boolean ENABLE_INFO_WINDOW = false; public static int DELAY_UI_MS = 0; // delays the launch of the user interface by X ms + public static int RPC_PORT; + private static final DebugFacade debugFacade = new DebugFacade(); public static void register(Debugger debugger) { @@ -26,7 +28,7 @@ public static void remove(Debugger debugger) { } public static void init() { - new TelemetryDebugger(IceAdapter.TELEMETRY_SERVER, IceAdapter.gameId, IceAdapter.id); + new TelemetryDebugger(IceAdapter.getTelemetryServer(), IceAdapter.getGameId(), IceAdapter.getId()); // Debugger window is started and set to debugFuture when either window is requested as the info window can be // used to open the debug window diff --git a/ice-adapter/src/main/java/com/faforever/iceadapter/debug/DebugWindow.java b/ice-adapter/src/main/java/com/faforever/iceadapter/debug/DebugWindow.java index 481aba0..46731d4 100644 --- a/ice-adapter/src/main/java/com/faforever/iceadapter/debug/DebugWindow.java +++ b/ice-adapter/src/main/java/com/faforever/iceadapter/debug/DebugWindow.java @@ -99,10 +99,10 @@ public void initStaticVariables() { runOnUIThread(() -> { controller.versionLabel.setText("Version: %s".formatted(IceAdapter.VERSION)); - controller.userLabel.setText("User: %s(%d)".formatted(IceAdapter.login, IceAdapter.id)); - controller.rpcPortLabel.setText("RPC_PORT: %d".formatted(IceAdapter.RPC_PORT)); - controller.gpgnetPortLabel.setText("GPGNET_PORT: %d".formatted(IceAdapter.GPGNET_PORT)); - controller.lobbyPortLabel.setText("LOBBY_PORT: %d".formatted(IceAdapter.LOBBY_PORT)); + controller.userLabel.setText("User: %s(%d)".formatted(IceAdapter.getLogin(), IceAdapter.getId())); + controller.rpcPortLabel.setText("RPC_PORT: %d".formatted(Debug.RPC_PORT)); + controller.gpgnetPortLabel.setText("GPGNET_PORT: %d".formatted(GPGNetServer.getGpgnetPort())); + controller.lobbyPortLabel.setText("LOBBY_PORT: %d".formatted(GPGNetServer.getLobbyPort())); }); } diff --git a/ice-adapter/src/main/java/com/faforever/iceadapter/debug/InfoWindowController.java b/ice-adapter/src/main/java/com/faforever/iceadapter/debug/InfoWindowController.java index 7fcf2a7..516d1c5 100644 --- a/ice-adapter/src/main/java/com/faforever/iceadapter/debug/InfoWindowController.java +++ b/ice-adapter/src/main/java/com/faforever/iceadapter/debug/InfoWindowController.java @@ -36,7 +36,10 @@ public void onShowDebugWindowClicked(ActionEvent actionEvent) { @SneakyThrows public void onTelemetryWebUiClicked(ActionEvent actionEvent) { String url = "%s/app.html?gameId=%d&playerId=%d" - .formatted(IceAdapter.TELEMETRY_SERVER.replaceFirst("ws", "http"), IceAdapter.gameId, IceAdapter.id); + .formatted( + IceAdapter.getTelemetryServer().replaceFirst("ws", "http"), + IceAdapter.getGameId(), + IceAdapter.getId()); new Thread(() -> { try { diff --git a/ice-adapter/src/main/java/com/faforever/iceadapter/debug/TelemetryDebugger.java b/ice-adapter/src/main/java/com/faforever/iceadapter/debug/TelemetryDebugger.java index 81a80e8..4d7c1d6 100644 --- a/ice-adapter/src/main/java/com/faforever/iceadapter/debug/TelemetryDebugger.java +++ b/ice-adapter/src/main/java/com/faforever/iceadapter/debug/TelemetryDebugger.java @@ -134,7 +134,8 @@ public void startupComplete() { log.error("Failed to connect to telemetry websocket", e); } - sendMessage(new RegisterAsPeer(UUID.randomUUID(), "java-ice-adapter/" + IceAdapter.VERSION, IceAdapter.login)); + sendMessage( + new RegisterAsPeer(UUID.randomUUID(), "java-ice-adapter/" + IceAdapter.VERSION, IceAdapter.getLogin())); } @Override diff --git a/ice-adapter/src/main/java/com/faforever/iceadapter/gpgnet/GPGNetServer.java b/ice-adapter/src/main/java/com/faforever/iceadapter/gpgnet/GPGNetServer.java index 50c6088..02ae0a5 100644 --- a/ice-adapter/src/main/java/com/faforever/iceadapter/gpgnet/GPGNetServer.java +++ b/ice-adapter/src/main/java/com/faforever/iceadapter/gpgnet/GPGNetServer.java @@ -19,6 +19,8 @@ @Slf4j public class GPGNetServer { + private static int GPGNET_PORT; + private static int LOBBY_PORT; private static ServerSocket serverSocket; private static volatile GPGNetClient currentClient; @@ -27,28 +29,29 @@ public class GPGNetServer { public static volatile LobbyInitMode lobbyInitMode = LobbyInitMode.NORMAL; - public static void init() { - if (IceAdapter.GPGNET_PORT == 0) { - IceAdapter.GPGNET_PORT = NetworkToolbox.findFreeTCPPort(20000, 65536); - log.info("Generated GPGNET_PORT: {}", IceAdapter.GPGNET_PORT); + public static void init(int gpgnetPort, int lobbyPort) { + if (gpgnetPort == 0) { + GPGNET_PORT = NetworkToolbox.findFreeTCPPort(20000, 65536); + log.info("Generated GPGNET_PORT: {}", GPGNET_PORT); } else { - log.info("Using GPGNET_PORT: {}", IceAdapter.GPGNET_PORT); + GPGNET_PORT = gpgnetPort; + log.info("Using GPGNET_PORT: {}", GPGNET_PORT); } - if (IceAdapter.LOBBY_PORT == 0) { - IceAdapter.LOBBY_PORT = NetworkToolbox.findFreeUDPPort(20000, 65536); - log.info("Generated LOBBY_PORT: {}", IceAdapter.LOBBY_PORT); + if (lobbyPort == 0) { + LOBBY_PORT = NetworkToolbox.findFreeUDPPort(20000, 65536); + log.info("Generated LOBBY_PORT: {}", LOBBY_PORT); } else { - log.info("Using LOBBY_PORT: {}", IceAdapter.LOBBY_PORT); + LOBBY_PORT = lobbyPort; + log.info("Using LOBBY_PORT: {}", LOBBY_PORT); } try { - serverSocket = new ServerSocket(IceAdapter.GPGNET_PORT); + serverSocket = new ServerSocket(GPGNetServer.getGpgnetPort()); } catch (IOException e) { log.error("Couldn't start GPGNetServer", e); System.exit(-1); } - new Thread(GPGNetServer::acceptThread).start(); log.info("GPGNetServer started"); } @@ -95,9 +98,9 @@ private void processGpgnetMessage(String command, List args) { sendGpgnetMessage( "CreateLobby", lobbyInitMode.getId(), - IceAdapter.LOBBY_PORT, - IceAdapter.login, - IceAdapter.id, + GPGNetServer.getLobbyPort(), + IceAdapter.getLogin(), + IceAdapter.getId(), 1); } else if (gameState == GameState.LOBBY) { lobbyFuture.complete(this); @@ -209,7 +212,7 @@ private static void onGpgnetConnectionLost() { * Listens for incoming connections from a game instance */ private static void acceptThread() { - while (IceAdapter.running) { + while (IceAdapter.isRunning()) { try { Socket socket = serverSocket.accept(); synchronized (serverSocket) { @@ -245,6 +248,14 @@ public static Optional getGameState() { return Optional.ofNullable(currentClient).map(GPGNetClient::getGameState); } + public static int getGpgnetPort() { + return GPGNET_PORT; + } + + public static int getLobbyPort() { + return LOBBY_PORT; + } + /** * Stops the GPGNetServer and thereby the connection to a currently connected client */ diff --git a/ice-adapter/src/main/java/com/faforever/iceadapter/ice/GameSession.java b/ice-adapter/src/main/java/com/faforever/iceadapter/ice/GameSession.java index 399c274..95a5c44 100644 --- a/ice-adapter/src/main/java/com/faforever/iceadapter/ice/GameSession.java +++ b/ice-adapter/src/main/java/com/faforever/iceadapter/ice/GameSession.java @@ -115,7 +115,7 @@ public static void setIceServers(List> iceServersData) { .build(new CacheLoader<>() { @Override public CompletableFuture load(String host) { - return PingWrapper.getLatency(host, IceAdapter.PING_COUNT) + return PingWrapper.getLatency(host, IceAdapter.getPingCount()) .thenApply(OptionalDouble::of) .exceptionally(ex -> OptionalDouble.empty()); } @@ -172,7 +172,7 @@ public CompletableFuture load(String host) { default -> log.warn("Invalid ICE server protocol: {}", uri); } - if (IceAdapter.PING_COUNT > 0) { + if (IceAdapter.getPingCount() > 0) { iceServer.setRoundTripTime(hostRTTCache.getUnchecked(host)); } diff --git a/ice-adapter/src/main/java/com/faforever/iceadapter/ice/IceServer.java b/ice-adapter/src/main/java/com/faforever/iceadapter/ice/IceServer.java index c4e6d25..aa4ea5b 100644 --- a/ice-adapter/src/main/java/com/faforever/iceadapter/ice/IceServer.java +++ b/ice-adapter/src/main/java/com/faforever/iceadapter/ice/IceServer.java @@ -22,6 +22,6 @@ public class IceServer { public boolean hasAcceptableLatency() { OptionalDouble rtt = this.getRoundTripTime().join(); - return !rtt.isPresent() || rtt.getAsDouble() < IceAdapter.ACCEPTABLE_LATENCY; + return rtt.isEmpty() || rtt.getAsDouble() < IceAdapter.getAcceptableLatency(); } } diff --git a/ice-adapter/src/main/java/com/faforever/iceadapter/ice/Peer.java b/ice-adapter/src/main/java/com/faforever/iceadapter/ice/Peer.java index 8aa11c7..b99bf6c 100644 --- a/ice-adapter/src/main/java/com/faforever/iceadapter/ice/Peer.java +++ b/ice-adapter/src/main/java/com/faforever/iceadapter/ice/Peer.java @@ -1,6 +1,7 @@ package com.faforever.iceadapter.ice; import com.faforever.iceadapter.IceAdapter; +import com.faforever.iceadapter.gpgnet.GPGNetServer; import java.io.IOException; import java.net.*; import lombok.Getter; @@ -33,10 +34,7 @@ public Peer(GameSession gameSession, int remoteId, String remoteLogin, boolean l this.preferredPort = preferredPort; log.debug( - "Peer created: {}, localOffer: {}, preferredPort: {}", - getPeerIdentifier(), - String.valueOf(localOffer), - preferredPort); + "Peer created: {}, localOffer: {}, preferredPort: {}", getPeerIdentifier(), localOffer, preferredPort); initForwarding(preferredPort); @@ -68,8 +66,8 @@ private void initForwarding(int port) { */ synchronized void onIceDataReceived(byte data[], int offset, int length) { try { - DatagramPacket packet = - new DatagramPacket(data, offset, length, InetAddress.getByName("127.0.0.1"), IceAdapter.LOBBY_PORT); + DatagramPacket packet = new DatagramPacket( + data, offset, length, InetAddress.getByName("127.0.0.1"), GPGNetServer.getLobbyPort()); faSocket.send(packet); } catch (UnknownHostException e) { } catch (IOException e) { @@ -90,7 +88,7 @@ synchronized void onIceDataReceived(byte data[], int offset, int length) { private void faListener() { byte data[] = new byte [65536]; // 64KiB = UDP MTU, in practice due to ethernet frames being <= 1500 B, this is often not used - while (IceAdapter.running && IceAdapter.gameSession == gameSession) { + while (IceAdapter.isRunning() && IceAdapter.gameSession == gameSession) { try { DatagramPacket packet = new DatagramPacket(data, data.length); faSocket.receive(packet); diff --git a/ice-adapter/src/main/java/com/faforever/iceadapter/ice/PeerIceModule.java b/ice-adapter/src/main/java/com/faforever/iceadapter/ice/PeerIceModule.java index 6488809..0b52672 100644 --- a/ice-adapter/src/main/java/com/faforever/iceadapter/ice/PeerIceModule.java +++ b/ice-adapter/src/main/java/com/faforever/iceadapter/ice/PeerIceModule.java @@ -29,6 +29,22 @@ @Getter @Slf4j public class PeerIceModule { + private static boolean ALLOW_HOST = true; + private static boolean ALLOW_REFLEXIVE = true; + private static boolean ALLOW_RELAY = true; + + public static void setForceRelay(boolean forceRelay) { + if (forceRelay) { + ALLOW_HOST = false; + ALLOW_REFLEXIVE = false; + ALLOW_RELAY = true; + } else { + ALLOW_HOST = true; + ALLOW_REFLEXIVE = true; + ALLOW_RELAY = true; + } + } + private static final int MINIMUM_PORT = 6112; // PORT (range +1000) to be used by ICE for communicating, each peer needs a seperate port private static final long FORCE_SRFLX_RELAY_INTERVAL = @@ -66,7 +82,7 @@ public PeerIceModule(Peer peer) { */ private void setState(IceState newState) { this.iceState = newState; - RPCService.onIceConnectionStateChanged(IceAdapter.id, peer.getRemoteId(), iceState.getMessage()); + RPCService.onIceConnectionStateChanged(IceAdapter.getId(), peer.getRemoteId(), iceState.getMessage()); debug().peerStateChanged(this.peer); } @@ -153,13 +169,13 @@ a, new LongTermCredential(iceServer.getTurnUsername(), iceServer.getTurnCredenti int previousConnectivityAttempts = getConnectivityAttempsInThePast(FORCE_SRFLX_RELAY_INTERVAL); CandidatesMessage localCandidatesMessage = CandidateUtil.packCandidates( - IceAdapter.id, + IceAdapter.getId(), peer.getRemoteId(), agent, component, - previousConnectivityAttempts < FORCE_SRFLX_COUNT && IceAdapter.ALLOW_HOST, - previousConnectivityAttempts < FORCE_RELAY_COUNT && IceAdapter.ALLOW_REFLEXIVE, - IceAdapter.ALLOW_RELAY); + previousConnectivityAttempts < FORCE_SRFLX_COUNT && ALLOW_HOST, + previousConnectivityAttempts < FORCE_RELAY_COUNT && ALLOW_REFLEXIVE, + ALLOW_RELAY); log.debug( getLogPrefix() + "Sending own candidates to {}, offered candidates: {}", peer.getRemoteId(), @@ -188,7 +204,7 @@ a, new LongTermCredential(iceServer.getTurnUsername(), iceServer.getTurnCredenti private List getViableIceServers() { List allIceServers = GameSession.getIceServers(); - if (IceAdapter.PING_COUNT <= 0 || allIceServers.isEmpty()) { + if (IceAdapter.getPingCount() <= 0 || allIceServers.isEmpty()) { return allIceServers; } @@ -265,9 +281,9 @@ public synchronized void onIceMessageReceived(CandidatesMessage remoteCandidates agent, component, mediaStream, - previousConnectivityAttempts < FORCE_SRFLX_COUNT && IceAdapter.ALLOW_HOST, - previousConnectivityAttempts < FORCE_RELAY_COUNT && IceAdapter.ALLOW_REFLEXIVE, - IceAdapter.ALLOW_RELAY); + previousConnectivityAttempts < FORCE_SRFLX_COUNT && ALLOW_HOST, + previousConnectivityAttempts < FORCE_RELAY_COUNT && ALLOW_REFLEXIVE, + ALLOW_RELAY); startIce(); }) @@ -311,7 +327,7 @@ private void startIce() { // We are connected connected = true; - RPCService.onConnected(IceAdapter.id, peer.getRemoteId(), true); + RPCService.onConnected(IceAdapter.getId(), peer.getRemoteId(), true); setState(CONNECTED); if (component.getSelectedPair().getLocalCandidate().getType() == CandidateType.RELAYED_CANDIDATE) { @@ -355,7 +371,7 @@ public synchronized void onConnectionLost() { if (connected) { connected = false; log.warn(getLogPrefix() + "ICE connection has been lost for peer"); - RPCService.onConnected(IceAdapter.id, peer.getRemoteId(), false); + RPCService.onConnected(IceAdapter.getId(), peer.getRemoteId(), false); } setState(DISCONNECTED); @@ -456,7 +472,7 @@ public void listener() { byte[] data = new byte [65536]; // 64KiB = UDP MTU, in practice due to ethernet frames being <= 1500 B, this is often not used - while (IceAdapter.running && IceAdapter.gameSession == peer.getGameSession()) { + while (IceAdapter.isRunning() && IceAdapter.gameSession == peer.getGameSession()) { try { DatagramPacket packet = new DatagramPacket(data, data.length); localComponent diff --git a/ice-adapter/src/main/java/com/faforever/iceadapter/rpc/RPCHandler.java b/ice-adapter/src/main/java/com/faforever/iceadapter/rpc/RPCHandler.java index ba10f4d..e56a8b2 100644 --- a/ice-adapter/src/main/java/com/faforever/iceadapter/rpc/RPCHandler.java +++ b/ice-adapter/src/main/java/com/faforever/iceadapter/rpc/RPCHandler.java @@ -14,6 +14,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.ice4j.TransportAddress; @@ -26,13 +27,11 @@ * Handles calls from JsonRPC (the client) */ @Slf4j +@RequiredArgsConstructor public class RPCHandler { - private final ObjectMapper objectMapper = new ObjectMapper(); - - public RPCHandler() { - objectMapper.registerModule(new JavaTimeModule()); - } + private final ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule()); + private final int rpcPort; public void hostGame(String mapName) { IceAdapter.onHostGame(mapName); @@ -95,7 +94,7 @@ public void setIceServers(List> iceServers) { @SneakyThrows public String status() { IceStatus.IceGPGNetState gpgpnet = new IceStatus.IceGPGNetState( - IceAdapter.GPGNET_PORT, GPGNetServer.isConnected(), GPGNetServer.getGameStateString(), "-"); + GPGNetServer.getGpgnetPort(), GPGNetServer.isConnected(), GPGNetServer.getGameStateString(), "-"); List relays = new ArrayList<>(); GameSession gameSession = IceAdapter.gameSession; @@ -152,9 +151,10 @@ public String status() { .mapToInt(s -> s.getTurnAddresses().size() + s.getStunAddresses().size()) .sum(), - IceAdapter.LOBBY_PORT, + GPGNetServer.getLobbyPort(), GPGNetServer.lobbyInitMode.getName(), - new IceStatus.IceOptions(IceAdapter.id, IceAdapter.login, IceAdapter.RPC_PORT, IceAdapter.GPGNET_PORT), + new IceStatus.IceOptions( + IceAdapter.getId(), IceAdapter.getLogin(), rpcPort, GPGNetServer.getGpgnetPort()), gpgpnet, relays.toArray(new IceStatus.IceRelay[relays.size()])); diff --git a/ice-adapter/src/main/java/com/faforever/iceadapter/rpc/RPCService.java b/ice-adapter/src/main/java/com/faforever/iceadapter/rpc/RPCService.java index f481363..c9200e9 100644 --- a/ice-adapter/src/main/java/com/faforever/iceadapter/rpc/RPCService.java +++ b/ice-adapter/src/main/java/com/faforever/iceadapter/rpc/RPCService.java @@ -24,22 +24,16 @@ @Slf4j public class RPCService { - private static final ObjectMapper objectMapper = new ObjectMapper(); - + private static final ObjectMapper objectMapper = new ObjectMapper().registerModule(new JavaTimeModule()); private static TcpServer tcpServer; - private static RPCHandler rpcHandler; - private static volatile boolean skipRPCMessages = false; - static { - objectMapper.registerModule(new JavaTimeModule()); - } - - public static void init() { - log.info("Creating RPC server on port {}", IceAdapter.RPC_PORT); + public static void init(int port) { + Debug.RPC_PORT = port; + log.info("Creating RPC server on port {}", port); - rpcHandler = new RPCHandler(); - tcpServer = new TcpServer(IceAdapter.RPC_PORT, rpcHandler); + RPCHandler rpcHandler = new RPCHandler(port); + tcpServer = new TcpServer(port, rpcHandler); tcpServer.start(); debug().rpcStarted(tcpServer.getFirstPeer());