From 2232b3128b12564256b5368eeaa29d5473136af2 Mon Sep 17 00:00:00 2001 From: delthas Date: Fri, 12 Jun 2020 14:35:26 +0200 Subject: [PATCH] Fix sending messages from detached channels Currently, a downstream receives MODE, RPL_CHANNELMODEIS and RPL_CREATIONTIME messages from soju for detached channels. It should not be sent any of these messages. This adds a detach check to the handling of these messages to avoid receiving these messages. --- upstream.go | 59 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/upstream.go b/upstream.go index a21e016..a0f5d69 100644 --- a/upstream.go +++ b/upstream.go @@ -858,24 +858,27 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error { } uc.appendLog(ch.Name, msg) - uc.forEachDownstream(func(dc *downstreamConn) { - params := make([]string, len(msg.Params)) - params[0] = dc.marshalEntity(uc.network, name) - params[1] = modeStr - copy(params[2:], msg.Params[2:]) - for i, modeParam := range params[2:] { - if _, ok := needMarshaling[i]; ok { - params[2+i] = dc.marshalEntity(uc.network, modeParam) + if ch, ok := uc.network.channels[name]; !ok || !ch.Detached { + uc.forEachDownstream(func(dc *downstreamConn) { + params := make([]string, len(msg.Params)) + params[0] = dc.marshalEntity(uc.network, name) + params[1] = modeStr + + copy(params[2:], msg.Params[2:]) + for i, modeParam := range params[2:] { + if _, ok := needMarshaling[i]; ok { + params[2+i] = dc.marshalEntity(uc.network, modeParam) + } } - } - dc.SendMessage(&irc.Message{ - Prefix: dc.marshalUserPrefix(uc.network, msg.Prefix), - Command: "MODE", - Params: params, + dc.SendMessage(&irc.Message{ + Prefix: dc.marshalUserPrefix(uc.network, msg.Prefix), + Command: "MODE", + Params: params, + }) }) - }) + } } case irc.RPL_UMODEIS: if err := parseMessageParams(msg, nil); err != nil { @@ -912,18 +915,20 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error { return err } if firstMode { - modeStr, modeParams := ch.modes.Format() + if c, ok := uc.network.channels[channel]; !ok || !c.Detached { + modeStr, modeParams := ch.modes.Format() - uc.forEachDownstream(func(dc *downstreamConn) { - params := []string{dc.nick, dc.marshalEntity(uc.network, channel), modeStr} - params = append(params, modeParams...) + uc.forEachDownstream(func(dc *downstreamConn) { + params := []string{dc.nick, dc.marshalEntity(uc.network, channel), modeStr} + params = append(params, modeParams...) - dc.SendMessage(&irc.Message{ - Prefix: dc.srv.prefix(), - Command: irc.RPL_CHANNELMODEIS, - Params: params, + dc.SendMessage(&irc.Message{ + Prefix: dc.srv.prefix(), + Command: irc.RPL_CHANNELMODEIS, + Params: params, + }) }) - }) + } } case rpl_creationtime: var channel, creationTime string @@ -1048,9 +1053,11 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error { } ch.complete = true - uc.forEachDownstream(func(dc *downstreamConn) { - forwardChannel(dc, ch) - }) + if c, ok := uc.network.channels[name]; !ok || !c.Detached { + uc.forEachDownstream(func(dc *downstreamConn) { + forwardChannel(dc, ch) + }) + } case irc.RPL_WHOREPLY: var channel, username, host, server, nick, mode, trailing string if err := parseMessageParams(msg, nil, &channel, &username, &host, &server, &nick, &mode, &trailing); err != nil {