diff libpurple/protocols/irc/msgs.c @ 22956:f1dfc0d70d19

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.
author Stu Tomlinson <stu@nosnilmot.com>
date Thu, 15 May 2008 15:22:04 +0000
parents f09acca60066
children f47438e456c2
line wrap: on
line diff
--- 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)