pidgin: 328ae78c: Fix irc nick collision handling, as requ...

nosnilmot at pidgin.im nosnilmot at pidgin.im
Thu May 15 11:26:13 EDT 2008


-----------------------------------------------------------------
Revision: 328ae78ce53f7df24ec23e268e458a87b3b42b07
Ancestor: faff59f52a91c3ab8f2db3ce56642828fabd0dc8
Author: nosnilmot at pidgin.im
Date: 2008-05-15T15:22:04
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/328ae78ce53f7df24ec23e268e458a87b3b42b07

Modified files:
        libpurple/protocols/irc/cmds.c libpurple/protocols/irc/irc.c
        libpurple/protocols/irc/irc.h libpurple/protocols/irc/msgs.c

ChangeLog: 

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.

-------------- next part --------------
============================================================
--- libpurple/protocols/irc/cmds.c	a6d877b741cce2a63467616046357c8cc276d3bd
+++ libpurple/protocols/irc/cmds.c	5a474ed951b98282d4d7564fc984cba00c852681
@@ -256,6 +256,9 @@ int irc_cmd_nick(struct irc_conn *irc, c
 		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);
 
============================================================
--- libpurple/protocols/irc/irc.c	123ab56826fab72d4e46f7dfdc7b0d385e4e61e0
+++ libpurple/protocols/irc/irc.c	72a70c0244023236c1bf6f5666ac555f599b8a05
@@ -404,7 +404,10 @@ static gboolean do_login(PurpleConnectio
 		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 @@ static void irc_close(PurpleConnection *
 	purple_circ_buffer_destroy(irc->outbuf);
 
 	g_free(irc->mode_chars);
+	g_free(irc->reqnick);
 
 	g_free(irc);
 }
============================================================
--- libpurple/protocols/irc/irc.h	9ff8aa10d4dad190585971b08adb090e56ac6c29
+++ libpurple/protocols/irc/irc.h	725eea8187529e6af90e5e25cd948a9f2e91facf
@@ -88,6 +88,8 @@ struct irc_conn {
 	time_t recv_time;
 
 	char *mode_chars;
+	char *reqnick;
+	gboolean nickused;
 };
 
 struct irc_buddy {
============================================================
--- libpurple/protocols/irc/msgs.c	aca0a320af3f8a3ff966ab46bb9561e000445237
+++ libpurple/protocols/irc/msgs.c	13ec164ae864a1248cefbd33c76b29da7a4f5419
@@ -937,6 +937,8 @@ void irc_msg_nick(struct irc_conn *irc, 
 	GSList *chats;
 	char *nick = irc_mask_nick(from);
 
+	irc->nickused = FALSE;
+
 	if (!gc) {
 		g_free(nick);
 		return;
@@ -985,17 +987,23 @@ void irc_msg_nickused(struct irc_conn *i
 	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)


More information about the Commits mailing list