3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-11 06:29:29 +01:00

Merge pull request #1227 from slingamn/issue1225.2

fix #1225
This commit is contained in:
Shivaram Lingamneni 2020-08-06 01:19:39 -07:00 committed by GitHub
commit 55b21fa86c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 24 deletions

View File

@ -1124,14 +1124,21 @@ func (client *Client) SetVHost(vhost string) (updated bool) {
return
}
// updateNick updates `nick` and `nickCasefolded`.
func (client *Client) updateNick(nick, nickCasefolded, skeleton string) {
// SetNick gives the client a nickname and marks it as registered, if necessary
func (client *Client) SetNick(nick, nickCasefolded, skeleton string) (success bool) {
client.stateMutex.Lock()
defer client.stateMutex.Unlock()
if client.destroyed {
return false
} else if !client.registered {
// XXX test this before setting it to avoid annoying the race detector
client.registered = true
}
client.nick = nick
client.nickCasefolded = nickCasefolded
client.skeleton = skeleton
client.updateNickMaskNoMutex()
return true
}
// updateNickMaskNoMutex updates the casefolded nickname and nickmask, not acquiring any mutexes.

View File

@ -243,10 +243,12 @@ func (clients *ClientManager) SetNick(client *Client, session *Session, newNick
return "", errNicknameInUse, false
}
if changeSuccess := client.SetNick(newNick, newCfNick, newSkeleton); !changeSuccess {
return "", errClientDestroyed, false
}
clients.removeInternal(client)
clients.byNick[newCfNick] = client
clients.bySkeleton[newSkeleton] = client
client.updateNick(newNick, newCfNick, newSkeleton)
return newNick, nil, false
}

View File

@ -235,20 +235,15 @@ func (client *Client) Oper() *Oper {
return client.oper
}
func (client *Client) Registered() bool {
client.stateMutex.RLock()
defer client.stateMutex.RUnlock()
return client.registered
}
func (client *Client) SetRegistered() {
func (client *Client) Registered() (result bool) {
// `registered` is only written from the client's own goroutine, but may be
// read from other goroutines; therefore, the client's own goroutine may read
// the value without synchronization, but must write it with synchronization,
// and other goroutines must read it with synchronization
client.stateMutex.Lock()
client.registered = true
client.stateMutex.Unlock()
client.stateMutex.RLock()
result = client.registered
client.stateMutex.RUnlock()
return
}
func (client *Client) RawHostname() (result string) {

View File

@ -91,13 +91,11 @@ func performNickChange(server *Server, client *Client, target *Client, session *
channel.AddHistoryItem(histItem, details.account)
}
if target.Registered() {
newCfnick := target.NickCasefolded()
if newCfnick != details.nickCasefolded {
client.server.monitorManager.AlertAbout(details.nick, details.nickCasefolded, false)
client.server.monitorManager.AlertAbout(assignedNickname, newCfnick, true)
}
} // else: these will be deferred to the end of registration (see #572)
newCfnick := target.NickCasefolded()
if newCfnick != details.nickCasefolded {
client.server.monitorManager.AlertAbout(details.nick, details.nickCasefolded, false)
client.server.monitorManager.AlertAbout(assignedNickname, newCfnick, true)
}
return nil
}

View File

@ -283,12 +283,8 @@ func (server *Server) tryRegister(c *Client, session *Session) (exiting bool) {
c.SetMode(defaultMode, true)
}
// registration has succeeded:
c.SetRegistered()
// count new user in statistics
server.stats.Register(c.HasMode(modes.Invisible))
server.monitorManager.AlertAbout(c.Nick(), c.NickCasefolded(), true)
server.playRegistrationBurst(session)
return false