diff options
author | Runxi Yu <me@runxiyu.org> | 2024-12-08 10:32:29 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2024-12-08 10:32:29 +0800 |
commit | 6bbe00f0c7aae6c468b1a3e12983a74a170e92b8 (patch) | |
tree | 970b43288cdbb8c05cf5df2aaaf79e94019d13af /cmd_nick.go | |
parent | Remove another unnecessary anonymous function (diff) | |
download | meseircd-6bbe00f0c7aae6c468b1a3e12983a74a170e92b8.tar.gz meseircd-6bbe00f0c7aae6c468b1a3e12983a74a170e92b8.tar.zst meseircd-6bbe00f0c7aae6c468b1a3e12983a74a170e92b8.zip |
Handle send failures
Diffstat (limited to 'cmd_nick.go')
-rw-r--r-- | cmd_nick.go | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/cmd_nick.go b/cmd_nick.go index 1c847e5..0d844b8 100644 --- a/cmd_nick.go +++ b/cmd_nick.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "log/slog" ) @@ -8,28 +9,36 @@ func init() { commandHandlers["NICK"] = handleClientNick } -func handleClientNick(msg RMsg, client *Client) bool { +func handleClientNick(msg RMsg, client *Client) error { if len(msg.Params) < 1 { - client.Send(MakeMsg(self, ERR_NEEDMOREPARAMS, "NICK", "Not enough parameters")) - return true + return client.Send(MakeMsg(self, ERR_NEEDMOREPARAMS, "NICK", "Not enough parameters")) } already, exists := nickToClient.LoadOrStore(msg.Params[0], client) if exists { if already != client { - client.Send(MakeMsg(self, ERR_NICKNAMEINUSE, client.Nick, msg.Params[0], "Nickname is already in use")) + err := client.Send(MakeMsg(self, ERR_NICKNAMEINUSE, client.Nick, msg.Params[0], "Nickname is already in use")) + if err != nil { + return err + } } } else { if client.State == ClientStateRegistered { if !nickToClient.CompareAndDelete(client.Nick, client) { slog.Error("nick inconsistent", "nick", client.Nick, "client", client) - return false + return fmt.Errorf("%w: %v", ErrInconsistent, client) + } + err := client.Send(MakeMsg(client, "NICK", msg.Params[0])) + if err != nil { + return err } - client.Send(MakeMsg(client, "NICK", msg.Params[0])) } client.Nick = msg.Params[0] } if client.State == ClientStatePreRegistration { - client.checkRegistration() + err := client.checkRegistration() + if err != nil { + return err + } } - return true + return nil } |