From b3742cc731bc5c693277c7b817d4fd52eccaaaff Mon Sep 17 00:00:00 2001 From: delthas Date: Fri, 1 May 2020 00:37:42 +0200 Subject: [PATCH] Update downstream nicks in single-server mode and after NICK Previously, the downstream nick was never changed, even when the downstream sent a NICK message or was in single-server mode with a different nick. This adds support for updating the downstream nick in the following cases: - when a downstream sends NICK - additionally, in single-server mode: - when a downstream connects and its single network is connected - when an upstream connects - when an upstream sends NICK --- downstream.go | 22 ++++++++++++++++++++++ upstream.go | 4 ++++ user.go | 2 ++ 3 files changed, 28 insertions(+) diff --git a/downstream.go b/downstream.go index 5782250..7a39423 100644 --- a/downstream.go +++ b/downstream.go @@ -620,6 +620,17 @@ func (dc *downstreamConn) updateSupportedCaps() { } } +func (dc *downstreamConn) updateNick() { + if uc := dc.upstream(); uc != nil && uc.nick != dc.nick { + dc.SendMessage(&irc.Message{ + Prefix: dc.prefix(), + Command: "NICK", + Params: []string{uc.nick}, + }) + dc.nick = uc.nick + } +} + func sanityCheckServer(addr string) error { dialer := net.Dialer{Timeout: 30 * time.Second} conn, err := tls.DialWithDialer(&dialer, "tcp", addr, nil) @@ -777,6 +788,8 @@ func (dc *downstreamConn) welcome() error { Params: []string{dc.nick, "No MOTD"}, }) + dc.updateNick() + dc.forEachUpstream(func(uc *upstreamConn) { for _, ch := range uc.channels { if !ch.complete { @@ -935,6 +948,15 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error { dc.forEachUpstream(func(uc *upstreamConn) { uc.SendMessage(msg) }) + + if dc.upstream() == nil && dc.nick != nick { + dc.SendMessage(&irc.Message{ + Prefix: dc.prefix(), + Command: "NICK", + Params: []string{nick}, + }) + dc.nick = nick + } case "JOIN": var namesStr string if err := parseMessageParams(msg, &namesStr); err != nil { diff --git a/upstream.go b/upstream.go index efedbea..61d7297 100644 --- a/upstream.go +++ b/upstream.go @@ -656,6 +656,10 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error { uc.forEachDownstream(func(dc *downstreamConn) { dc.SendMessage(dc.marshalMessage(msg, uc.network)) }) + } else { + uc.forEachDownstream(func(dc *downstreamConn) { + dc.updateNick() + }) } case "JOIN": if msg.Prefix == nil { diff --git a/user.go b/user.go index 13d51e8..dacf13b 100644 --- a/user.go +++ b/user.go @@ -298,6 +298,8 @@ func (u *user) run() { uc.forEachDownstream(func(dc *downstreamConn) { dc.updateSupportedCaps() sendServiceNOTICE(dc, fmt.Sprintf("connected to %s", uc.network.GetName())) + + dc.updateNick() }) uc.network.lastError = nil case eventUpstreamDisconnected: