From 43ddc39c5ffc6fe44fff440a3067766569303450 Mon Sep 17 00:00:00 2001 From: Brutus5000 Date: Tue, 10 Dec 2024 20:31:27 +0100 Subject: [PATCH] Inject gpgNetServer into RPCHandler --- .../com/faforever/iceadapter/gpgnet/GPGNetServer.java | 6 ++---- .../java/com/faforever/iceadapter/rpc/RPCHandler.java | 11 ++++++----- .../java/com/faforever/iceadapter/rpc/RPCService.java | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) 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 f10036f..e442fc2 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 @@ -18,6 +18,7 @@ import java.util.concurrent.locks.ReentrantLock; import java.util.stream.Collectors; import lombok.Getter; +import lombok.Setter; import lombok.extern.slf4j.Slf4j; @Slf4j @@ -40,16 +41,13 @@ public void sendToGpgNet(String header, Object... args) { gpgNetClient.getLobbyFuture().thenRun(() -> gpgNetClient.sendGpgnetMessage(header, args))); } + @Setter private volatile LobbyInitMode lobbyInitMode = LobbyInitMode.NORMAL; public static LobbyInitMode getLobbyInitMode() { return INSTANCE.lobbyInitMode; } - public static void setLobbyInitMode(LobbyInitMode mode) { - INSTANCE.lobbyInitMode = mode; - } - public void init(int gpgnetPort, int lobbyPort, RPCService rpcService) { INSTANCE = this; this.rpcService = rpcService; 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 393744e..d3f8c7a 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 @@ -37,6 +37,7 @@ public class RPCHandler { private final Lock lockStatus = new ReentrantLock(); private final int rpcPort; private final FafRpcCallbacks callbacks; + private final GPGNetServer gpgNetServer; public void hostGame(String mapName) { callbacks.onHostGame(mapName); @@ -55,7 +56,7 @@ public void disconnectFromPeer(long remotePlayerId) { } public void setLobbyInitMode(String lobbyInitMode) { - GPGNetServer.setLobbyInitMode(LobbyInitMode.getByName(lobbyInitMode)); + gpgNetServer.setLobbyInitMode(LobbyInitMode.getByName(lobbyInitMode)); log.debug("LobbyInitMode set to {}", lobbyInitMode); } @@ -95,7 +96,7 @@ public void setIceServers(List> iceServers) { @SneakyThrows public String status() { IceStatus.IceGPGNetState gpgpnet = new IceStatus.IceGPGNetState( - GPGNetServer.getGpgnetPort(), GPGNetServer.isConnected(), GPGNetServer.getGameStateString(), "-"); + gpgNetServer.getGpgnetPort(), gpgNetServer.isConnected(), gpgNetServer.getGameStateString(), "-"); List relays = new ArrayList<>(); GameSession gameSession = IceAdapter.getGameSession(); @@ -155,10 +156,10 @@ public String status() { .mapToInt(s -> s.getTurnAddresses().size() + s.getStunAddresses().size()) .sum(), - GPGNetServer.getLobbyPort(), - GPGNetServer.getLobbyInitMode().getName(), + gpgNetServer.getLobbyPort(), + gpgNetServer.getLobbyInitMode().getName(), new IceStatus.IceOptions( - IceAdapter.getId(), IceAdapter.getLogin(), rpcPort, GPGNetServer.getGpgnetPort()), + 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 6931fbd..f81748a 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 @@ -31,7 +31,7 @@ public void init(int port, GPGNetServer gpgNetServer, FafRpcCallbacks callbacks) Debug.RPC_PORT = port; log.info("Creating RPC server on port {}", port); - RPCHandler rpcHandler = new RPCHandler(port, callbacks); + RPCHandler rpcHandler = new RPCHandler(port, callbacks, gpgNetServer); tcpServer = new TcpServer(port, rpcHandler); tcpServer.start();