From b11dc1c84c17640bcc3d2ac9090472ce8119dc72 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Thu, 5 May 2022 01:04:28 -0400 Subject: [PATCH] fix #1886 Add more clarify in NS INFO and SAREGISTER about unregistered nicknames --- irc/accounts.go | 18 +++++++++++++++++- irc/errors.go | 1 + irc/handlers.go | 2 +- irc/nickserv.go | 8 +++++++- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/irc/accounts.go b/irc/accounts.go index ce5f0e41..f4edeaa8 100644 --- a/irc/accounts.go +++ b/irc/accounts.go @@ -433,7 +433,7 @@ func (am *AccountManager) Register(client *Client, account string, callbackNames // can't register an account with the same name as a registered nick if am.NickToAccount(account) != "" { - return errAccountAlreadyRegistered + return errNameReserved } return am.server.store.Update(func(tx *buntdb.Tx) error { @@ -1480,6 +1480,22 @@ func (am *AccountManager) LoadAccount(accountName string) (result ClientAccount, return } +func (am *AccountManager) accountWasUnregistered(accountName string) (result bool) { + casefoldedAccount, err := CasefoldName(accountName) + if err != nil { + return false + } + + unregisteredKey := fmt.Sprintf(keyAccountUnregistered, casefoldedAccount) + am.server.store.View(func(tx *buntdb.Tx) error { + if _, err := tx.Get(unregisteredKey); err == nil { + result = true + } + return nil + }) + return +} + // look up the unfolded version of an account name, possibly after deletion func (am *AccountManager) AccountToAccountName(account string) (result string) { casefoldedAccount, err := CasefoldName(account) diff --git a/irc/errors.go b/irc/errors.go index f308121a..34f7fcdb 100644 --- a/irc/errors.go +++ b/irc/errors.go @@ -74,6 +74,7 @@ var ( errRegisteredOnly = errors.New("Cannot join registered-only channel without an account") errValidEmailRequired = errors.New("A valid email address is required for account registration") errInvalidAccountRename = errors.New("Account renames can only change the casefolding of the account name") + errNameReserved = errors.New(`Name reserved due to a prior registration`) ) // String Errors diff --git a/irc/handlers.go b/irc/handlers.go index 0b5e470c..2fdece9c 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -69,7 +69,7 @@ func registrationErrorToMessage(config *Config, client *Client, err error) (mess } switch err { - case errAccountAlreadyRegistered, errAccountAlreadyVerified, errAccountAlreadyUnregistered, errAccountAlreadyLoggedIn, errAccountCreation, errAccountMustHoldNick, errAccountBadPassphrase, errCertfpAlreadyExists, errFeatureDisabled, errAccountBadPassphrase: + case errAccountAlreadyRegistered, errAccountAlreadyVerified, errAccountAlreadyUnregistered, errAccountAlreadyLoggedIn, errAccountCreation, errAccountMustHoldNick, errAccountBadPassphrase, errCertfpAlreadyExists, errFeatureDisabled, errAccountBadPassphrase, errNameReserved: message = err.Error() case errLimitExceeded: message = `There have been too many registration attempts recently; try again later` diff --git a/irc/nickserv.go b/irc/nickserv.go index 44139359..d2c7dd60 100644 --- a/irc/nickserv.go +++ b/irc/nickserv.go @@ -913,7 +913,11 @@ func nsInfoHandler(service *ircService, server *Server, client *Client, command account, err := server.accounts.LoadAccount(accountName) if err != nil || !account.Verified { - service.Notice(rb, client.t("Account does not exist")) + if server.accounts.accountWasUnregistered(accountName) { + service.Notice(rb, client.t("Name reserved due to a prior registration")) + } else { + service.Notice(rb, client.t("Account does not exist")) + } return } @@ -1025,6 +1029,8 @@ func nsSaregisterHandler(service *ircService, server *Server, client *Client, co var errMsg string if err == errAccountAlreadyRegistered || err == errAccountAlreadyVerified { errMsg = client.t("Account already exists") + } else if err == errNameReserved { + errMsg = client.t(err.Error()) } else if err == errAccountBadPassphrase { errMsg = client.t("Passphrase contains forbidden characters or is otherwise invalid") } else {