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 /clients.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 'clients.go')
-rw-r--r-- | clients.go | 30 |
1 files changed, 21 insertions, 9 deletions
@@ -15,6 +15,7 @@ type Client struct { Ident string Gecos string Host string + Caps map[string]struct{} Server Server State ClientState } @@ -65,6 +66,7 @@ func NewLocalClient(conn *net.Conn) (*Client, error) { Server: self, State: ClientStatePreRegistration, Nick: "*", + Caps: make(map[string]struct{}), } for range 10 { uid_ := []byte(self.SID) @@ -86,22 +88,32 @@ func NewLocalClient(conn *net.Conn) (*Client, error) { } func (client *Client) checkRegistration() error { - if client.State != ClientStatePreRegistration { - slog.Error("spurious call to checkRegistration", "client", client) - return ErrCallState - } - if client.Nick != "*" && client.Ident != "" { - return client.Send(MakeMsg(self, RPL_WELCOME, client.Nick, "Welcome")) + switch client.State { + case ClientStatePreRegistration: + if client.Nick != "*" && client.Ident != "" { + client.State = ClientStateRegistered + return client.Send(MakeMsg(self, RPL_WELCOME, client.Nick, "Welcome")) + } + return nil // Incomplete for registration + case ClientStateCapabilitiesFinished: + if client.Nick != "*" && client.Ident != "" { + client.State = ClientStateRegistered + return client.Send(MakeMsg(self, RPL_WELCOME, client.Nick, "Welcome")) + } + return nil + default: + return nil } - return nil } type ClientState uint8 const ( - ClientStateRemote ClientState = iota - ClientStatePreRegistration + ClientStatePreRegistration ClientState = iota + ClientStateCapabilities + ClientStateCapabilitiesFinished ClientStateRegistered + ClientStateRemote ) var ( |