downstream: ensure numerics always carry a source prefix

From [1]:

> Distinct from a normal message, a numeric reply MUST contain a
> <source> and use a three-digit numeric as the command.

[1]: https://modern.ircdocs.horse/#numeric-replies
This commit is contained in:
Simon Ser 2024-04-30 14:23:49 +02:00
parent d5108f3994
commit 51a12983d8

View file

@ -530,6 +530,12 @@ func (dc *downstreamConn) SendMessage(ctx context.Context, msg *irc.Message) {
msg = &msgCopy
msg.Prefix = nil
}
if msg.Prefix == nil && isNumeric(msg.Command) {
// Numerics must always carry a source
msgCopy := *msg
msg = &msgCopy
msg.Prefix = dc.srv.prefix()
}
dc.srv.metrics.downstreamOutMessagesTotal.Inc()
dc.conn.SendMessage(ctx, msg)