From 2d47d7067f0b3af24b187af1ab2b8b65ad59e722 Mon Sep 17 00:00:00 2001 From: delthas Date: Fri, 8 May 2020 20:24:59 +0200 Subject: [PATCH] Add support for downstream NICK to a single upstream Users often have different nicks on different upstreams, and we should support changing the user nick on a single upstream. This adds support for a new trivial extension, `NICK nick/network`, which will change the nick on the specified network, and do nothing for the other networks. --- downstream.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/downstream.go b/downstream.go index 7a39423..09ffb67 100644 --- a/downstream.go +++ b/downstream.go @@ -933,9 +933,18 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error { return err } + var upstream *upstreamConn + if dc.upstream() == nil { + uc, unmarshaledNick, err := dc.unmarshalEntity(nick) + if err == nil { // NICK nick/network: NICK only on a specific upstream + upstream = uc + nick = unmarshaledNick + } + } + var err error dc.forEachNetwork(func(n *network) { - if err != nil { + if err != nil || (upstream != nil && upstream.network != n) { return } n.Nick = nick @@ -946,7 +955,13 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error { } dc.forEachUpstream(func(uc *upstreamConn) { - uc.SendMessage(msg) + if upstream != nil && upstream != uc { + return + } + uc.SendMessage(&irc.Message{ + Command: "NICK", + Params: []string{nick}, + }) }) if dc.upstream() == nil && dc.nick != nick {