use of games.strategy.util.Version in project triplea by triplea-game.
the class GameDataManager method loadGame.
/**
* Loads game data from the specified stream.
*
* @param is The stream from which the game data will be loaded. The caller is responsible for closing this stream; it
* will not be closed when this method returns.
*
* @return The loaded game data.
*
* @throws IOException If an error occurs while loading the game.
*/
public static GameData loadGame(final InputStream is) throws IOException {
checkNotNull(is);
final ObjectInputStream input = new ObjectInputStream(new GZIPInputStream(is));
try {
final Version readVersion = (Version) input.readObject();
final boolean headless = HeadlessGameServer.headless();
if (!GameEngineVersion.of(ClientContext.engineVersion()).isCompatibleWithEngineVersion(readVersion)) {
// a hack for now, but a headless server should not try to open any savegame that is not its version
if (headless) {
final String message = "Incompatible game save, we are: " + ClientContext.engineVersion() + " Trying to load game created with: " + readVersion;
HeadlessGameServer.sendChat(message);
System.out.println(message);
return null;
}
final String error = "Incompatible engine versions. We are: " + ClientContext.engineVersion() + " . Trying to load game created with: " + readVersion + "\nTo download the latest version of TripleA, Please visit " + UrlConstants.LATEST_GAME_DOWNLOAD_WEBSITE;
throw new IOException(error);
} else if (!headless && readVersion.isGreaterThan(ClientContext.engineVersion())) {
// we can still load it because our engine is compatible, however this save was made by a
// newer engine, so prompt the user to upgrade
final String messageString = "Your TripleA engine is OUT OF DATE. This save was made by a newer version of TripleA." + "\nHowever, because the first 3 version numbers are the same as your current version, we can " + "still open the savegame." + "\n\nThis TripleA engine is version " + ClientContext.engineVersion().toStringFull() + " and you are trying to open a savegame made with version " + readVersion.toStringFull() + "\n\nTo download the latest version of TripleA, Please visit " + UrlConstants.LATEST_GAME_DOWNLOAD_WEBSITE + "\n\nIt is recommended that you upgrade to the latest version of TripleA before playing this " + "savegame." + "\n\nDo you wish to continue and open this save with your current 'old' version?";
final int answer = JOptionPane.showConfirmDialog(null, messageString, "Open Newer Save Game?", JOptionPane.YES_NO_OPTION);
if (answer != JOptionPane.YES_OPTION) {
return null;
}
}
final GameData data = (GameData) input.readObject();
loadDelegates(input, data);
data.postDeSerialize();
return data;
} catch (final ClassNotFoundException cnfe) {
throw new IOException(cnfe.getMessage());
}
}
use of games.strategy.util.Version in project triplea by triplea-game.
the class GameRunner method joinGame.
public static void joinGame(final GameDescription description, final Messengers messengers, final Container parent) {
final GameDescription.GameStatus status = description.getStatus();
if (GameDescription.GameStatus.LAUNCHING == status) {
return;
}
final Version engineVersionOfGameToJoin = new Version(description.getEngineVersion());
final String newClassPath = null;
if (!GameEngineVersion.of(ClientContext.engineVersion()).isCompatibleWithEngineVersion(engineVersionOfGameToJoin)) {
JOptionPane.showMessageDialog(parent, "Host is using version " + engineVersionOfGameToJoin.toStringFull() + ". You need to have a compatible engine version in order to join this game.", "Incompatible TripleA engine", JOptionPane.ERROR_MESSAGE);
return;
}
joinGame(description.getPort(), description.getHostedBy().getAddress().getHostAddress(), newClassPath, messengers);
}
use of games.strategy.util.Version in project triplea by triplea-game.
the class MapDownloadController method isMapOutOfDate.
private static boolean isMapOutOfDate(final DownloadFileDescription download, final DownloadedMaps downloadedMaps) {
final Optional<Version> latestVersion = Optional.ofNullable(download.getVersion());
final Optional<Version> downloadedVersion = getDownloadedVersion(download.getMapName(), downloadedMaps);
final AtomicBoolean mapOutOfDate = new AtomicBoolean(false);
latestVersion.ifPresent(latest -> downloadedVersion.ifPresent(downloaded -> mapOutOfDate.set(latest.isGreaterThan(downloaded))));
return mapOutOfDate.get();
}
use of games.strategy.util.Version 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());
}
}
Aggregations