mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
Merge pull request #929 from slingamn/verify_rename.1
enforce nick protection immediately after verification
This commit is contained in:
commit
ae2a92ca9a
@ -744,6 +744,7 @@ func (am *AccountManager) dispatchMailtoCallback(client *Client, account string,
|
||||
|
||||
func (am *AccountManager) Verify(client *Client, account string, code string) error {
|
||||
casefoldedAccount, err := CasefoldName(account)
|
||||
var skeleton string
|
||||
if err != nil || account == "" || account == "*" {
|
||||
return errAccountVerificationFailed
|
||||
}
|
||||
@ -814,7 +815,7 @@ func (am *AccountManager) Verify(client *Client, account string, code string) er
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
skeleton, _ := Skeleton(raw.Name)
|
||||
skeleton, _ = Skeleton(raw.Name)
|
||||
am.Lock()
|
||||
am.nickToAccount[casefoldedAccount] = casefoldedAccount
|
||||
am.skeletonToAccount[skeleton] = casefoldedAccount
|
||||
@ -839,6 +840,18 @@ func (am *AccountManager) Verify(client *Client, account string, code string) er
|
||||
if client != nil {
|
||||
am.Login(client, clientAccount)
|
||||
}
|
||||
_, method := am.EnforcementStatus(casefoldedAccount, skeleton)
|
||||
if method != NickEnforcementNone {
|
||||
currentClient := am.server.clients.Get(casefoldedAccount)
|
||||
if currentClient == nil || currentClient == client || currentClient.Account() == casefoldedAccount {
|
||||
return nil
|
||||
}
|
||||
if method == NickEnforcementStrict {
|
||||
am.server.RandomlyRename(currentClient)
|
||||
} else if method == NickEnforcementWithTimeout {
|
||||
currentClient.nickTimer.Touch(nil)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -98,6 +98,10 @@ func (server *Server) RandomlyRename(client *Client) {
|
||||
nick := strings.Replace(format, "*", utils.B32Encoder.EncodeToString(buf), -1)
|
||||
sessions := client.Sessions()
|
||||
if len(sessions) == 0 {
|
||||
// this can happen if they are anonymous and BRB (in general, an always-on
|
||||
// client has title to its nickname and will never be the victim of
|
||||
// a call to RandomlyRename)
|
||||
client.destroy(nil)
|
||||
return
|
||||
}
|
||||
// XXX arbitrarily pick the first session to receive error messages;
|
||||
|
Loading…
Reference in New Issue
Block a user