aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2024-12-08 10:13:58 +0800
committerRunxi Yu <me@runxiyu.org>2024-12-08 10:13:58 +0800
commit7fe8fe6c9fff814b88929026384f1851ff321781 (patch)
tree3e79a8579d06047519f1f19843dcc74579060970
parentClient teardown and proper nick changes (diff)
downloadmeseircd-7fe8fe6c9fff814b88929026384f1851ff321781.tar.gz
meseircd-7fe8fe6c9fff814b88929026384f1851ff321781.tar.zst
meseircd-7fe8fe6c9fff814b88929026384f1851ff321781.zip
Registration
-rw-r--r--clients.go13
-rw-r--r--cmd_nick.go3
-rw-r--r--cmd_user.go22
-rw-r--r--numerics.go4
-rw-r--r--servers.go2
5 files changed, 42 insertions, 2 deletions
diff --git a/clients.go b/clients.go
index 53fd134..15512c0 100644
--- a/clients.go
+++ b/clients.go
@@ -1,8 +1,8 @@
package main
import (
- "net"
"log/slog"
+ "net"
"sync"
)
@@ -11,6 +11,7 @@ type Client struct {
UID string
Nick string
Ident string
+ Gecos string
Host string
Server Server
State ClientState
@@ -57,6 +58,16 @@ func (client *Client) Teardown() {
}
}
+func (client *Client) checkRegistration() {
+ if client.State != ClientStatePreRegistration {
+ slog.Error("spurious call to checkRegistration", "client", client)
+ return // TODO: Return an error?
+ }
+ if client.Nick != "*" && client.Ident != "" {
+ client.Send(MakeMsg(self, RPL_WELCOME, client.Nick, "Welcome"))
+ }
+}
+
type ClientState uint8
const (
diff --git a/cmd_nick.go b/cmd_nick.go
index 89ee4d9..1c847e5 100644
--- a/cmd_nick.go
+++ b/cmd_nick.go
@@ -28,5 +28,8 @@ func handleClientNick(msg RMsg, client *Client) bool {
}
client.Nick = msg.Params[0]
}
+ if client.State == ClientStatePreRegistration {
+ client.checkRegistration()
+ }
return true
}
diff --git a/cmd_user.go b/cmd_user.go
new file mode 100644
index 0000000..99d9027
--- /dev/null
+++ b/cmd_user.go
@@ -0,0 +1,22 @@
+package main
+
+import (
+// "log/slog"
+)
+
+func init() {
+ commandHandlers["USER"] = handleClientUser
+}
+
+func handleClientUser(msg RMsg, client *Client) bool {
+ if len(msg.Params) < 4 {
+ client.Send(MakeMsg(self, ERR_NEEDMOREPARAMS, "USER", "Not enough parameters"))
+ return true
+ }
+ client.Ident = "~" + msg.Params[0]
+ client.Gecos = msg.Params[3]
+ if client.State == ClientStatePreRegistration {
+ client.checkRegistration()
+ }
+ return true
+}
diff --git a/numerics.go b/numerics.go
index 4af93dd..c8a351b 100644
--- a/numerics.go
+++ b/numerics.go
@@ -1,6 +1,10 @@
package main
const (
+ RPL_WELCOME = "001"
+)
+
+const (
ERR_UNKNOWNCOMMAND = "421"
ERR_INPUTTOOLONG = "417"
ERR_NEEDMOREPARAMS = "461"
diff --git a/servers.go b/servers.go
index 343be53..4cc8b31 100644
--- a/servers.go
+++ b/servers.go
@@ -1,8 +1,8 @@
package main
import (
- "net"
"log/slog"
+ "net"
)
type Server struct {