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 10, 2024
1 parent 38c1074 commit b1ba7c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 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

0 comments on commit b1ba7c2

Please sign in to comment.