From 2554c92df7f5496e7698cd20c748b9491c49c49a Mon Sep 17 00:00:00 2001 From: Hubert Hirtz Date: Sun, 19 Sep 2021 16:47:27 +0200 Subject: [PATCH] Allow CAP negotiation to happen with CAP REQ See https://ircv3.net/specs/extensions/capability-negotiation > Upon receiving either a CAP LS or CAP REQ command during connection > registration, the server MUST not complete registration until the > client sends a CAP END command to indicate that capability negotiation > has ended. This commit should prevent soju from trying to authenticate the user prior to having received AUTHENTICATE messages, when the client eagerly requests capabilities with CAP REQ seeing available capabilities beforehand with CAP LS. --- downstream.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/downstream.go b/downstream.go index 4e6ed54..d03a244 100644 --- a/downstream.go +++ b/downstream.go @@ -185,7 +185,7 @@ type downstreamConn struct { password string // empty after authentication network *network // can be nil - negociatingCaps bool + negotiatingCaps bool capVersion int supportedCaps map[string]string caps map[string]bool @@ -717,7 +717,7 @@ func (dc *downstreamConn) handleMessageUnregistered(msg *irc.Message) error { dc.logger.Printf("unhandled message: %v", msg) return newUnknownCommandError(msg.Command) } - if dc.rawUsername != "" && dc.nick != "" && !dc.negociatingCaps { + if dc.rawUsername != "" && dc.nick != "" && !dc.negotiatingCaps { return dc.register() } return nil @@ -770,7 +770,7 @@ func (dc *downstreamConn) handleCapCommand(cmd string, args []string) error { } if !dc.registered { - dc.negociatingCaps = true + dc.negotiatingCaps = true } case "LIST": var caps []string @@ -832,8 +832,12 @@ func (dc *downstreamConn) handleCapCommand(cmd string, args []string) error { Command: "CAP", Params: []string{replyTo, reply, args[0]}, }) + + if !dc.registered { + dc.negotiatingCaps = true + } case "END": - dc.negociatingCaps = false + dc.negotiatingCaps = false default: return ircError{&irc.Message{ Command: err_invalidcapcmd,