diff options
Diffstat (limited to 'cmd_nick.go')
-rw-r--r-- | cmd_nick.go | 22 |
1 files changed, 22 insertions, 0 deletions
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 +} |