diff options
author | Runxi Yu <me@runxiyu.org> | 2024-12-08 09:25:21 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2024-12-08 09:25:21 +0800 |
commit | 337995010159041aaf52b7749b46a0c0f55288d1 (patch) | |
tree | 373af2f37ebf26ceceea125405cd4b76ab02e2f7 /clients.go | |
parent | Make Client.conn optional (diff) | |
download | meseircd-337995010159041aaf52b7749b46a0c0f55288d1.tar.gz meseircd-337995010159041aaf52b7749b46a0c0f55288d1.tar.zst meseircd-337995010159041aaf52b7749b46a0c0f55288d1.zip |
Primitive client states
Diffstat (limited to 'clients.go')
-rw-r--r-- | clients.go | 21 |
1 files changed, 18 insertions, 3 deletions
@@ -2,6 +2,7 @@ package main import ( "net" + "log/slog" ) type Client struct { @@ -11,21 +12,27 @@ type Client struct { Ident string Host string Server Server + State ClientState } -func (client *Client) Send(msg SMsg) { - client.SendRaw(msg.ClientSerialize()) +func (client *Client) Send(msg SMsg) error { + return client.SendRaw(msg.ClientSerialize()) } // Send failures are not returned; broken connections detected and severed on // the next receive. -func (client *Client) SendRaw(s string) { +func (client *Client) SendRaw(s string) error { + if client.conn == nil { + panic("not implemented") + } + slog.Debug("send", "line", s, "conn", client.conn) _, err := (*client.conn).Write([]byte(s)) if err != nil { // TODO: Should shut down the netFd instead but the stdlib // doesn't expose a way to do this. (*client.conn).Close() } + return nil } func (client Client) ClientSource() string { @@ -36,3 +43,11 @@ func (client Client) ClientSource() string { func (client Client) ServerSource() string { return string(client.Server.SID[:]) + string(client.UID[:]) } + +type ClientState uint8 + +const ( + ClientStateRemote ClientState = iota + ClientStatePreRegistration + ClientStateRegistered +) |