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);
}
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;
}
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));
}
Aggregations