diff -ru telepathy-idle-0.1.2/src/idle-connection.c telepathy-idle-ted/src/idle-connection.c --- telepathy-idle-0.1.2/src/idle-connection.c 2007-09-25 15:25:58.000000000 -0400 +++ telepathy-idle-ted/src/idle-connection.c 2008-02-25 12:29:45.000000000 -0500 @@ -716,11 +716,36 @@ return IDLE_PARSER_HANDLER_RESULT_NOT_HANDLED; } +#define IDLE_NICK_APPEND_CHAR "_" + static IdleParserHandlerResult _nickname_in_use_handler(IdleParser *parser, IdleParserMessageCode code, GValueArray *args, gpointer user_data) { IdleConnection *conn = IDLE_CONNECTION(user_data); + IdleConnectionPrivate *priv = IDLE_CONNECTION_GET_PRIVATE(conn); - if (conn->parent.status == TP_CONNECTION_STATUS_CONNECTING) - connection_connect_cb(conn, FALSE, TP_CONNECTION_STATUS_REASON_NAME_IN_USE); + if (conn->parent.status == TP_CONNECTION_STATUS_CONNECTING) { + /* Code to make it so that nicks don't collide. If the nick + * collides and we're trying to connect we'll keep appending on + * IDLE_NICK_APPEND_CHAR until the nick becomes half of the full + * message length allowed. Half because, well, if your nick is + * so long that you can't write messages it isn't very useful. + * Basically we send another nick command, and this call back + * is called if it returns an error also. + */ + if (strlen(priv->nickname) + strlen(IDLE_NICK_APPEND_CHAR) + strlen("NICK ") > IRC_MSG_MAXLEN / 2) { + connection_connect_cb(conn, FALSE, TP_CONNECTION_STATUS_REASON_NAME_IN_USE); + } else { + gchar * newnick = g_strdup_printf("%s%s", priv->nickname, IDLE_NICK_APPEND_CHAR); + GValue nickparam; + g_value_init(&nickparam, G_TYPE_STRING); + g_value_set_string(&nickparam, newnick); + idle_connection_set_property(conn, PROP_NICKNAME, &nickparam, NULL); + g_free(newnick); + + gchar msg[IRC_MSG_MAXLEN+1]; + g_snprintf(msg, IRC_MSG_MAXLEN+1, "NICK %s", priv->nickname); + send_irc_cmd(conn, msg); + } + } return IDLE_PARSER_HANDLER_RESULT_HANDLED; }