mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-22 11:59:40 +01:00
commit
55b21fa86c
@ -1124,14 +1124,21 @@ func (client *Client) SetVHost(vhost string) (updated bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateNick updates `nick` and `nickCasefolded`.
|
// SetNick gives the client a nickname and marks it as registered, if necessary
|
||||||
func (client *Client) updateNick(nick, nickCasefolded, skeleton string) {
|
func (client *Client) SetNick(nick, nickCasefolded, skeleton string) (success bool) {
|
||||||
client.stateMutex.Lock()
|
client.stateMutex.Lock()
|
||||||
defer client.stateMutex.Unlock()
|
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.nick = nick
|
||||||
client.nickCasefolded = nickCasefolded
|
client.nickCasefolded = nickCasefolded
|
||||||
client.skeleton = skeleton
|
client.skeleton = skeleton
|
||||||
client.updateNickMaskNoMutex()
|
client.updateNickMaskNoMutex()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateNickMaskNoMutex updates the casefolded nickname and nickmask, not acquiring any mutexes.
|
// updateNickMaskNoMutex updates the casefolded nickname and nickmask, not acquiring any mutexes.
|
||||||
|
@ -243,10 +243,12 @@ func (clients *ClientManager) SetNick(client *Client, session *Session, newNick
|
|||||||
return "", errNicknameInUse, false
|
return "", errNicknameInUse, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if changeSuccess := client.SetNick(newNick, newCfNick, newSkeleton); !changeSuccess {
|
||||||
|
return "", errClientDestroyed, false
|
||||||
|
}
|
||||||
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)
|
|
||||||
return newNick, nil, false
|
return newNick, nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,20 +235,15 @@ func (client *Client) Oper() *Oper {
|
|||||||
return client.oper
|
return client.oper
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) Registered() bool {
|
func (client *Client) Registered() (result bool) {
|
||||||
client.stateMutex.RLock()
|
|
||||||
defer client.stateMutex.RUnlock()
|
|
||||||
return client.registered
|
|
||||||
}
|
|
||||||
|
|
||||||
func (client *Client) SetRegistered() {
|
|
||||||
// `registered` is only written from the client's own goroutine, but may be
|
// `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
|
// read from other goroutines; therefore, the client's own goroutine may read
|
||||||
// the value without synchronization, but must write it with synchronization,
|
// the value without synchronization, but must write it with synchronization,
|
||||||
// and other goroutines must read it with synchronization
|
// and other goroutines must read it with synchronization
|
||||||
client.stateMutex.Lock()
|
client.stateMutex.RLock()
|
||||||
client.registered = true
|
result = client.registered
|
||||||
client.stateMutex.Unlock()
|
client.stateMutex.RUnlock()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) RawHostname() (result string) {
|
func (client *Client) RawHostname() (result string) {
|
||||||
|
@ -91,13 +91,11 @@ func performNickChange(server *Server, client *Client, target *Client, session *
|
|||||||
channel.AddHistoryItem(histItem, details.account)
|
channel.AddHistoryItem(histItem, details.account)
|
||||||
}
|
}
|
||||||
|
|
||||||
if target.Registered() {
|
newCfnick := target.NickCasefolded()
|
||||||
newCfnick := target.NickCasefolded()
|
if newCfnick != details.nickCasefolded {
|
||||||
if newCfnick != details.nickCasefolded {
|
client.server.monitorManager.AlertAbout(details.nick, details.nickCasefolded, false)
|
||||||
client.server.monitorManager.AlertAbout(details.nick, details.nickCasefolded, false)
|
client.server.monitorManager.AlertAbout(assignedNickname, newCfnick, true)
|
||||||
client.server.monitorManager.AlertAbout(assignedNickname, newCfnick, true)
|
}
|
||||||
}
|
|
||||||
} // else: these will be deferred to the end of registration (see #572)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,12 +283,8 @@ func (server *Server) tryRegister(c *Client, session *Session) (exiting bool) {
|
|||||||
c.SetMode(defaultMode, true)
|
c.SetMode(defaultMode, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// registration has succeeded:
|
|
||||||
c.SetRegistered()
|
|
||||||
|
|
||||||
// count new user in statistics
|
// count new user in statistics
|
||||||
server.stats.Register(c.HasMode(modes.Invisible))
|
server.stats.Register(c.HasMode(modes.Invisible))
|
||||||
server.monitorManager.AlertAbout(c.Nick(), c.NickCasefolded(), true)
|
|
||||||
|
|
||||||
server.playRegistrationBurst(session)
|
server.playRegistrationBurst(session)
|
||||||
return false
|
return false
|
||||||
|
Loading…
Reference in New Issue
Block a user