From 519d19c364f9984214f5e962135489212ccbc2d0 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Sun, 10 Feb 2019 13:57:32 -0500 Subject: [PATCH] fix #364 --- irc/client.go | 14 +++++++++++--- irc/handlers.go | 3 ++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/irc/client.go b/irc/client.go index 8ebb2a5b..c0110764 100644 --- a/irc/client.go +++ b/irc/client.go @@ -824,7 +824,9 @@ func (client *Client) RplISupport(rb *ResponseBuffer) { } } -// Quit sets the given quit message for the client and tells the client to quit out. +// Quit sets the given quit message for the client. +// (You must ensure separately that destroy() is called, e.g., by returning `true` from +// the command handler or calling it yourself.) func (client *Client) Quit(message string) { client.stateMutex.Lock() alreadyQuit := client.isQuitting @@ -832,14 +834,20 @@ func (client *Client) Quit(message string) { client.isQuitting = true client.quitMessage = message } + registered := client.registered + prefix := client.nickMaskString client.stateMutex.Unlock() if alreadyQuit { return } - quitMsg := ircmsg.MakeMessage(nil, client.nickMaskString, "QUIT", message) - quitLine, _ := quitMsg.Line() + var quitLine string + // #364: don't send QUIT lines to unregistered clients + if registered { + quitMsg := ircmsg.MakeMessage(nil, prefix, "QUIT", message) + quitLine, _ = quitMsg.Line() + } errorMsg := ircmsg.MakeMessage(nil, "", "ERROR", message) errorLine, _ := errorMsg.Line() diff --git a/irc/handlers.go b/irc/handlers.go index 9eb20b72..740fc9a9 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -1996,6 +1996,7 @@ func operHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Resp } if !authorized { rb.Add(nil, server.name, ERR_PASSWDMISMATCH, client.nick, client.t("Password incorrect")) + client.Quit(client.t("Password incorrect")) return true } @@ -2059,7 +2060,7 @@ func passHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Resp password := []byte(msg.Params[0]) if bcrypt.CompareHashAndPassword(serverPassword, password) != nil { rb.Add(nil, server.name, ERR_PASSWDMISMATCH, client.nick, client.t("Password incorrect")) - rb.Add(nil, server.name, "ERROR", client.t("Password incorrect")) + client.Quit(client.t("Password incorrect")) return true }