Skip to content

Commit

Permalink
Inject gpgNetServer into RPCHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
Brutus5000 committed Dec 17, 2024
1 parent 9c29731 commit 5a20e88
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down Expand Up @@ -95,7 +96,7 @@ public void setIceServers(List<Map<String, Object>> iceServers) {
@SneakyThrows
public String status() {
IceStatus.IceGPGNetState gpgpnet = new IceStatus.IceGPGNetState(
GPGNetServer.getGpgnetPort(), GPGNetServer.isConnected(), GPGNetServer.getGameStateString(), "-");
gpgNetServer.getGpgnetPort(), gpgNetServer.isConnected(), gpgNetServer.getGameStateString(), "-");

List<IceStatus.IceRelay> relays = new ArrayList<>();
GameSession gameSession = IceAdapter.getGameSession();
Expand Down Expand Up @@ -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()]));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 5a20e88

Please sign in to comment.