From 9530df5db04957cc517a80f189937194bc451736 Mon Sep 17 00:00:00 2001 From: delthas Date: Thu, 26 Mar 2020 06:03:07 +0100 Subject: [PATCH] Add downstream INVITE support --- downstream.go | 28 ++++++++++++++++++++++++++++ upstream.go | 14 ++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/downstream.go b/downstream.go index fa8f6fb..2194b45 100644 --- a/downstream.go +++ b/downstream.go @@ -1236,6 +1236,34 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error { uc.network.ring.Produce(echoMsg) } + case "INVITE": + var user, channel string + if err := parseMessageParams(msg, &user, &channel); err != nil { + return err + } + + ucChannel, upstreamChannel, err := dc.unmarshalEntity(channel) + if err != nil { + return err + } + + ucUser, upstreamUser, err := dc.unmarshalEntity(user) + if err != nil { + return err + } + + if ucChannel != ucUser { + return ircError{&irc.Message{ + Command: irc.ERR_USERNOTINCHANNEL, + Params: []string{dc.nick, user, channel, "They aren't on that channel"}, + }} + } + uc := ucChannel + + uc.SendMessageLabeled(dc, &irc.Message{ + Command: "INVITE", + Params: []string{upstreamUser, upstreamChannel}, + }) default: dc.logger.Printf("unhandled message: %v", msg) return newUnknownCommandError(msg.Command) diff --git a/upstream.go b/upstream.go index d6684d8..a2332dd 100644 --- a/upstream.go +++ b/upstream.go @@ -1045,6 +1045,20 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error { Params: []string{dc.marshalNick(uc, nick), dc.marshalChannel(uc, channel)}, }) }) + case irc.RPL_INVITING: + var nick string + var channel string + if err := parseMessageParams(msg, &nick, &channel); err != nil { + return err + } + + uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) { + dc.SendMessage(&irc.Message{ + Prefix: dc.srv.prefix(), + Command: irc.RPL_INVITING, + Params: []string{dc.nick, dc.marshalNick(uc, nick), dc.marshalChannel(uc, channel)}, + }) + }) case "TAGMSG": // TODO: relay to downstream connections that accept message-tags case "ACK":