From c438554f9ae840a0e2788e6c7ee097bce258b8f4 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 23 Sep 2026 21:59:20 -0500 Subject: [PATCH] Ignore nick change when there is a configured nick The user has configured their nick and that's what we should use. If they send a nick change, just reply letting them know what their nick actually is. --- src/bridge/bridge.cpp | 23 ++++++++++++++++ .../scenarios/nick_change_when_configured.py | 26 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 tests/end_to_end/scenarios/nick_change_when_configured.py diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp index daf297b..fcf3dcc 100644 --- a/src/bridge/bridge.cpp +++ b/src/bridge/bridge.cpp @@ -599,6 +599,29 @@ void Bridge::send_irc_nick_change(const Iid& iid, const std::string& new_nick, c if (new_nick == irc->get_own_nick()) return; +#ifdef USE_DATABASE + auto soptions = Database::get_irc_server_options(this->get_bare_jid(), iid.get_server()); + const auto& db_nick = soptions.col(); + if (!db_nick.empty()) + { + IrcChannel* channel = irc->get_channel(iid.get_local()); + const IrcUser* self = channel ? channel->get_self() : nullptr; + // Send presence 110+210 to let them know the nick we're actually using + if (self) + { + this->send_user_join(iid.get_server(), iid.get_local(), self, + self->get_most_significant_mode(irc->get_sorted_user_modes()), + true, requesting_resource); + } + else + { + IrcUser user(irc->get_own_nick()); + this->send_user_join(iid.get_server(), iid.get_local(), &user, '\0', true, requesting_resource); + } + return; + } +#endif + irc->send_nick_command(new_nick); } diff --git a/tests/end_to_end/scenarios/nick_change_when_configured.py b/tests/end_to_end/scenarios/nick_change_when_configured.py new file mode 100644 index 0000000..15dc38a --- /dev/null +++ b/tests/end_to_end/scenarios/nick_change_when_configured.py @@ -0,0 +1,26 @@ +from scenarios import * + +scenario = ( + send_stanza(""), + sequences.connection(), + expect_stanza("/presence[@to='{jid_one}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_one}']/muc_user:x/muc_user:item[@affiliation='admin'][@role='moderator']", + "/presence/muc_user:x/muc_user:status[@code='110']"), + expect_stanza("/message[@from='#foo%{irc_server_one}'][@type='groupchat']/subject[not(text())]"), + + # Configure a nickname in the database for this server + send_stanza(""), + expect_stanza("/iq[@type='result']", + after = save_value("sessionid", extract_attribute("/iq[@type='result']/commands:command[@node='configure']", "sessionid"))), + send_stanza("" + "" + "" + "{nick_one}" + ""), + expect_stanza("/iq[@type='result']/commands:command[@node='configure'][@status='completed']/commands:note[@type='info'][text()='Configuration successfully applied.']"), + + # Now with a DB nick configured, attempt to change nick: should reply with 110 + 210 presence rewriting to DB nick + send_stanza(""), + expect_stanza("/presence[@to='{jid_one}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_one}']/muc_user:x/muc_user:item[@affiliation='admin'][@role='moderator']", + "/presence/muc_user:x/muc_user:status[@code='110']", + "/presence/muc_user:x/muc_user:status[@code='210']"), +)