Search in sources :

Example 1 with LobbyServerProperties

use of games.strategy.engine.lobby.client.login.LobbyServerProperties in project triplea by triplea-game.

the class MetaSetupPanel method connectToLobby.

private void connectToLobby() {
    final LobbyServerProperties lobbyServerProperties = new LobbyServerPropertiesFetcher().fetchLobbyServerProperties();
    final LobbyLogin login = new LobbyLogin(JOptionPane.getFrameForComponent(this), lobbyServerProperties);
    final LobbyClient client = login.login();
    if (client == null) {
        return;
    }
    final LobbyFrame lobbyFrame = new LobbyFrame(client, lobbyServerProperties);
    GameRunner.hideMainFrame();
    lobbyFrame.setVisible(true);
}
Also used : LobbyClient(games.strategy.engine.lobby.client.LobbyClient) LobbyServerProperties(games.strategy.engine.lobby.client.login.LobbyServerProperties) LobbyServerPropertiesFetcher(games.strategy.engine.config.client.LobbyServerPropertiesFetcher) LobbyFrame(games.strategy.engine.lobby.client.ui.LobbyFrame) LobbyLogin(games.strategy.engine.lobby.client.login.LobbyLogin)

Example 2 with LobbyServerProperties

use of games.strategy.engine.lobby.client.login.LobbyServerProperties in project triplea by triplea-game.

the class LobbyPropertyFileParserTest method parseWithSimpleCase.

/**
 * Just one set of values in a config file with no verson. The props we return should be a pretty
 * straight forward 1:1
 */
@Test
public void parseWithSimpleCase() throws Exception {
    final TestProps testProps = new TestProps();
    testProps.host = TestData.host;
    testProps.port = TestData.port;
    testProps.errorMessage = TestData.errorMessage;
    testProps.message = TestData.message;
    testProps.version = TestData.clientCurrentVersion;
    final File testFile = createTempFile(testProps);
    final LobbyServerProperties result = LobbyPropertyFileParser.parse(testFile, new Version(TestData.clientCurrentVersion));
    assertThat(result.host, is(TestData.host));
    assertThat(result.port, is(Integer.valueOf(TestData.port)));
    assertThat(result.serverMessage, is(TestData.message));
    assertThat(result.serverErrorMessage, is(TestData.errorMessage));
}
Also used : Version(games.strategy.util.Version) File(java.io.File) LobbyServerProperties(games.strategy.engine.lobby.client.login.LobbyServerProperties) Test(org.junit.jupiter.api.Test)

Example 3 with LobbyServerProperties

use of games.strategy.engine.lobby.client.login.LobbyServerProperties in project triplea by triplea-game.

the class LobbyPropertyFileParserTest method checkVersionSelection.

/**
 * YAML config has multple lobby configs depending on client version. Here we make sure the version checks
 * line up and we get the expected lobby config back.
 */
@Test
public void checkVersionSelection() throws Exception {
    final File testFile = createTempFile(testDataSet());
    final LobbyServerProperties result = LobbyPropertyFileParser.parse(testFile, new Version(TestData.clientCurrentVersion));
    assertThat(result.host, is(TestData.hostOther));
    assertThat(result.port, is(Integer.valueOf(TestData.portOther)));
    assertThat(result.serverMessage, is(""));
    assertThat(result.serverErrorMessage, is(""));
}
Also used : Version(games.strategy.util.Version) File(java.io.File) LobbyServerProperties(games.strategy.engine.lobby.client.login.LobbyServerProperties) Test(org.junit.jupiter.api.Test)

Example 4 with LobbyServerProperties

use of games.strategy.engine.lobby.client.login.LobbyServerProperties in project triplea by triplea-game.

the class LobbyServerPropertiesFetcher method getRemoteProperties.

private LobbyServerProperties getRemoteProperties() {
    final String lobbyPropsUrl = UrlConstants.LOBBY_PROPS.toString();
    final Version currentVersion = ClientContext.engineVersion();
    try {
        final LobbyServerProperties downloadedProps = downloadAndParseRemoteFile(lobbyPropsUrl, currentVersion, LobbyPropertyFileParser::parse);
        ClientSetting.LOBBY_LAST_USED_HOST.save(downloadedProps.host);
        ClientSetting.LOBBY_LAST_USED_PORT.save(downloadedProps.port);
        ClientSetting.flush();
        return downloadedProps;
    } catch (final IOException e) {
        if (!ClientSetting.LOBBY_LAST_USED_HOST.isSet()) {
            ClientLogger.logError(String.format("Failed to download lobby server property file from %s; " + "Please verify your internet connection and try again.", lobbyPropsUrl), e);
            throw new RuntimeException(e);
        }
        ClientLogger.logQuietly("Encountered an error while downloading lobby property file: " + lobbyPropsUrl + ", will attempt to connect to the lobby at its last known address. If this problem keeps happening, " + "you may be seeing network troubles, or the lobby may not be available.", e);
        // graceful recovery case, use the last lobby address we knew about
        return new LobbyServerProperties(ClientSetting.LOBBY_LAST_USED_HOST.value(), ClientSetting.LOBBY_LAST_USED_PORT.intValue());
    }
}
Also used : Version(games.strategy.util.Version) IOException(java.io.IOException) LobbyServerProperties(games.strategy.engine.lobby.client.login.LobbyServerProperties)

Example 5 with LobbyServerProperties

use of games.strategy.engine.lobby.client.login.LobbyServerProperties in project triplea by triplea-game.

the class LobbyServerPropertiesFetcher method downloadAndParseRemoteFile.

/**
 * @param lobbyPropFileUrl The taret URL to scrape for a lobby properties file.
 * @param currentVersion Our current engine version. The properties file can contain
 *        multiple listings for different versions.
 * @return Parsed LobbyServerProperties object from the data we found at the remote
 *         url.
 * @throws IOException Thrown if there is a failure doing the remote network fetching
 *         or IO problem once we downloaded the remote file to a temp file and are then
 *         reading it..
 */
@VisibleForTesting
LobbyServerProperties downloadAndParseRemoteFile(final String lobbyPropFileUrl, final Version currentVersion, final BiFunction<File, Version, LobbyServerProperties> propertyParser) throws IOException {
    final DownloadUtils.FileDownloadResult fileDownloadResult = fileDownloader.download(lobbyPropFileUrl);
    if (!fileDownloadResult.wasSuccess) {
        throw new IOException("Failed to download: " + lobbyPropFileUrl);
    }
    final LobbyServerProperties properties = propertyParser.apply(fileDownloadResult.downloadedFile, currentVersion);
    // delete file after it has been used. If there there was an IOException, the 'deleteOnExit' should
    // kick in and delete the file. (hence there is no try/catch/finally block here)
    fileDownloadResult.downloadedFile.delete();
    return properties;
}
Also used : DownloadUtils(games.strategy.engine.framework.map.download.DownloadUtils) IOException(java.io.IOException) LobbyServerProperties(games.strategy.engine.lobby.client.login.LobbyServerProperties) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

LobbyServerProperties (games.strategy.engine.lobby.client.login.LobbyServerProperties)5 Version (games.strategy.util.Version)3 File (java.io.File)2 IOException (java.io.IOException)2 Test (org.junit.jupiter.api.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 LobbyServerPropertiesFetcher (games.strategy.engine.config.client.LobbyServerPropertiesFetcher)1 DownloadUtils (games.strategy.engine.framework.map.download.DownloadUtils)1 LobbyClient (games.strategy.engine.lobby.client.LobbyClient)1 LobbyLogin (games.strategy.engine.lobby.client.login.LobbyLogin)1 LobbyFrame (games.strategy.engine.lobby.client.ui.LobbyFrame)1