Search in sources :

Example 1 with IEmailSender

use of games.strategy.engine.pbem.IEmailSender 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 IEmailSender

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

the class PbemSetupPanel method loadEmailSender.

/**
 * Configures the list of Email senders. If the game was saved we use this email sender.
 * Since passwords are not stored in save games, the LocalBeanCache is checked
 *
 * @param data
 *        the game data
 */
private void loadEmailSender(final GameData data) {
    // The list of email, either loaded from cache or created
    final List<IEmailSender> emailSenders = new ArrayList<>();
    emailSenders.add(useCacheIfAvailable(new NullEmailSender()));
    emailSenders.add(useCacheIfAvailable(new GmailEmailSender()));
    emailSenders.add(useCacheIfAvailable(new HotmailEmailSender()));
    emailSenders.add(useCacheIfAvailable(new GenericEmailSender()));
    emailSenderEditor.setBeans(emailSenders);
    // now get the sender from the save game, update it with credentials from the cache, and set it
    final IEmailSender sender = (IEmailSender) data.getProperties().get(PBEMMessagePoster.EMAIL_SENDER_PROP_NAME);
    if (sender != null) {
        final IEmailSender cached = (IEmailSender) LocalBeanCache.INSTANCE.getSerializable(sender.getClass().getCanonicalName());
        if (cached != null) {
            sender.setUserName(cached.getUserName());
            sender.setPassword(cached.getPassword());
            sender.setCredentialsSaved(cached.areCredentialsSaved());
        }
        emailSenderEditor.setSelectedBean(sender);
    }
}
Also used : GmailEmailSender(games.strategy.engine.pbem.GmailEmailSender) NullEmailSender(games.strategy.engine.pbem.NullEmailSender) IEmailSender(games.strategy.engine.pbem.IEmailSender) ArrayList(java.util.ArrayList) HotmailEmailSender(games.strategy.engine.pbem.HotmailEmailSender) GenericEmailSender(games.strategy.engine.pbem.GenericEmailSender)

Example 3 with IEmailSender

use of games.strategy.engine.pbem.IEmailSender 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

IEmailSender (games.strategy.engine.pbem.IEmailSender)3 IForumPoster (games.strategy.engine.pbem.IForumPoster)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 GenericEmailSender (games.strategy.engine.pbem.GenericEmailSender)1 GmailEmailSender (games.strategy.engine.pbem.GmailEmailSender)1 HotmailEmailSender (games.strategy.engine.pbem.HotmailEmailSender)1 NullEmailSender (games.strategy.engine.pbem.NullEmailSender)1 IRemoteDiceServer (games.strategy.engine.random.IRemoteDiceServer)1 PbemDiceRoller (games.strategy.engine.random.PbemDiceRoller)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1