From 5ee0f1c205c1fe81130854f2b0eeb66023b5c862 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Thu, 14 Apr 2016 07:30:14 +1000 Subject: [PATCH] capability: Remove CAP CLEAR as per IRCv3 recommendations, allow CAP command after registration --- irc/capability.go | 49 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/irc/capability.go b/irc/capability.go index 3ec4d3f9..27c12c79 100644 --- a/irc/capability.go +++ b/irc/capability.go @@ -7,13 +7,12 @@ import ( type CapSubCommand string const ( - CAP_LS CapSubCommand = "LS" - CAP_LIST CapSubCommand = "LIST" - CAP_REQ CapSubCommand = "REQ" - CAP_ACK CapSubCommand = "ACK" - CAP_NAK CapSubCommand = "NAK" - CAP_CLEAR CapSubCommand = "CLEAR" - CAP_END CapSubCommand = "END" + CAP_LS CapSubCommand = "LS" + CAP_LIST CapSubCommand = "LIST" + CAP_REQ CapSubCommand = "REQ" + CAP_ACK CapSubCommand = "ACK" + CAP_NAK CapSubCommand = "NAK" + CAP_END CapSubCommand = "END" ) // Capabilities are optional features a client may request from a server. @@ -101,11 +100,6 @@ func (msg *CapCommand) HandleRegServer(server *Server) { } client.Reply(RplCap(client, CAP_ACK, msg.capabilities)) - case CAP_CLEAR: - reply := RplCap(client, CAP_ACK, client.capabilities.DisableString()) - client.capabilities = make(CapabilitySet) - client.Reply(reply) - case CAP_END: client.capState = CapNegotiated server.tryRegister(client) @@ -114,3 +108,34 @@ func (msg *CapCommand) HandleRegServer(server *Server) { client.ErrInvalidCapCmd(msg.subCommand) } } + +func (msg *CapCommand) HandleServer(server *Server) { + client := msg.Client() + + switch msg.subCommand { + case CAP_LS: + client.Reply(RplCap(client, CAP_LS, SupportedCapabilities)) + + case CAP_LIST: + client.Reply(RplCap(client, CAP_LIST, client.capabilities)) + + case CAP_REQ: + for capability := range msg.capabilities { + if !SupportedCapabilities[capability] { + client.Reply(RplCap(client, CAP_NAK, msg.capabilities)) + return + } + } + for capability := range msg.capabilities { + client.capabilities[capability] = true + } + client.Reply(RplCap(client, CAP_ACK, msg.capabilities)) + + case CAP_END: + // no-op after registration performed + return + + default: + client.ErrInvalidCapCmd(msg.subCommand) + } +}