Search in sources :

Example 1 with LOBBY_HOST

use of games.strategy.engine.framework.CliProperties.LOBBY_HOST 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;
    }
}
Also used : Observer(java.util.Observer) ClientMessenger(games.strategy.net.ClientMessenger) LOBBY_GAME_COMMENTS(games.strategy.engine.framework.CliProperties.LOBBY_GAME_COMMENTS) GUID(games.strategy.net.GUID) SERVER_PASSWORD(games.strategy.engine.framework.CliProperties.SERVER_PASSWORD) HashMap(java.util.HashMap) HeadlessGameServer(games.strategy.engine.framework.headlessGameServer.HeadlessGameServer) IConnectionLogin(games.strategy.net.IConnectionLogin) LobbyServer(games.strategy.engine.lobby.server.LobbyServer) MacFinder(games.strategy.net.MacFinder) IMessengerErrorListener(games.strategy.net.IMessengerErrorListener) SwingUtilities(javax.swing.SwingUtilities) Map(java.util.Map) IMessenger(games.strategy.net.IMessenger) GameDescription(games.strategy.engine.lobby.server.GameDescription) IConnectionChangeListener(games.strategy.net.IConnectionChangeListener) RemoteMessenger(games.strategy.engine.message.RemoteMessenger) ClientContext(games.strategy.engine.ClientContext) JComponent(javax.swing.JComponent) LobbyLoginValidator(games.strategy.engine.lobby.server.login.LobbyLoginValidator) INode(games.strategy.net.INode) Frame(java.awt.Frame) ILobbyGameController(games.strategy.engine.lobby.server.ILobbyGameController) LOBBY_HOST(games.strategy.engine.framework.CliProperties.LOBBY_HOST) GameStepListener(games.strategy.engine.data.events.GameStepListener) GameStatus(games.strategy.engine.lobby.server.GameDescription.GameStatus) Instant(java.time.Instant) JOptionPane(javax.swing.JOptionPane) GameRunner(games.strategy.engine.framework.GameRunner) RemoteHostUtils(games.strategy.engine.lobby.server.RemoteHostUtils) TRIPLEA_PORT(games.strategy.engine.framework.CliProperties.TRIPLEA_PORT) UnifiedMessenger(games.strategy.engine.message.unifiedmessenger.UnifiedMessenger) ClientLogger(games.strategy.debug.ClientLogger) GameSelectorModel(games.strategy.engine.framework.startup.mc.GameSelectorModel) IRemoteMessenger(games.strategy.engine.message.IRemoteMessenger) LOBBY_PORT(games.strategy.engine.framework.CliProperties.LOBBY_PORT) OpenFileUtility(games.strategy.net.OpenFileUtility) IServerMessenger(games.strategy.net.IServerMessenger) UrlConstants(games.strategy.triplea.UrlConstants) IGame(games.strategy.engine.framework.IGame) LOBBY_GAME_HOSTED_BY(games.strategy.engine.framework.CliProperties.LOBBY_GAME_HOSTED_BY) RemoteMessenger(games.strategy.engine.message.RemoteMessenger) IRemoteMessenger(games.strategy.engine.message.IRemoteMessenger) UnifiedMessenger(games.strategy.engine.message.unifiedmessenger.UnifiedMessenger) RemoteHostUtils(games.strategy.engine.lobby.server.RemoteHostUtils) HashMap(java.util.HashMap) Map(java.util.Map) IConnectionLogin(games.strategy.net.IConnectionLogin) ClientMessenger(games.strategy.net.ClientMessenger)

Aggregations

ClientLogger (games.strategy.debug.ClientLogger)1 ClientContext (games.strategy.engine.ClientContext)1 GameStepListener (games.strategy.engine.data.events.GameStepListener)1 LOBBY_GAME_COMMENTS (games.strategy.engine.framework.CliProperties.LOBBY_GAME_COMMENTS)1 LOBBY_GAME_HOSTED_BY (games.strategy.engine.framework.CliProperties.LOBBY_GAME_HOSTED_BY)1 LOBBY_HOST (games.strategy.engine.framework.CliProperties.LOBBY_HOST)1 LOBBY_PORT (games.strategy.engine.framework.CliProperties.LOBBY_PORT)1 SERVER_PASSWORD (games.strategy.engine.framework.CliProperties.SERVER_PASSWORD)1 TRIPLEA_PORT (games.strategy.engine.framework.CliProperties.TRIPLEA_PORT)1 GameRunner (games.strategy.engine.framework.GameRunner)1 IGame (games.strategy.engine.framework.IGame)1 HeadlessGameServer (games.strategy.engine.framework.headlessGameServer.HeadlessGameServer)1 GameSelectorModel (games.strategy.engine.framework.startup.mc.GameSelectorModel)1 GameDescription (games.strategy.engine.lobby.server.GameDescription)1 GameStatus (games.strategy.engine.lobby.server.GameDescription.GameStatus)1 ILobbyGameController (games.strategy.engine.lobby.server.ILobbyGameController)1 LobbyServer (games.strategy.engine.lobby.server.LobbyServer)1 RemoteHostUtils (games.strategy.engine.lobby.server.RemoteHostUtils)1 LobbyLoginValidator (games.strategy.engine.lobby.server.login.LobbyLoginValidator)1 IRemoteMessenger (games.strategy.engine.message.IRemoteMessenger)1