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.
This commit is contained in:
parent
e85c98f315
commit
1e04fc24a7
18
degesch.c
18
degesch.c
|
@ -2693,6 +2693,10 @@ buffer_rename (struct app_context *ctx,
|
||||||
{
|
{
|
||||||
hard_assert (buffer->type == BUFFER_PM);
|
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 =
|
struct buffer *collision =
|
||||||
str_map_find (&buffer->server->irc_buffer_map, new_name);
|
str_map_find (&buffer->server->irc_buffer_map, new_name);
|
||||||
if (collision)
|
if (collision)
|
||||||
|
@ -4383,9 +4387,13 @@ irc_handle_nick (struct server *s, const struct irc_message *msg)
|
||||||
if (!user)
|
if (!user)
|
||||||
return;
|
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
|
// 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;
|
return;
|
||||||
|
|
||||||
// Log a message in any PM buffer and rename it;
|
// Log a message in any PM buffer and rename it;
|
||||||
|
@ -4393,9 +4401,12 @@ irc_handle_nick (struct server *s, const struct irc_message *msg)
|
||||||
struct buffer *pm_buffer =
|
struct buffer *pm_buffer =
|
||||||
str_map_find (&s->irc_buffer_map, user->nickname);
|
str_map_find (&s->irc_buffer_map, user->nickname);
|
||||||
if (pm_buffer)
|
if (pm_buffer)
|
||||||
|
{
|
||||||
|
if (!lexicographically_identical)
|
||||||
{
|
{
|
||||||
str_map_set (&s->irc_buffer_map, new_nickname, pm_buffer);
|
str_map_set (&s->irc_buffer_map, new_nickname, pm_buffer);
|
||||||
str_map_set (&s->irc_buffer_map, user->nickname, NULL);
|
str_map_set (&s->irc_buffer_map, user->nickname, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
char *who = irc_is_this_us (s, msg->prefix)
|
char *who = irc_is_this_us (s, msg->prefix)
|
||||||
? irc_to_utf8 (s->ctx, 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
|
// Finally rename the user
|
||||||
|
if (!lexicographically_identical)
|
||||||
|
{
|
||||||
str_map_set (&s->irc_users, new_nickname, user_ref (user));
|
str_map_set (&s->irc_users, new_nickname, user_ref (user));
|
||||||
str_map_set (&s->irc_users, user->nickname, NULL);
|
str_map_set (&s->irc_users, user->nickname, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
free (user->nickname);
|
free (user->nickname);
|
||||||
user->nickname = xstrdup (new_nickname);
|
user->nickname = xstrdup (new_nickname);
|
||||||
|
|
Loading…
Reference in New Issue