capability: Remove CAP CLEAR as per IRCv3 recommendations, allow CAP command after registration

This commit is contained in:
Daniel Oaks 2016-04-14 07:30:14 +10:00
parent c3288823af
commit 5ee0f1c205
1 changed files with 37 additions and 12 deletions

View File

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