diff options
author | Runxi Yu <me@runxiyu.org> | 2024-12-08 13:57:25 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2024-12-08 13:57:25 +0800 |
commit | 6fdea28236771ee1d90a6fc959075c79939ad566 (patch) | |
tree | 0fd3e2f013729468b11d06d09283a92b98ae4358 /cmd_cap.go | |
parent | tags.go: Remove erroneous MIT SPDX-License-Identifier (diff) | |
download | meseircd-6fdea28236771ee1d90a6fc959075c79939ad566.tar.gz meseircd-6fdea28236771ee1d90a6fc959075c79939ad566.tar.zst meseircd-6fdea28236771ee1d90a6fc959075c79939ad566.zip |
CAP: Primitive negotiation
Diffstat (limited to 'cmd_cap.go')
-rw-r--r-- | cmd_cap.go | 35 |
1 files changed, 34 insertions, 1 deletions
@@ -16,13 +16,46 @@ func handleClientCap(msg RMsg, client *Client) error { } return nil } + if client.State == ClientStateRemote { + return ErrRemoteClient + } switch strings.ToUpper(msg.Params[0]) { case "LS": - err := client.Send(MakeMsg(self, "CAP", client.Nick, "LS", "sasl=PLAIN,EXTERNAL")) + if client.State == ClientStatePreRegistration { + client.State = ClientStateCapabilities + } + err := client.Send(MakeMsg(self, "CAP", client.Nick, "LS", capls)) + // TODO: Split when too long if err != nil { return err } case "REQ": + if client.State == ClientStatePreRegistration { + client.State = ClientStateCapabilities + } + caps := strings.Split(msg.Params[1], " ") + for _, c := range caps { + if c[0] == '-' { + // TODO: Remove capability + delete(client.Caps, c) + continue + } + _, ok := Caps[c] + if ok { + client.Send(MakeMsg(self, "CAP", client.Nick, "ACK", c)) + client.Caps[c] = struct{}{} + // TODO: This is terrible + } else { + client.Send(MakeMsg(self, "CAP", client.Nick, "NAK", c)) + } + } + case "END": + if client.State != ClientStateCapabilities { + // Just ignore it + return nil + } + client.State = ClientStateCapabilitiesFinished + client.checkRegistration() } return nil } |