use of games.strategy.engine.lobby.server.RemoteHostUtils in project triplea by triplea-game.
the class InGameLobbyWatcher method newInGameLobbyWatcher.
/**
* Reads SystemProperties to see if we should connect to a lobby server
*
* <p>
* After creation, those properties are cleared, since we should watch the first start game.
* </p>
*
* @return null if no watcher should be created
*/
public static InGameLobbyWatcher newInGameLobbyWatcher(final IServerMessenger gameMessenger, final JComponent parent, final InGameLobbyWatcher oldWatcher) {
final String host = System.getProperty(LOBBY_HOST);
final String port = System.getProperty(LOBBY_PORT);
final String hostedBy = System.getProperty(LOBBY_GAME_HOSTED_BY);
if (host == null || port == null) {
return null;
}
// clear the properties
System.clearProperty(LOBBY_HOST);
System.clearProperty(LOBBY_PORT);
System.clearProperty(LOBBY_GAME_HOSTED_BY);
// add them as temporary properties (in case we load an old savegame and need them again)
System.setProperty(LOBBY_HOST + GameRunner.OLD_EXTENSION, host);
System.setProperty(LOBBY_PORT + GameRunner.OLD_EXTENSION, port);
System.setProperty(LOBBY_GAME_HOSTED_BY + GameRunner.OLD_EXTENSION, hostedBy);
final IConnectionLogin login = challengeProperties -> {
final Map<String, String> properties = new HashMap<>();
properties.put(LobbyLoginValidator.ANONYMOUS_LOGIN, Boolean.TRUE.toString());
properties.put(LobbyLoginValidator.LOBBY_VERSION, LobbyServer.LOBBY_VERSION.toString());
properties.put(LobbyLoginValidator.LOBBY_WATCHER_LOGIN, Boolean.TRUE.toString());
return properties;
};
try {
System.out.println("host:" + host + " port:" + port);
final String mac = MacFinder.getHashedMacAddress();
final ClientMessenger messenger = new ClientMessenger(host, Integer.parseInt(port), getRealName(hostedBy) + "_" + LOBBY_WATCHER_NAME, mac, login);
final UnifiedMessenger um = new UnifiedMessenger(messenger);
final RemoteMessenger rm = new RemoteMessenger(um);
final RemoteHostUtils rhu = new RemoteHostUtils(messenger.getServerNode(), gameMessenger);
rm.registerRemote(rhu, RemoteHostUtils.getRemoteHostUtilsName(um.getLocalNode()));
return new InGameLobbyWatcher(messenger, rm, gameMessenger, parent, oldWatcher);
} catch (final Exception e) {
ClientLogger.logQuietly("Failed to create in-game lobby watcher", e);
return null;
}
}
Aggregations