aboutsummaryrefslogtreecommitdiff
path: root/cmd_nick.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2024-12-08 09:49:40 +0800
committerRunxi Yu <me@runxiyu.org>2024-12-08 09:49:40 +0800
commit112722f1c8de842f6c8b672ea73b3cae182274ba (patch)
tree41cc23dc14b36c3c53b1dbb18cad7d334e9758af /cmd_nick.go
parentPrimitive client states (diff)
downloadmeseircd-112722f1c8de842f6c8b672ea73b3cae182274ba.tar.gz
meseircd-112722f1c8de842f6c8b672ea73b3cae182274ba.tar.zst
meseircd-112722f1c8de842f6c8b672ea73b3cae182274ba.zip
Primitive nick registration
Diffstat (limited to 'cmd_nick.go')
-rw-r--r--cmd_nick.go22
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
+}