Search in sources :

Example 1 with PlayerListing

use of games.strategy.engine.framework.message.PlayerListing in project triplea by triplea-game.

the class LauncherFactory method getLocalLaunchers.

/**
 * Creates a launcher for a single player local (no network) game.
 */
public static ILauncher getLocalLaunchers(final GameSelectorModel gameSelectorModel, final Collection<? extends PlayerCountrySelection> playerRows) {
    final Map<String, String> playerTypes = playerRows.stream().collect(Collectors.toMap(PlayerCountrySelection::getPlayerName, PlayerCountrySelection::getPlayerType));
    final Map<String, Boolean> playersEnabled = playerRows.stream().collect(Collectors.toMap(PlayerCountrySelection::getPlayerName, PlayerCountrySelection::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 new LocalLauncher(gameSelectorModel, new PlainRandomSource(), pl);
}
Also used : PlainRandomSource(games.strategy.engine.random.PlainRandomSource) PlayerListing(games.strategy.engine.framework.message.PlayerListing)

Example 2 with PlayerListing

use of games.strategy.engine.framework.message.PlayerListing in project triplea by triplea-game.

the class ClientModel method createClientMessenger.

boolean createClientMessenger(Component ui) {
    gameDataOnStartup = gameSelectorModel.getGameData();
    gameSelectorModel.setCanSelect(false);
    ui = JOptionPane.getFrameForComponent(ui);
    this.ui = ui;
    // load in the saved name!
    final ClientProps props = getProps(ui);
    if (props == null) {
        gameSelectorModel.setCanSelect(true);
        cancel();
        return false;
    }
    final String name = props.getName();
    logger.log(Level.FINE, "Client playing as:" + name);
    ClientSetting.PLAYER_NAME.save(name);
    ClientSetting.flush();
    final int port = props.getPort();
    if (port >= 65536 || port <= 0) {
        EventThreadJOptionPane.showMessageDialog(ui, "Invalid Port: " + port, "Error", JOptionPane.ERROR_MESSAGE);
        return false;
    }
    final String address = props.getHost();
    try {
        final String mac = MacFinder.getHashedMacAddress();
        messenger = new ClientMessenger(address, port, name, mac, objectStreamFactory, new ClientLogin(this.ui));
    } catch (final CouldNotLogInException e) {
        EventThreadJOptionPane.showMessageDialog(ui, e.getMessage());
        return false;
    } catch (final Exception ioe) {
        ioe.printStackTrace(System.out);
        EventThreadJOptionPane.showMessageDialog(ui, "Unable to connect:" + ioe.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        return false;
    }
    messenger.addErrorListener(this);
    final UnifiedMessenger unifiedMessenger = new UnifiedMessenger(messenger);
    channelMessenger = new ChannelMessenger(unifiedMessenger);
    remoteMessenger = new RemoteMessenger(unifiedMessenger);
    channelMessenger.registerChannelSubscriber(channelListener, IClientChannel.CHANNEL_NAME);
    chatPanel = new ChatPanel(messenger, channelMessenger, remoteMessenger, ServerModel.CHAT_NAME, Chat.ChatSoundProfile.GAME_CHATROOM);
    if (getIsServerHeadlessTest()) {
        gameSelectorModel.setClientModelForHostBots(this);
        ((ChatPanel) chatPanel).getChatMessagePanel().addServerMessage("Welcome to an automated dedicated host service (a host bot). " + "\nIf anyone disconnects, the autosave will be reloaded (a save might be loaded right now). " + "\nYou can get the current save, or you can load a save (only saves that it has the map for).");
    }
    remoteMessenger.registerRemote(observerWaitingToJoin, ServerModel.getObserverWaitingToStartName(messenger.getLocalNode()));
    // save this, it will be cleared later
    gameDataOnStartup = gameSelectorModel.getGameData();
    final IServerStartupRemote serverStartup = getServerStartup();
    final PlayerListing players = serverStartup.getPlayerListing();
    internalPlayerListingChanged(players);
    if (!serverStartup.isGameStarted(messenger.getLocalNode())) {
        remoteMessenger.unregisterRemote(ServerModel.getObserverWaitingToStartName(messenger.getLocalNode()));
    }
    gameSelectorModel.setIsHostHeadlessBot(hostIsHeadlessBot);
    return true;
}
Also used : RemoteMessenger(games.strategy.engine.message.RemoteMessenger) IRemoteMessenger(games.strategy.engine.message.IRemoteMessenger) UnifiedMessenger(games.strategy.engine.message.unifiedmessenger.UnifiedMessenger) CouldNotLogInException(games.strategy.net.CouldNotLogInException) IChatPanel(games.strategy.engine.chat.IChatPanel) ChatPanel(games.strategy.engine.chat.ChatPanel) IOException(java.io.IOException) CouldNotLogInException(games.strategy.net.CouldNotLogInException) IChannelMessenger(games.strategy.engine.message.IChannelMessenger) ChannelMessenger(games.strategy.engine.message.ChannelMessenger) PlayerListing(games.strategy.engine.framework.message.PlayerListing) ClientMessenger(games.strategy.net.ClientMessenger) IClientMessenger(games.strategy.net.IClientMessenger) ClientLogin(games.strategy.engine.framework.startup.login.ClientLogin)

Example 3 with PlayerListing

use of games.strategy.engine.framework.message.PlayerListing 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

PlayerListing (games.strategy.engine.framework.message.PlayerListing)3 ChatPanel (games.strategy.engine.chat.ChatPanel)1 IChatPanel (games.strategy.engine.chat.IChatPanel)1 LocalLauncher (games.strategy.engine.framework.startup.launcher.LocalLauncher)1 ClientLogin (games.strategy.engine.framework.startup.login.ClientLogin)1 ChannelMessenger (games.strategy.engine.message.ChannelMessenger)1 IChannelMessenger (games.strategy.engine.message.IChannelMessenger)1 IRemoteMessenger (games.strategy.engine.message.IRemoteMessenger)1 RemoteMessenger (games.strategy.engine.message.RemoteMessenger)1 UnifiedMessenger (games.strategy.engine.message.unifiedmessenger.UnifiedMessenger)1 IEmailSender (games.strategy.engine.pbem.IEmailSender)1 IForumPoster (games.strategy.engine.pbem.IForumPoster)1 IRemoteDiceServer (games.strategy.engine.random.IRemoteDiceServer)1 PbemDiceRoller (games.strategy.engine.random.PbemDiceRoller)1 PlainRandomSource (games.strategy.engine.random.PlainRandomSource)1 ClientMessenger (games.strategy.net.ClientMessenger)1 CouldNotLogInException (games.strategy.net.CouldNotLogInException)1 IClientMessenger (games.strategy.net.IClientMessenger)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1