Search in sources :

Example 1 with IForumPoster

use of games.strategy.engine.pbem.IForumPoster in project triplea by triplea-game.

the class PbemSetupPanel method postStartGame.

@Override
public void postStartGame() {
    // // store the dice server
    final GameData data = gameSelectorModel.getGameData();
    data.getProperties().set(DICE_ROLLER, diceServerEditor.getBean());
    // store the Turn Summary Poster
    final IForumPoster poster = (IForumPoster) forumPosterEditor.getBean();
    if (poster != null) {
        // clone the poster, the remove sensitive info, and put the clone into the game data
        // this was the sensitive info is not stored in the save game, but the user cache still has the password
        final IForumPoster summaryPoster = poster.doClone();
        summaryPoster.clearSensitiveInfo();
        data.getProperties().set(PBEMMessagePoster.FORUM_POSTER_PROP_NAME, summaryPoster);
    }
    // store the email poster
    IEmailSender sender = (IEmailSender) emailSenderEditor.getBean();
    if (sender != null) {
        // create a clone, delete the sensitive information in the clone, and use it in the game
        // the locally cached version still has the password so the user doesn't have to enter it every time
        sender = sender.clone();
        sender.clearSensitiveInfo();
        data.getProperties().set(PBEMMessagePoster.EMAIL_SENDER_PROP_NAME, sender);
    }
    // store whether we are a pbem game or not, whether we are capable of posting a game save
    if (poster != null || sender != null) {
        data.getProperties().set(PBEMMessagePoster.PBEM_GAME_PROP_NAME, true);
    }
}
Also used : GameData(games.strategy.engine.data.GameData) IEmailSender(games.strategy.engine.pbem.IEmailSender) IForumPoster(games.strategy.engine.pbem.IForumPoster)

Example 2 with IForumPoster

use of games.strategy.engine.pbem.IForumPoster in project triplea by triplea-game.

the class PbemSetupPanel method loadForumPosters.

/**
 * Load the Forum poster that are stored in the GameData, and select it in the list.
 * Sensitive information such as passwords are not stored in save games, so the are loaded from the LocalBeanCache
 *
 * @param data the game data
 */
private void loadForumPosters(final GameData data) {
    // get the forum posters,
    final List<IForumPoster> forumPosters = new ArrayList<>();
    forumPosters.add(useCacheIfAvailable(new NullForumPoster()));
    forumPosters.add(useCacheIfAvailable(new AxisAndAlliesForumPoster()));
    forumPosters.add(useCacheIfAvailable(new TripleAForumPoster()));
    forumPosterEditor.setBeans(forumPosters);
    // now get the poster stored in the save game
    final IForumPoster forumPoster = (IForumPoster) data.getProperties().get(PBEMMessagePoster.FORUM_POSTER_PROP_NAME);
    if (forumPoster != null) {
        // if we have a cached version, use the credentials from this, as each player has different forum login
        final IForumPoster cached = (IForumPoster) LocalBeanCache.INSTANCE.getSerializable(forumPoster.getClass().getCanonicalName());
        if (cached != null) {
            forumPoster.setUsername(cached.getUsername());
            forumPoster.setPassword(cached.getPassword());
            forumPoster.setCredentialsSaved(cached.areCredentialsSaved());
        }
        forumPosterEditor.setSelectedBean(forumPoster);
    }
}
Also used : AxisAndAlliesForumPoster(games.strategy.triplea.pbem.AxisAndAlliesForumPoster) NullForumPoster(games.strategy.engine.pbem.NullForumPoster) ArrayList(java.util.ArrayList) IForumPoster(games.strategy.engine.pbem.IForumPoster) TripleAForumPoster(games.strategy.engine.pbem.TripleAForumPoster)

Example 3 with IForumPoster

use of games.strategy.engine.pbem.IForumPoster in project triplea by triplea-game.

the class ForumPosterEditor method testForum.

/**
 * Tests the Forum poster.
 */
void testForum() {
    final IForumPoster poster = (IForumPoster) getBean();
    final ProgressWindow progressWindow = GameRunner.newProgressWindow(poster.getTestMessage());
    progressWindow.setVisible(true);
    // start a background thread
    new Thread(() -> {
        if (poster.getIncludeSaveGame()) {
            try {
                final File f = File.createTempFile("123", "test");
                f.deleteOnExit();
                /*
           * For .txt use this:
           * final FileOutputStream fout = new FileOutputStream(f);
           * fout.write("Test upload".getBytes());
           * fout.close();
           * poster.addSaveGame(f, "test.txt");
           */
                // For .jpg use this:
                final BufferedImage image = new BufferedImage(130, 40, BufferedImage.TYPE_INT_RGB);
                final Graphics g = image.getGraphics();
                g.drawString("Testing file upload", 10, 20);
                try {
                    ImageIO.write(image, "jpg", f);
                } catch (final IOException e) {
                // ignore
                }
                poster.addSaveGame(f, "Test.jpg");
            } catch (final IOException e) {
            // ignore
            }
        }
        poster.postTurnSummary("Test summary from TripleA, engine version: " + ClientContext.engineVersion() + ", time: " + TimeManager.getLocalizedTime(), "Testing Forum poster");
        progressWindow.setVisible(false);
        // now that we have a result, marshall it back unto the swing thread
        SwingUtilities.invokeLater(() -> GameRunner.showMessageDialog(bean.getTurnSummaryRef(), GameRunner.Title.of("Test Turn Summary Post"), JOptionPane.INFORMATION_MESSAGE));
    }).start();
}
Also used : Graphics(java.awt.Graphics) ProgressWindow(games.strategy.ui.ProgressWindow) IOException(java.io.IOException) IForumPoster(games.strategy.engine.pbem.IForumPoster) File(java.io.File) BufferedImage(java.awt.image.BufferedImage)

Example 4 with IForumPoster

use of games.strategy.engine.pbem.IForumPoster in project triplea by triplea-game.

the class PbemSetupPanel method getLauncher.

/**
 * Called when the user hits play.
 */
@Override
public Optional<ILauncher> getLauncher() {
    // update local cache and write to disk before game starts
    final IForumPoster poster = (IForumPoster) forumPosterEditor.getBean();
    if (poster != null) {
        LocalBeanCache.INSTANCE.storeSerializable(poster.getClass().getCanonicalName(), poster);
    }
    final IEmailSender sender = (IEmailSender) emailSenderEditor.getBean();
    if (sender != null) {
        LocalBeanCache.INSTANCE.storeSerializable(sender.getClass().getCanonicalName(), sender);
    }
    final IRemoteDiceServer server = (IRemoteDiceServer) diceServerEditor.getBean();
    LocalBeanCache.INSTANCE.storeSerializable(server.getDisplayName(), server);
    LocalBeanCache.INSTANCE.writeToDisk();
    // create local launcher
    final String gameUuid = (String) gameSelectorModel.getGameData().getProperties().get(GameData.GAME_UUID);
    final PbemDiceRoller randomSource = new PbemDiceRoller((IRemoteDiceServer) diceServerEditor.getBean(), gameUuid);
    final Map<String, String> playerTypes = new HashMap<>();
    final Map<String, Boolean> playersEnabled = new HashMap<>();
    for (final PlayerSelectorRow player : this.playerTypes) {
        playerTypes.put(player.getPlayerName(), player.getPlayerType());
        playersEnabled.put(player.getPlayerName(), player.isPlayerEnabled());
    }
    // we don't need the playerToNode list, the
    // disable-able players, or the alliances
    // list, for a local game
    final PlayerListing pl = new PlayerListing(null, playersEnabled, playerTypes, gameSelectorModel.getGameData().getGameVersion(), gameSelectorModel.getGameName(), gameSelectorModel.getGameRound(), null, null);
    return Optional.of(new LocalLauncher(gameSelectorModel, randomSource, pl));
}
Also used : LocalLauncher(games.strategy.engine.framework.startup.launcher.LocalLauncher) HashMap(java.util.HashMap) IEmailSender(games.strategy.engine.pbem.IEmailSender) PlayerListing(games.strategy.engine.framework.message.PlayerListing) IForumPoster(games.strategy.engine.pbem.IForumPoster) PbemDiceRoller(games.strategy.engine.random.PbemDiceRoller) IRemoteDiceServer(games.strategy.engine.random.IRemoteDiceServer)

Aggregations

IForumPoster (games.strategy.engine.pbem.IForumPoster)4 IEmailSender (games.strategy.engine.pbem.IEmailSender)2 GameData (games.strategy.engine.data.GameData)1 PlayerListing (games.strategy.engine.framework.message.PlayerListing)1 LocalLauncher (games.strategy.engine.framework.startup.launcher.LocalLauncher)1 NullForumPoster (games.strategy.engine.pbem.NullForumPoster)1 TripleAForumPoster (games.strategy.engine.pbem.TripleAForumPoster)1 IRemoteDiceServer (games.strategy.engine.random.IRemoteDiceServer)1 PbemDiceRoller (games.strategy.engine.random.PbemDiceRoller)1 AxisAndAlliesForumPoster (games.strategy.triplea.pbem.AxisAndAlliesForumPoster)1 ProgressWindow (games.strategy.ui.ProgressWindow)1 Graphics (java.awt.Graphics)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1