AmendHub

Download:

jcs

/

wallops

/

amendments

/

104

irc: Handle our own nick change outside of a channel


jcs made amendment 104 2 months ago
--- irc.c Thu Sep 12 20:25:07 2024 +++ irc.c Mon Sep 16 09:46:22 2024 @@ -42,8 +42,8 @@ void irc_add_nick_to_channel(struct irc_channel *chann short flags, short count_hint); void irc_remove_nick_from_channel(struct irc_channel *channel, char *nick); bool irc_nick_is_in_channel(struct irc_channel *channel, char *nick); -void irc_change_user_nick(struct irc_channel *channel, - struct irc_user *user, char *nick); +void irc_change_user_nick(struct irc_connection *conn, + struct irc_channel *channel, struct irc_user *user, char *nick); bool irc_parse_channel_mode_change(struct irc_channel *channel, char *mode, char *args); void irc_do_mode_to_users(struct irc_connection *conn, char *channel_name, @@ -531,7 +531,6 @@ irc_process_server(struct irc_connection *conn) chatter_printf(conn->chatter, conn, user->nick, "$B[%s($0%s@%s$B)]$0$/ %s", user->nick, user->username, user->hostname, msg.msg); - if (!conn->chatter->focusable->visible) notify(); } else { @@ -542,8 +541,8 @@ irc_process_server(struct irc_connection *conn) msg.msg[size] == ',' || msg.msg[size] == '\0')) { /* highlight message directed to us */ chatter_printf(conn->chatter, conn, msg.arg[0], - "<$U%s$0>$/ %s", user->nick, - msg.msg); + "<$U%s$0>$/ %s", + user->nick, msg.msg); if (!conn->chatter->focusable->visible) notify(); } else @@ -663,16 +662,23 @@ irc_process_server(struct irc_connection *conn) } if (strcmp(msg.cmd, "NICK") == 0) { user = irc_parse_user(msg.source); + + if (strcasecmp(user->nick, conn->nick) == 0) { + chatter_printf(conn->chatter, conn, NULL, + "$B*** %s$0 is now known as $B%s$0", + user->nick, msg.msg); + irc_change_user_nick(conn, NULL, user, msg.msg); + } + SLIST_FOREACH(channel, &conn->channels_list, list) { if (!irc_nick_is_in_channel(channel, user->nick)) continue; - if (strcmp(msg.msg, conn->nick) == 0 || - !(settings.ignores & IGNORE_NICKS)) + if (!(settings.ignores & IGNORE_NICKS)) chatter_printf(conn->chatter, conn, channel->name, "$B*** %s$0 is now known as $B%s$0", user->nick, msg.msg); - irc_change_user_nick(channel, user, msg.msg); + irc_change_user_nick(conn, channel, user, msg.msg); } /* TODO: if any query windows for this nick, update them */ return true; @@ -1520,8 +1526,8 @@ irc_nick_is_in_channel(struct irc_channel *channel, ch } void -irc_change_user_nick(struct irc_channel *channel, struct irc_user *user, - char *nick) +irc_change_user_nick(struct irc_connection *conn, + struct irc_channel *channel, struct irc_user *user, char *nick) { struct irc_channel_nick *cnick; short n, flags; @@ -1543,10 +1549,10 @@ irc_change_user_nick(struct irc_channel *channel, stru irc_add_nick_to_channel(channel, nick, flags, 0); } - if (strcmp(channel->connection->nick, user->nick) == 0) { - xfree(&channel->connection->nick); - channel->connection->nick = xstrdup(nick); - chatter_update_titlebar(channel->chatter); + if (strcasecmp(conn->nick, user->nick) == 0) { + xfree(&conn->nick); + conn->nick = xstrdup(nick); + chatter_update_titlebar(conn->chatter); } }