From e39948cdbd33f2837baaeb054ce690650a5c810f Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 13 Mar 2020 11:26:43 +0100 Subject: [PATCH] Add upstream CAP LS support --- upstream.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/upstream.go b/upstream.go index 7c95aad..14b21eb 100644 --- a/upstream.go +++ b/upstream.go @@ -47,6 +47,7 @@ type upstreamConn struct { modes modeSet channels map[string]*upstreamChannel history map[string]uint64 + caps map[string]string } func connectToUpstream(network *network) (*upstreamConn, error) { @@ -77,6 +78,7 @@ func connectToUpstream(network *network) (*upstreamConn, error) { ring: NewRing(network.user.srv.RingCap), channels: make(map[string]*upstreamChannel), history: make(map[string]uint64), + caps: make(map[string]string), } go func() { @@ -166,6 +168,29 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error { } case "NOTICE": uc.logger.Print(msg) + case "CAP": + if len(msg.Params) < 2 { + return newNeedMoreParamsError(msg.Command) + } + caps := strings.Fields(msg.Params[len(msg.Params) - 1]) + more := msg.Params[len(msg.Params) - 2] == "*" + + for _, s := range caps { + kv := strings.SplitN(s, "=", 2) + k := strings.ToLower(kv[0]) + var v string + if len(kv) >= 2 { + v = kv[1] + } + uc.caps[k] = v + } + + if !more { + uc.SendMessage(&irc.Message{ + Command: "CAP", + Params: []string{"END"}, + }) + } case irc.RPL_WELCOME: uc.registered = true uc.logger.Printf("connection registered") @@ -430,6 +455,11 @@ func (uc *upstreamConn) register() { uc.realname = uc.nick } + uc.SendMessage(&irc.Message{ + Command: "CAP", + Params: []string{"LS", "302"}, + }) + uc.SendMessage(&irc.Message{ Command: "NICK", Params: []string{uc.nick},