3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

fix CAP messages

This commit is contained in:
Jeremy Latt 2014-03-08 13:59:48 -08:00
parent f56db354ee
commit 33df043961
4 changed files with 26 additions and 16 deletions

View File

@ -23,7 +23,7 @@ var (
) )
const ( const (
SEM_VER = "ergonomadic-1.2.14" SEM_VER = "ergonomadic-1.2.15"
CRLF = "\r\n" CRLF = "\r\n"
MAX_REPLY_LEN = 512 - len(CRLF) MAX_REPLY_LEN = 512 - len(CRLF)

View File

@ -142,6 +142,10 @@ func RplKill(client *Client, target *Client, comment string) string {
"%s :%s", target.Nick(), comment) "%s :%s", target.Nick(), comment)
} }
func RplCap(client *Client, subCommand CapSubCommand, arg interface{}) string {
return NewStringReply(nil, CAP, "%s %s :%s", client.Nick(), subCommand, arg)
}
// numeric replies // numeric replies
func (target *Client) RplWelcome() { func (target *Client) RplWelcome() {

View File

@ -270,36 +270,28 @@ func (msg *CapCommand) HandleRegServer(server *Server) {
switch msg.subCommand { switch msg.subCommand {
case CAP_LS: case CAP_LS:
client.capState = CapNegotiating client.capState = CapNegotiating
client.Reply("CAP LS * :%s", SupportedCapabilities) client.Reply(RplCap(client, CAP_LS, SupportedCapabilities))
case CAP_LIST: case CAP_LIST:
client.Reply("CAP LIST * :%s", client.capabilities) client.Reply(RplCap(client, CAP_LIST, client.capabilities))
case CAP_REQ: case CAP_REQ:
client.capState = CapNegotiating client.capState = CapNegotiating
for capability := range msg.capabilities { for capability := range msg.capabilities {
if !SupportedCapabilities[capability] { if !SupportedCapabilities[capability] {
client.Reply("CAP NAK * :%s", msg.capabilities) client.Reply(RplCap(client, CAP_NAK, msg.capabilities))
return return
} }
} }
for capability := range msg.capabilities { for capability := range msg.capabilities {
client.capabilities[capability] = true client.capabilities[capability] = true
} }
client.Reply("CAP ACK * :%s", msg.capabilities) client.Reply(RplCap(client, CAP_ACK, msg.capabilities))
case CAP_CLEAR: case CAP_CLEAR:
format := strings.TrimRight( reply := RplCap(client, CAP_ACK, client.capabilities.DisableString())
strings.Repeat("%s%s ", len(client.capabilities)), " ") client.capabilities = make(CapabilitySet)
args := make([]interface{}, len(client.capabilities)) client.Reply(reply)
index := 0
for capability := range client.capabilities {
args[index] = Disable
args[index+1] = capability
index += 2
delete(client.capabilities, capability)
}
client.Reply("CAP ACK * :"+format, args...)
case CAP_END: case CAP_END:
client.capState = CapNegotiated client.capState = CapNegotiated

View File

@ -14,6 +14,10 @@ type CapSubCommand string
type Capability string type Capability string
func (capability Capability) String() string {
return string(capability)
}
type CapModifier rune type CapModifier rune
func (mod CapModifier) String() string { func (mod CapModifier) String() string {
@ -34,6 +38,16 @@ func (set CapabilitySet) String() string {
return strings.Join(strs, " ") return strings.Join(strs, " ")
} }
func (set CapabilitySet) DisableString() string {
parts := make([]string, len(set))
index := 0
for capability := range set {
parts[index] = Disable.String() + capability.String()
index += 1
}
return strings.Join(parts, " ")
}
// a string with wildcards // a string with wildcards
type Mask string type Mask string