~emersion/soju-dev

Forward MOTD messages downstream v2 APPLIED

Gregory Anders: 1
 Forward MOTD messages downstream

 2 files changed, 29 insertions(+), 2 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/soju-dev/patches/23229/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH v2] Forward MOTD messages downstream Export this patch

The first MOTD upon connection is ignored, but subsequent MOTD messages
(requested by the "MOTD" message from the client, typically using a
/motd command) are forwarded.
---
 downstream.go |  2 +-
 upstream.go   | 29 ++++++++++++++++++++++++++++-
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/downstream.go b/downstream.go
index e263054..8e94095 100644
--- a/downstream.go
+++ b/downstream.go
@@ -1105,7 +1105,7 @@ func (dc *downstreamConn) welcome() error {
	dc.SendMessage(&irc.Message{
		Prefix:  dc.srv.prefix(),
		Command: irc.ERR_NOMOTD,
		Params:  []string{dc.nick, "No MOTD"},
		Params:  []string{dc.nick, "Use /motd to read the message of the day"},
	})

	dc.updateNick()
diff --git a/upstream.go b/upstream.go
index c812ef1..1f42a24 100644
--- a/upstream.go
+++ b/upstream.go
@@ -103,6 +103,8 @@ type upstreamConn struct {

	// set of LIST commands in progress, per downstream
	pendingLISTDownstreamSet map[uint64]struct{}

	gotMotd bool
}

func connectToUpstream(network *network) (*upstreamConn, error) {
@@ -662,6 +664,21 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
			uc.network.updateCasemapping(casemapRFC1459)
			uc.nickCM = uc.network.casemap(uc.nick)
		}

		if !uc.gotMotd {
			// Ignore the initial MOTD upon connection, but forward
			// subsequent MOTD messages downstream
			uc.gotMotd = true
			return nil
		}

		uc.forEachDownstreamByID(downstreamID, func (dc *downstreamConn) {
			dc.SendMessage(&irc.Message {
				Prefix: uc.srv.prefix(),
				Command: msg.Command,
				Params: msg.Params,
			})
		})
	case "BATCH":
		var tag string
		if err := parseMessageParams(msg, &tag); err != nil {
@@ -1421,7 +1438,17 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
	case irc.RPL_LUSERCLIENT, irc.RPL_LUSEROP, irc.RPL_LUSERUNKNOWN, irc.RPL_LUSERCHANNELS, irc.RPL_LUSERME:
		// Ignore
	case irc.RPL_MOTDSTART, irc.RPL_MOTD:
		// Ignore
		if !uc.gotMotd {
			return nil
		}

		uc.forEachDownstreamByID(downstreamID, func (dc *downstreamConn) {
			dc.SendMessage(&irc.Message {
				Prefix: uc.srv.prefix(),
				Command: msg.Command,
				Params: msg.Params,
			})
		})
	case irc.RPL_LISTSTART:
		// Ignore
	case rpl_localusers, rpl_globalusers:
-- 
2.32.0
LGTM.

Pushed, thanks!