diff options
author | Runxi Yu <me@runxiyu.org> | 2024-12-08 10:04:03 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2024-12-08 10:04:03 +0800 |
commit | da1b2cac2940eb1cf7f67328762fd5db5e1a0c8d (patch) | |
tree | c033fa01658d3768236caacb696019551e1439b1 /cmd_nick.go | |
parent | Primitive nick registration (diff) | |
download | meseircd-da1b2cac2940eb1cf7f67328762fd5db5e1a0c8d.tar.gz meseircd-da1b2cac2940eb1cf7f67328762fd5db5e1a0c8d.tar.zst meseircd-da1b2cac2940eb1cf7f67328762fd5db5e1a0c8d.zip |
Client teardown and proper nick changes
Diffstat (limited to 'cmd_nick.go')
-rw-r--r-- | cmd_nick.go | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/cmd_nick.go b/cmd_nick.go index ad68cc6..89ee4d9 100644 --- a/cmd_nick.go +++ b/cmd_nick.go @@ -1,5 +1,9 @@ package main +import ( + "log/slog" +) + func init() { commandHandlers["NICK"] = handleClientNick } @@ -9,14 +13,20 @@ func handleClientNick(msg RMsg, client *Client) bool { client.Send(MakeMsg(self, ERR_NEEDMOREPARAMS, "NICK", "Not enough parameters")) return true } - _, exists := nickToClient.LoadOrStore(msg.Params[0], client) + already, exists := nickToClient.LoadOrStore(msg.Params[0], client) if exists { - client.Send(MakeMsg(self, ERR_NICKNAMEINUSE, client.Nick, msg.Params[0], "Nickname is already in use")) + if already != client { + client.Send(MakeMsg(self, ERR_NICKNAMEINUSE, client.Nick, msg.Params[0], "Nickname is already in use")) + } } else { - client.Nick = msg.Params[0] if client.State == ClientStateRegistered { + if !nickToClient.CompareAndDelete(client.Nick, client) { + slog.Error("nick inconsistent", "nick", client.Nick, "client", client) + return false + } client.Send(MakeMsg(client, "NICK", msg.Params[0])) } + client.Nick = msg.Params[0] } return true } |