diff options
-rw-r--r-- | clients.go | 13 | ||||
-rw-r--r-- | cmd_nick.go | 3 | ||||
-rw-r--r-- | cmd_user.go | 22 | ||||
-rw-r--r-- | numerics.go | 4 | ||||
-rw-r--r-- | servers.go | 2 |
5 files changed, 42 insertions, 2 deletions
@@ -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" @@ -1,8 +1,8 @@ package main import ( - "net" "log/slog" + "net" ) type Server struct { |