Search in sources :

Example 1 with IRCID

use of org.eclipse.ecf.internal.provider.irc.identity.IRCID in project ecf by eclipse.

the class IRCConnectWizard method performFinish.

public boolean performFinish() {
    final String connectID = page.getConnectID();
    final String password = page.getPassword();
    connectContext = ConnectContextFactory.createPasswordConnectContext(password);
    page.saveComboText();
    try {
        targetID = IDFactory.getDefault().createID(container.getConnectNamespace(), connectID);
    } catch (final IDCreateException e) {
        new IDCreateErrorDialog(null, connectID, e).open();
        return false;
    }
    final IChatRoomManager manager = (IChatRoomManager) this.container.getAdapter(IChatRoomManager.class);
    final IRCUI ui = new IRCUI(this.container, manager, null);
    ui.showForTarget(targetID);
    // If it's not already connected, then we connect this new container
    if (!ui.isContainerConnected()) {
        page.saveComboItems();
        // bug 274613, we need to remove the extra autojoin channel bits
        IRCID id = (IRCID) targetID;
        // start with user, then host, then port, abc@irc.freenode.net:6667
        StringBuffer buffer = new StringBuffer(id.getUsername());
        buffer.append('@').append(id.getHost());
        buffer.append(':').append(id.getPort());
        // create a truncated ID instance for the container to connect to
        id = (IRCID) container.getConnectNamespace().createInstance(new Object[] { buffer.toString() });
        new AsynchContainerConnectAction(container, id, connectContext, null, new Runnable() {

            public void run() {
                cachePassword(page.getPasswordKeyFromUserName(connectID), password);
            }
        }).run();
    }
    return true;
}
Also used : IDCreateErrorDialog(org.eclipse.ecf.ui.dialogs.IDCreateErrorDialog) AsynchContainerConnectAction(org.eclipse.ecf.ui.actions.AsynchContainerConnectAction) IChatRoomManager(org.eclipse.ecf.presence.chatroom.IChatRoomManager) IRCID(org.eclipse.ecf.internal.provider.irc.identity.IRCID)

Example 2 with IRCID

use of org.eclipse.ecf.internal.provider.irc.identity.IRCID in project ecf by eclipse.

the class IRCRootContainer method connect.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ecf.core.IContainer#connect(org.eclipse.ecf.core.identity.ID,
	 * org.eclipse.ecf.core.security.IConnectContext)
	 */
public void connect(ID connectID, IConnectContext connectContext) throws ContainerConnectException {
    if (connection != null)
        throw new ContainerConnectException(Messages.IRCRootContainer_Exception_Already_Connected);
    if (connectID == null)
        throw new ContainerConnectException(Messages.IRCRootContainer_Exception_TargetID_Null);
    if (!(connectID instanceof IRCID))
        throw new ContainerConnectException(NLS.bind(Messages.IRCRootContainer_Exception_TargetID_Wrong_Type, new Object[] { targetID, IRCID.class.getName() }));
    if (connectWaiting)
        throw new ContainerConnectException(Messages.IRCRootContainer_Connecting);
    fireContainerEvent(new ContainerConnectingEvent(this.getID(), connectID, connectContext));
    // Get password via callback in connectContext
    String pw = getPasswordFromConnectContext(connectContext);
    IRCID tID = (IRCID) connectID;
    String host = tID.getHost();
    int port = tID.getPort();
    String pass = pw;
    String nick = tID.getUser();
    String user = nick;
    this.username = user;
    String name = null;
    boolean ssl = false;
    if (!ssl) {
        connection = new IRCConnection(host, new int[] { port }, pass, nick, user, name);
    } else {
        connection = new SSLIRCConnection(host, new int[] { port }, pass, nick, user, name);
    }
    // connection setup
    connection.addIRCEventListener(getIRCEventListener());
    connection.setPong(true);
    connection.setDaemon(false);
    connection.setColors(true);
    if (encoding != null)
        connection.setEncoding(encoding);
    trace(Messages.IRCRootContainer_Connecting_To + targetID);
    synchronized (connectLock) {
        connectWaiting = true;
        connectException = null;
        try {
            connection.connect();
            long timeout = CONNECT_TIMEOUT + System.currentTimeMillis();
            while (connectWaiting && (timeout > System.currentTimeMillis())) {
                connectLock.wait(2000);
            }
            if (connectWaiting)
                throw new TimeoutException(NLS.bind(Messages.IRCRootContainer_Connect_Timeout, tID.getName()), CONNECT_TIMEOUT);
            if (connectException != null)
                throw connectException;
            this.targetID = tID;
            fireContainerEvent(new ContainerConnectedEvent(getID(), this.targetID));
            if (datashareContainer != null) {
                // now that we've connected successfully, we send a USERHOST
                // message to the server so that we can attempt to retrieve
                // our current IP
                retrieveUserhost = true;
                connection.doUserhost(nick);
            }
        } catch (Exception e) {
            this.targetID = null;
            throw new ContainerConnectException(NLS.bind(Messages.IRCRootContainer_Exception_Connect_Failed, connectID.getName()), e);
        } finally {
            connectWaiting = false;
            connectException = null;
        }
    }
}
Also used : SSLIRCConnection(org.schwering.irc.lib.ssl.SSLIRCConnection) SSLIRCConnection(org.schwering.irc.lib.ssl.SSLIRCConnection) ECFException(org.eclipse.ecf.core.util.ECFException) TimeoutException(org.eclipse.equinox.concurrent.future.TimeoutException) IRCID(org.eclipse.ecf.internal.provider.irc.identity.IRCID) TimeoutException(org.eclipse.equinox.concurrent.future.TimeoutException)

Aggregations

IRCID (org.eclipse.ecf.internal.provider.irc.identity.IRCID)2 ECFException (org.eclipse.ecf.core.util.ECFException)1 IChatRoomManager (org.eclipse.ecf.presence.chatroom.IChatRoomManager)1 AsynchContainerConnectAction (org.eclipse.ecf.ui.actions.AsynchContainerConnectAction)1 IDCreateErrorDialog (org.eclipse.ecf.ui.dialogs.IDCreateErrorDialog)1 TimeoutException (org.eclipse.equinox.concurrent.future.TimeoutException)1 SSLIRCConnection (org.schwering.irc.lib.ssl.SSLIRCConnection)1