3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 10:42:52 +01:00

Actually let the takeover work somewhat more properly

This commit is contained in:
Daniel Oaks 2018-01-21 12:39:09 +10:00
parent 0d5327de8a
commit 7760634efe

View File

@ -351,6 +351,9 @@ func (client *Client) TryResume() {
return
}
// unmark the new client's nick as being occupied
server.clients.removeInternal(client)
// send RESUMED to the reconnecting client
if timestamp == nil {
client.Send(nil, oldClient.NickMaskString(), "RESUMED", oldClient.nick, client.username, client.Hostname())
@ -402,7 +405,7 @@ func (client *Client) TryResume() {
server.clients.byNick[oldnick] = client
oldClient.destroy(false)
oldClient.destroy(true)
}
// IdleTime returns how long this client's been idle.
@ -602,12 +605,14 @@ func (client *Client) Quit(message string) {
// destroy gets rid of a client, removes them from server lists etc.
func (client *Client) destroy(beingResumed bool) {
// allow destroy() to execute at most once
client.stateMutex.Lock()
isDestroyed := client.isDestroyed
client.isDestroyed = true
client.stateMutex.Unlock()
if isDestroyed {
return
if !beingResumed {
client.stateMutex.Lock()
isDestroyed := client.isDestroyed
client.isDestroyed = true
client.stateMutex.Unlock()
if isDestroyed {
return
}
}
if beingResumed {
@ -647,18 +652,26 @@ func (client *Client) destroy(beingResumed bool) {
}
}
fmt.Println("2")
// clean up server
if !beingResumed {
client.server.clients.Remove(client)
}
fmt.Println("3")
// clean up self
if client.idletimer != nil {
client.idletimer.Stop()
}
fmt.Println("4")
client.socket.Close()
fmt.Println("5")
// send quit messages to friends
if !beingResumed {
for friend := range friends {