# HG changeset patch # User Stu Tomlinson # Date 1210864924 0 # Node ID f1dfc0d70d19a02b098b9793ecdf3f614c2bd9e0 # Parent a84b748c4c1eb85d8f80b66bbf4385a054e1cf3d Fix irc nick collision handling, as requested by that demanding user elb. Now we append the extra digit, unless the server responds with a shorter nick than we requested, in which case we just change the last digit as before. diff -r a84b748c4c1e -r f1dfc0d70d19 libpurple/protocols/irc/cmds.c --- a/libpurple/protocols/irc/cmds.c Thu May 15 13:26:55 2008 +0000 +++ b/libpurple/protocols/irc/cmds.c Thu May 15 15:22:04 2008 +0000 @@ -256,6 +256,9 @@ return 0; buf = irc_format(irc, "v:", "NICK", args[0]); + g_free(irc->reqnick); + irc->reqnick = g_strdup(args[0]); + irc->nickused = FALSE; irc_send(irc, buf); g_free(buf); diff -r a84b748c4c1e -r f1dfc0d70d19 libpurple/protocols/irc/irc.c --- a/libpurple/protocols/irc/irc.c Thu May 15 13:26:55 2008 +0000 +++ b/libpurple/protocols/irc/irc.c Thu May 15 15:22:04 2008 +0000 @@ -404,7 +404,10 @@ return FALSE; } g_free(buf); - buf = irc_format(irc, "vn", "NICK", purple_connection_get_display_name(gc)); + username = purple_connection_get_display_name(gc); + buf = irc_format(irc, "vn", "NICK", username); + irc->reqnick = g_strdup(username); + irc->nickused = FALSE; if (irc_send(irc, buf) < 0) { g_free(buf); return FALSE; @@ -491,6 +494,7 @@ purple_circ_buffer_destroy(irc->outbuf); g_free(irc->mode_chars); + g_free(irc->reqnick); g_free(irc); } diff -r a84b748c4c1e -r f1dfc0d70d19 libpurple/protocols/irc/irc.h --- a/libpurple/protocols/irc/irc.h Thu May 15 13:26:55 2008 +0000 +++ b/libpurple/protocols/irc/irc.h Thu May 15 15:22:04 2008 +0000 @@ -88,6 +88,8 @@ time_t recv_time; char *mode_chars; + char *reqnick; + gboolean nickused; }; struct irc_buddy { diff -r a84b748c4c1e -r f1dfc0d70d19 libpurple/protocols/irc/msgs.c --- a/libpurple/protocols/irc/msgs.c Thu May 15 13:26:55 2008 +0000 +++ b/libpurple/protocols/irc/msgs.c Thu May 15 15:22:04 2008 +0000 @@ -937,6 +937,8 @@ GSList *chats; char *nick = irc_mask_nick(from); + irc->nickused = FALSE; + if (!gc) { g_free(nick); return; @@ -985,17 +987,23 @@ if (!args || !args[1]) return; - newnick = g_strdup(args[1]); + if (strlen(args[1]) < strlen(irc->reqnick) || irc->nickused) + newnick = g_strdup(args[1]); + else + newnick = g_strdup_printf("%s0", args[1]); end = newnick + strlen(newnick) - 1; /* try fallbacks */ if((*end < '9') && (*end >= '1')) { *end = *end + 1; } else *end = '1'; + g_free(irc->reqnick); + irc->reqnick = newnick; + irc->nickused = TRUE; + buf = irc_format(irc, "vn", "NICK", newnick); irc_send(irc, buf); g_free(buf); - g_free(newnick); } void irc_msg_notice(struct irc_conn *irc, const char *name, const char *from, char **args)