From f13a9c9d86f7d3ad9072cdb743be5806ac66c5d8 Mon Sep 17 00:00:00 2001 From: delthas Date: Tue, 19 May 2020 17:27:43 +0200 Subject: [PATCH] Send a label with all messages sent from downstream This is preparatory work for forwarding errors of downstream-initiated messages to their sender, as well as any other unknown message. Preivously, we only sent labels (for labeled-response) for specific downstream messages, such as WHO, where we knew the reply should only be sent to that specific downstream. However, in the case of an error of a message that is not labeled, the error reply is not be tagged with a downstream id label and we can't forward it to a specific downstream. It is not a good solution either to forward this error to all downstreams. This adds labels to all downstream-initiated messages (provided the upstream supports it). --- downstream.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/downstream.go b/downstream.go index cc565d0..47f7af4 100644 --- a/downstream.go +++ b/downstream.go @@ -958,7 +958,7 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error { if upstream != nil && upstream != uc { return } - uc.SendMessage(&irc.Message{ + uc.SendMessageLabeled(dc.id, &irc.Message{ Command: "NICK", Params: []string{nick}, }) @@ -998,7 +998,7 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error { if key != "" { params = append(params, key) } - uc.SendMessage(&irc.Message{ + uc.SendMessageLabeled(dc.id, &irc.Message{ Command: "JOIN", Params: params, }) @@ -1040,7 +1040,7 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error { if reason != "" { params = append(params, reason) } - uc.SendMessage(&irc.Message{ + uc.SendMessageLabeled(dc.id, &irc.Message{ Command: "PART", Params: params, }) @@ -1101,7 +1101,7 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error { if reason != "" { params = append(params, reason) } - uc.SendMessage(&irc.Message{ + uc.SendMessageLabeled(dc.id, &irc.Message{ Command: "KICK", Params: params, }) @@ -1120,7 +1120,7 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error { if name == dc.nick { if modeStr != "" { dc.forEachUpstream(func(uc *upstreamConn) { - uc.SendMessage(&irc.Message{ + uc.SendMessageLabeled(dc.id, &irc.Message{ Command: "MODE", Params: []string{uc.nick, modeStr}, }) @@ -1150,7 +1150,7 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error { if modeStr != "" { params := []string{upstreamName, modeStr} params = append(params, msg.Params[2:]...) - uc.SendMessage(&irc.Message{ + uc.SendMessageLabeled(dc.id, &irc.Message{ Command: "MODE", Params: params, }) @@ -1199,7 +1199,7 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error { if len(msg.Params) > 1 { // setting topic topic := msg.Params[1] - uc.SendMessage(&irc.Message{ + uc.SendMessageLabeled(dc.id, &irc.Message{ Command: "TOPIC", Params: []string{upstreamChannel, topic}, }) @@ -1417,7 +1417,7 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error { if uc.isChannel(upstreamName) { unmarshaledText = dc.unmarshalText(uc, text) } - uc.SendMessage(&irc.Message{ + uc.SendMessageLabeled(dc.id, &irc.Message{ Command: "PRIVMSG", Params: []string{upstreamName, unmarshaledText}, }) @@ -1451,7 +1451,7 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error { if uc.isChannel(upstreamName) { unmarshaledText = dc.unmarshalText(uc, text) } - uc.SendMessage(&irc.Message{ + uc.SendMessageLabeled(dc.id, &irc.Message{ Command: "NOTICE", Params: []string{upstreamName, unmarshaledText}, })