use of games.strategy.engine.message.unifiedmessenger.UnifiedMessenger 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