Search in sources :

Example 1 with HeadlessServerMessenger

use of games.strategy.net.HeadlessServerMessenger in project triplea by triplea-game.

the class LocalLauncher method launchInNewThread.

@Override
protected void launchInNewThread(final Component parent) {
    Exception exceptionLoadingGame = null;
    ServerGame game = null;
    try {
        gameData.doPreGameStartDataModifications(playerListing);
        final Messengers messengers = new Messengers(new HeadlessServerMessenger());
        final Set<IGamePlayer> gamePlayers = gameData.getGameLoader().createPlayers(playerListing.getLocalPlayerTypes());
        game = new ServerGame(gameData, gamePlayers, new HashMap<>(), messengers);
        game.setRandomSource(randomSource);
        // for debugging, we can use a scripted random source
        if (ScriptedRandomSource.useScriptedRandom()) {
            game.setRandomSource(new ScriptedRandomSource());
        }
        gameData.getGameLoader().startGame(game, gamePlayers, headless);
    } catch (final MapNotFoundException e) {
        exceptionLoadingGame = e;
    } catch (final Exception ex) {
        ClientLogger.logQuietly("Failed to start game", ex);
        exceptionLoadingGame = ex;
    } finally {
        gameLoadingWindow.doneWait();
    }
    try {
        if (exceptionLoadingGame == null) {
            game.startGame();
        }
    } finally {
        // todo(kg), this does not occur on the swing thread, and this notifies setupPanel observers
        // having an oddball issue with the zip stream being closed while parsing to load default game. might be caused
        // by closing of stream while unloading map resources.
        Interruptibles.sleep(100);
        gameSelectorModel.loadDefaultGameNewThread();
        SwingUtilities.invokeLater(() -> JOptionPane.getFrameForComponent(parent).setVisible(true));
    }
}
Also used : IGamePlayer(games.strategy.engine.gamePlayer.IGamePlayer) Messengers(games.strategy.net.Messengers) ServerGame(games.strategy.engine.framework.ServerGame) HashMap(java.util.HashMap) HeadlessServerMessenger(games.strategy.net.HeadlessServerMessenger) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource)

Aggregations

ServerGame (games.strategy.engine.framework.ServerGame)1 IGamePlayer (games.strategy.engine.gamePlayer.IGamePlayer)1 ScriptedRandomSource (games.strategy.engine.random.ScriptedRandomSource)1 HeadlessServerMessenger (games.strategy.net.HeadlessServerMessenger)1 Messengers (games.strategy.net.Messengers)1 HashMap (java.util.HashMap)1