From 2fe0a57e430796cdec489817a35b3e4dee790eb1 Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Wed, 9 Jun 2021 13:25:15 -0600 Subject: [PATCH] Forward MOTD messages downstream 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: