aboutsummaryrefslogtreecommitdiff
path: root/cmd_cap.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2024-12-08 13:57:25 +0800
committerRunxi Yu <me@runxiyu.org>2024-12-08 13:57:25 +0800
commit6fdea28236771ee1d90a6fc959075c79939ad566 (patch)
tree0fd3e2f013729468b11d06d09283a92b98ae4358 /cmd_cap.go
parenttags.go: Remove erroneous MIT SPDX-License-Identifier (diff)
downloadmeseircd-6fdea28236771ee1d90a6fc959075c79939ad566.tar.gz
meseircd-6fdea28236771ee1d90a6fc959075c79939ad566.tar.zst
meseircd-6fdea28236771ee1d90a6fc959075c79939ad566.zip
CAP: Primitive negotiation
Diffstat (limited to 'cmd_cap.go')
-rw-r--r--cmd_cap.go35
1 files changed, 34 insertions, 1 deletions
diff --git a/cmd_cap.go b/cmd_cap.go
index 328bce6..c1ddb1d 100644
--- a/cmd_cap.go
+++ b/cmd_cap.go
@@ -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
}