use of games.strategy.engine.chat.ChatPanel 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.chat.ChatPanel in project triplea by triplea-game.
the class ServerModel method createServerMessenger.
/**
* UI can be null. We use it as the parent for message dialogs we show.
* If you have a component displayed, use it.
*/
boolean createServerMessenger(@Nullable final Component ui, @Nonnull final ServerConnectionProps props) {
this.ui = (ui == null) ? null : JOptionPane.getFrameForComponent(ui);
try {
serverMessenger = new ServerMessenger(props.getName(), props.getPort(), objectStreamFactory);
final ClientLoginValidator clientLoginValidator = new ClientLoginValidator(serverMessenger);
clientLoginValidator.setGamePassword(props.getPassword());
serverMessenger.setLoginValidator(clientLoginValidator);
serverMessenger.addErrorListener(this);
serverMessenger.addConnectionChangeListener(this);
final UnifiedMessenger unifiedMessenger = new UnifiedMessenger(serverMessenger);
remoteMessenger = new RemoteMessenger(unifiedMessenger);
remoteMessenger.registerRemote(serverStartupRemote, SERVER_REMOTE_NAME);
channelMessenger = new ChannelMessenger(unifiedMessenger);
final NullModeratorController moderatorController = new NullModeratorController(serverMessenger, null);
moderatorController.register(remoteMessenger);
chatController = new ChatController(CHAT_NAME, serverMessenger, remoteMessenger, channelMessenger, moderatorController);
if (ui == null && headless) {
chatPanel = new HeadlessChat(serverMessenger, channelMessenger, remoteMessenger, CHAT_NAME, Chat.ChatSoundProfile.GAME_CHATROOM);
} else {
chatPanel = new ChatPanel(serverMessenger, channelMessenger, remoteMessenger, CHAT_NAME, Chat.ChatSoundProfile.GAME_CHATROOM);
}
serverMessenger.setAcceptNewConnections(true);
gameDataChanged();
return true;
} catch (final IOException ioe) {
ioe.printStackTrace(System.out);
if (headless) {
System.out.println("Unable to create server socket:" + ioe.getMessage());
} else {
JOptionPane.showMessageDialog(ui, "Unable to create server socket:" + ioe.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
return false;
}
}
Aggregations