3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-26 13:59:44 +01:00

Merge pull request #878 from slingamn/issue749_guest_again

fix double-application of guest prefix
This commit is contained in:
Shivaram Lingamneni 2020-03-19 02:34:24 -07:00 committed by GitHub
commit 1d228eaa92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -117,7 +117,7 @@ func (clients *ClientManager) Resume(oldClient *Client, session *Session) (err e
func (clients *ClientManager) SetNick(client *Client, session *Session, newNick string) (setNick string, err error) { func (clients *ClientManager) SetNick(client *Client, session *Session, newNick string) (setNick string, err error) {
config := client.server.Config() config := client.server.Config()
var newcfnick, newSkeleton string var newCfNick, newSkeleton string
client.stateMutex.RLock() client.stateMutex.RLock()
account := client.account account := client.account
@ -139,7 +139,7 @@ func (clients *ClientManager) SetNick(client *Client, session *Session, newNick
return "", errNickAccountMismatch return "", errNickAccountMismatch
} }
newNick = accountName newNick = accountName
newcfnick = account newCfNick = account
newSkeleton, err = Skeleton(newNick) newSkeleton, err = Skeleton(newNick)
if err != nil { if err != nil {
return "", errNicknameInvalid return "", errNicknameInvalid
@ -151,14 +151,23 @@ func (clients *ClientManager) SetNick(client *Client, session *Session, newNick
} }
if account == "" && config.Accounts.NickReservation.ForceGuestFormat { if account == "" && config.Accounts.NickReservation.ForceGuestFormat {
newNick = strings.Replace(config.Accounts.NickReservation.GuestFormat, "*", newNick, 1) newCfNick, err = CasefoldName(newNick)
}
newcfnick, err = CasefoldName(newNick)
if err != nil { if err != nil {
return "", errNicknameInvalid return "", errNicknameInvalid
} }
if len(newNick) > config.Limits.NickLen || len(newcfnick) > config.Limits.NickLen { if !config.Accounts.NickReservation.guestRegexpFolded.MatchString(newCfNick) {
newNick = strings.Replace(config.Accounts.NickReservation.GuestFormat, "*", newNick, 1)
newCfNick = "" // re-fold it below
}
}
if newCfNick == "" {
newCfNick, err = CasefoldName(newNick)
}
if err != nil {
return "", errNicknameInvalid
}
if len(newNick) > config.Limits.NickLen || len(newCfNick) > config.Limits.NickLen {
return "", errNicknameInvalid return "", errNicknameInvalid
} }
newSkeleton, err = Skeleton(newNick) newSkeleton, err = Skeleton(newNick)
@ -166,11 +175,11 @@ func (clients *ClientManager) SetNick(client *Client, session *Session, newNick
return "", errNicknameInvalid return "", errNicknameInvalid
} }
if restrictedCasefoldedNicks[newcfnick] || restrictedSkeletons[newSkeleton] { if restrictedCasefoldedNicks[newCfNick] || restrictedSkeletons[newSkeleton] {
return "", errNicknameInvalid return "", errNicknameInvalid
} }
reservedAccount, method := client.server.accounts.EnforcementStatus(newcfnick, newSkeleton) reservedAccount, method := client.server.accounts.EnforcementStatus(newCfNick, newSkeleton)
if method == NickEnforcementStrict && reservedAccount != "" && reservedAccount != account { if method == NickEnforcementStrict && reservedAccount != "" && reservedAccount != account {
return "", errNicknameReserved return "", errNicknameReserved
} }
@ -192,7 +201,7 @@ func (clients *ClientManager) SetNick(client *Client, session *Session, newNick
clients.Lock() clients.Lock()
defer clients.Unlock() defer clients.Unlock()
currentClient := clients.byNick[newcfnick] currentClient := clients.byNick[newCfNick]
// the client may just be changing case // the client may just be changing case
if currentClient != nil && currentClient != client && session != nil { if currentClient != nil && currentClient != client && session != nil {
// these conditions forbid reattaching to an existing session: // these conditions forbid reattaching to an existing session:
@ -225,9 +234,9 @@ func (clients *ClientManager) SetNick(client *Client, session *Session, newNick
} }
clients.removeInternal(client) clients.removeInternal(client)
clients.byNick[newcfnick] = client clients.byNick[newCfNick] = client
clients.bySkeleton[newSkeleton] = client clients.bySkeleton[newSkeleton] = client
client.updateNick(newNick, newcfnick, newSkeleton) client.updateNick(newNick, newCfNick, newSkeleton)
return newNick, nil return newNick, nil
} }