From da1b2cac2940eb1cf7f67328762fd5db5e1a0c8d Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 8 Dec 2024 10:04:03 +0800 Subject: Client teardown and proper nick changes --- clients.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'clients.go') diff --git a/clients.go b/clients.go index a181f99..53fd134 100644 --- a/clients.go +++ b/clients.go @@ -45,6 +45,18 @@ func (client Client) ServerSource() string { return client.UID } +func (client *Client) Teardown() { + if client.conn != nil { + (*client.conn).Close() + } + if !uidToClient.CompareAndDelete(client.UID, client) { + slog.Error("uid inconsistent", "uid", client.UID, "client", client) + } + if !nickToClient.CompareAndDelete(client.Nick, client) { + slog.Error("nick inconsistent", "nick", client.Nick, "client", client) + } +} + type ClientState uint8 const ( -- cgit v1.2.3