Search in sources :

Example 16 with Version

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());
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) GameData(games.strategy.engine.data.GameData) GameEngineVersion(games.strategy.engine.GameEngineVersion) Version(games.strategy.util.Version) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 17 with Version

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);
}
Also used : Version(games.strategy.util.Version) GameEngineVersion(games.strategy.engine.GameEngineVersion) GameDescription(games.strategy.engine.lobby.server.GameDescription)

Example 18 with Version

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();
}
Also used : SwingComponents(games.strategy.ui.SwingComponents) Collection(java.util.Collection) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Collectors(java.util.stream.Collectors) File(java.io.File) Objects(java.util.Objects) ClientLogger(games.strategy.debug.ClientLogger) ResourceLoader(games.strategy.triplea.ResourceLoader) List(java.util.List) ClientFileSystemHelper(games.strategy.engine.ClientFileSystemHelper) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ClientSetting(games.strategy.triplea.settings.ClientSetting) ClientContext(games.strategy.engine.ClientContext) Version(games.strategy.util.Version) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Version(games.strategy.util.Version)

Example 19 with Version

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());
    }
}
Also used : Version(games.strategy.util.Version) IOException(java.io.IOException) LobbyServerProperties(games.strategy.engine.lobby.client.login.LobbyServerProperties)

Aggregations

Version (games.strategy.util.Version)19 Test (org.junit.jupiter.api.Test)7 GameEngineVersion (games.strategy.engine.GameEngineVersion)5 LobbyServerProperties (games.strategy.engine.lobby.client.login.LobbyServerProperties)3 File (java.io.File)3 IOException (java.io.IOException)2 List (java.util.List)2 JSONArray (com.github.openjson.JSONArray)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ClientLogger (games.strategy.debug.ClientLogger)1 ClientContext (games.strategy.engine.ClientContext)1 ClientFileSystemHelper (games.strategy.engine.ClientFileSystemHelper)1 GameData (games.strategy.engine.data.GameData)1 GameDescription (games.strategy.engine.lobby.server.GameDescription)1 ResourceLoader (games.strategy.triplea.ResourceLoader)1 ClientSetting (games.strategy.triplea.settings.ClientSetting)1 SwingComponents (games.strategy.ui.SwingComponents)1 ObjectInputStream (java.io.ObjectInputStream)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1