From 73bea0168df06875a0bb81e4560e2892c22ae96a Mon Sep 17 00:00:00 2001 From: Alex Jaspersen Date: Mon, 4 May 2020 02:14:55 +0000 Subject: [PATCH] Read account names and additional nicknames from the db to avoid casefolding issues. --- irc/accounts.go | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/irc/accounts.go b/irc/accounts.go index cb47a97a..d5cc962f 100644 --- a/irc/accounts.go +++ b/irc/accounts.go @@ -7,6 +7,7 @@ import ( "bytes" "encoding/json" "fmt" + "sort" "strconv" "strings" "sync" @@ -1047,15 +1048,37 @@ func (am *AccountManager) AuthenticateByPassphrase(client *Client, accountName s return err } -func (am *AccountManager) AllNicks() []string { - am.RLock() - defer am.RUnlock() +// AllNicks returns the uncasefolded nicknames for all accounts, including additional (grouped) nicks. +func (am *AccountManager) AllNicks() (result []string) { + // Account names + accountNamePrefix := fmt.Sprintf(keyAccountName, "") + am.server.store.View(func(tx *buntdb.Tx) error { + return tx.AscendGreaterOrEqual("", accountNamePrefix, func(key, value string) bool { + if !strings.HasPrefix(key, accountNamePrefix) { + return false + } + result = append(result, value) + return true + }) + }) - nicks := make([]string, 0, len(am.nickToAccount)) - for nick := range am.nickToAccount { - nicks = append(nicks, nick) - } - return nicks + // Additional nicknames + accountAdditionalNicksPrefix := fmt.Sprintf(keyAccountAdditionalNicks, "") + am.server.store.View(func(tx *buntdb.Tx) error { + return tx.AscendGreaterOrEqual("", accountAdditionalNicksPrefix, func(key, value string) bool { + if !strings.HasPrefix(key, accountAdditionalNicksPrefix) { + return false + } + additionalNicks := unmarshalReservedNicks(value) + for _, additionalNick := range additionalNicks { + result = append(result, additionalNick) + } + return true + }) + }) + + sort.Strings(result) + return } func (am *AccountManager) LoadAccount(accountName string) (result ClientAccount, err error) {