From a81162e4a5f830339cfb143eeb951a57868c52b3 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 8 Dec 2024 12:40:41 +0800 Subject: NICK: Also delete old nick association when not fully registered --- cmd_nick.go | 8 ++++---- errors.go | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cmd_nick.go b/cmd_nick.go index 0d844b8..9ac3cd8 100644 --- a/cmd_nick.go +++ b/cmd_nick.go @@ -22,11 +22,11 @@ func handleClientNick(msg RMsg, client *Client) error { } } } else { + if !nickToClient.CompareAndDelete(client.Nick, client) { + slog.Error("nick inconsistent", "nick", client.Nick, "client", client) + return fmt.Errorf("%w: %v", ErrInconsistentClient, client) + } if client.State == ClientStateRegistered { - if !nickToClient.CompareAndDelete(client.Nick, client) { - slog.Error("nick inconsistent", "nick", client.Nick, "client", client) - return fmt.Errorf("%w: %v", ErrInconsistent, client) - } err := client.Send(MakeMsg(client, "NICK", msg.Params[0])) if err != nil { return err diff --git a/errors.go b/errors.go index 7c0a037..a65fdef 100644 --- a/errors.go +++ b/errors.go @@ -13,6 +13,8 @@ var ( ErrNotConnectedServer = errors.New("not connected server") ErrSendToSelf = errors.New("attempt to send message to self") ErrUIDBusy = errors.New("too many busy uids") - ErrInconsistent = errors.New("inconsistent state") ErrCallState = errors.New("invalid call state") + ErrInconsistentGlobal = errors.New("inconsistent global state") + ErrInconsistentClient = errors.New("inconsistent client state") + ErrRemoteClient = errors.New("operation not supported for a remote client") ) -- cgit v1.2.3