From 1e04fc24a7b2b23a9913011c92629c47e58a6735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?= Date: Sun, 21 Jun 2015 22:30:59 +0200 Subject: [PATCH] degesch: fix /nick handling When the new nickname was lexicographically identical (for example User -> uSer), the whole thing broke down. In addition to that, we used to check if the new nickname exists and failed in that case. It _can_, however, exist. It just mustn't be us. --- degesch.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/degesch.c b/degesch.c index 75ad5af..5268777 100644 --- a/degesch.c +++ b/degesch.c @@ -2693,6 +2693,10 @@ buffer_rename (struct app_context *ctx, { hard_assert (buffer->type == BUFFER_PM); + // FIXME: this will never find anything as we are being sent + // the full buffer name, including the server name; + // searching in "buffers_by_name" won't do it either, + // we seem to need more information to properly handle this struct buffer *collision = str_map_find (&buffer->server->irc_buffer_map, new_name); if (collision) @@ -4383,9 +4387,13 @@ irc_handle_nick (struct server *s, const struct irc_message *msg) if (!user) return; - // What the fuck + bool lexicographically_identical = + !irc_server_strcmp (s, user->nickname, new_nickname); + + // What the fuck, someone renamed themselves to ourselves // TODO: probably log a message and force a reconnect - if (str_map_find (&s->irc_users, new_nickname)) + if (!lexicographically_identical + && !irc_server_strcmp (s, new_nickname, s->irc_user->nickname)) return; // Log a message in any PM buffer and rename it; @@ -4394,8 +4402,11 @@ irc_handle_nick (struct server *s, const struct irc_message *msg) str_map_find (&s->irc_buffer_map, user->nickname); if (pm_buffer) { - str_map_set (&s->irc_buffer_map, new_nickname, pm_buffer); - str_map_set (&s->irc_buffer_map, user->nickname, NULL); + if (!lexicographically_identical) + { + str_map_set (&s->irc_buffer_map, new_nickname, pm_buffer); + str_map_set (&s->irc_buffer_map, user->nickname, NULL); + } char *who = irc_is_this_us (s, msg->prefix) ? irc_to_utf8 (s->ctx, msg->prefix) @@ -4440,8 +4451,11 @@ irc_handle_nick (struct server *s, const struct irc_message *msg) } // Finally rename the user - str_map_set (&s->irc_users, new_nickname, user_ref (user)); - str_map_set (&s->irc_users, user->nickname, NULL); + if (!lexicographically_identical) + { + str_map_set (&s->irc_users, new_nickname, user_ref (user)); + str_map_set (&s->irc_users, user->nickname, NULL); + } free (user->nickname); user->nickname = xstrdup (new_nickname);