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);
}
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));
}
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(""));
}
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());
}
}
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;
}
Aggregations