From c84ef97b90f0a94dd85128701daa87bdbffb5bf2 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Sun, 28 Apr 2019 01:50:16 +1000 Subject: [PATCH 1/3] Make CAP version upgrading work as recommended by cap spec --- irc/handlers.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/irc/handlers.go b/irc/handlers.go index ac8821bc..7270fb04 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -535,8 +535,12 @@ func capHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Respo if !client.registered { rb.session.capState = caps.NegotiatingState } - if len(msg.Params) > 1 && msg.Params[1] == "302" { - rb.session.capVersion = 302 + if 1 < len(msg.Params) { + num, err := strconv.Atoi(msg.Params[1]) + newVersion := caps.Version(num) + if err == nil && rb.session.capVersion < newVersion { + rb.session.capVersion = newVersion + } } // weechat 1.4 has a bug here where it won't accept the CAP reply unless it contains // the server.name source... otherwise it doesn't respond to the CAP message with From 22ed6bb1f1a6b2da4b5e9f528b332a1611c29dc1 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Sun, 28 Apr 2019 01:50:43 +1000 Subject: [PATCH 2/3] Detect cap-notify clients better (as recommended by cap spec) --- irc/client_lookup_set.go | 16 ++++++++++++++++ irc/server.go | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/irc/client_lookup_set.go b/irc/client_lookup_set.go index 8a585ffd..6bdf74d2 100644 --- a/irc/client_lookup_set.go +++ b/irc/client_lookup_set.go @@ -207,6 +207,22 @@ func (clients *ClientManager) AllWithCaps(capabs ...caps.Capability) (sessions [ return } +// AllWithCapsNotify returns all clients with the given capabilities, and that support cap-notify. +func (clients *ClientManager) AllWithCapsNotify(capabs ...caps.Capability) (sessions []*Session) { + clients.RLock() + defer clients.RUnlock() + for _, client := range clients.byNick { + for _, session := range client.Sessions() { + capabs = append(capabs, caps.CapNotify) + if session.capabilities.HasAll(capabs...) || 302 <= session.capVersion { + sessions = append(sessions, session) + } + } + } + + return +} + // FindAll returns all clients that match the given userhost mask. func (clients *ClientManager) FindAll(userhost string) (set ClientSet) { set = make(ClientSet) diff --git a/irc/server.go b/irc/server.go index e4d2aadb..27f8952e 100644 --- a/irc/server.go +++ b/irc/server.go @@ -744,7 +744,7 @@ func (server *Server) applyConfig(config *Config, initial bool) (err error) { removedCaps.Union(updatedCaps) if !addedCaps.Empty() || !removedCaps.Empty() { - capBurstSessions = server.clients.AllWithCaps(caps.CapNotify) + capBurstSessions = server.clients.AllWithCapsNotify() added[caps.Cap301] = addedCaps.String(caps.Cap301, CapValues) added[caps.Cap302] = addedCaps.String(caps.Cap302, CapValues) From 267c51bbbf13847ee2bc2eda60ef11573c5b9157 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Sun, 28 Apr 2019 15:57:42 +1000 Subject: [PATCH 3/3] Review fix --- irc/client_lookup_set.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/irc/client_lookup_set.go b/irc/client_lookup_set.go index 6bdf74d2..1982d968 100644 --- a/irc/client_lookup_set.go +++ b/irc/client_lookup_set.go @@ -209,11 +209,12 @@ func (clients *ClientManager) AllWithCaps(capabs ...caps.Capability) (sessions [ // AllWithCapsNotify returns all clients with the given capabilities, and that support cap-notify. func (clients *ClientManager) AllWithCapsNotify(capabs ...caps.Capability) (sessions []*Session) { + capabs = append(capabs, caps.CapNotify) clients.RLock() defer clients.RUnlock() for _, client := range clients.byNick { for _, session := range client.Sessions() { - capabs = append(capabs, caps.CapNotify) + // cap-notify is implicit in cap version 302 and above if session.capabilities.HasAll(capabs...) || 302 <= session.capVersion { sessions = append(sessions, session) }