From 112722f1c8de842f6c8b672ea73b3cae182274ba Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 8 Dec 2024 09:49:40 +0800 Subject: Primitive nick registration --- cmd_nick.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 cmd_nick.go (limited to 'cmd_nick.go') diff --git a/cmd_nick.go b/cmd_nick.go new file mode 100644 index 0000000..ad68cc6 --- /dev/null +++ b/cmd_nick.go @@ -0,0 +1,22 @@ +package main + +func init() { + commandHandlers["NICK"] = handleClientNick +} + +func handleClientNick(msg RMsg, client *Client) bool { + if len(msg.Params) < 1 { + client.Send(MakeMsg(self, ERR_NEEDMOREPARAMS, "NICK", "Not enough parameters")) + return true + } + _, 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")) + } else { + client.Nick = msg.Params[0] + if client.State == ClientStateRegistered { + client.Send(MakeMsg(client, "NICK", msg.Params[0])) + } + } + return true +} -- cgit v1.2.3