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) + } +}