diff --git a/irc/accounts.go b/irc/accounts.go index 284e9d2e..cbb600be 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 { @@ -1482,6 +1482,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 8f102f30..e28fcbc9 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 aab52186..72fc10b2 100644 --- a/irc/nickserv.go +++ b/irc/nickserv.go @@ -923,7 +923,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 } @@ -1035,6 +1039,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 {