changeset 22958: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 a84b748c4c1e
children 2555e069cd8c
files libpurple/protocols/irc/cmds.c libpurple/protocols/irc/irc.c libpurple/protocols/irc/irc.h libpurple/protocols/irc/msgs.c
diffstat 4 files changed, 20 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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);
 
--- 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);
 }
--- 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 {
--- 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)