Broadcast unhandled messages to downstream connections

In case labelled-response isn't supported, broadcast unhandled messages
to all downstream connections. That's better than silently dropping the
messages.
This commit is contained in:
Simon Ser 2020-07-08 18:21:52 +02:00
parent 1685ba23b3
commit 51dc9f0bf9
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

View File

@ -1315,15 +1315,13 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
} }
} }
if downstreamID != 0 { uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) {
uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) { dc.SendMessage(&irc.Message{
dc.SendMessage(&irc.Message{ Prefix: uc.srv.prefix(),
Prefix: uc.srv.prefix(), Command: msg.Command,
Command: msg.Command, Params: []string{dc.nick, command, reason},
Params: []string{dc.nick, command, reason},
})
}) })
} })
case "ACK": case "ACK":
// Ignore // Ignore
case irc.RPL_NOWAWAY, irc.RPL_UNAWAY: case irc.RPL_NOWAWAY, irc.RPL_UNAWAY:
@ -1347,24 +1345,23 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
fallthrough fallthrough
default: default:
uc.logger.Printf("unhandled message: %v", msg) uc.logger.Printf("unhandled message: %v", msg)
if downstreamID != 0 {
uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) { uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) {
// best effort marshaling for unknown messages, replies and errors: // best effort marshaling for unknown messages, replies and errors:
// most numerics start with the user nick, marshal it if that's the case // most numerics start with the user nick, marshal it if that's the case
// otherwise, conservately keep the params without marshaling // otherwise, conservately keep the params without marshaling
params := msg.Params params := msg.Params
if _, err := strconv.Atoi(msg.Command); err == nil { // numeric if _, err := strconv.Atoi(msg.Command); err == nil { // numeric
if len(msg.Params) > 0 && isOurNick(uc.network, msg.Params[0]) { if len(msg.Params) > 0 && isOurNick(uc.network, msg.Params[0]) {
params[0] = dc.nick params[0] = dc.nick
}
} }
dc.SendMessage(&irc.Message{ }
Prefix: uc.srv.prefix(), dc.SendMessage(&irc.Message{
Command: msg.Command, Prefix: uc.srv.prefix(),
Params: params, Command: msg.Command,
}) Params: params,
}) })
} })
} }
return nil return nil
} }