mirror of
https://github.com/ergochat/ergo.git
synced 2025-01-03 16:42:38 +01:00
RESUME: Fix a few bugs, play modestrings 'n' all
This commit is contained in:
parent
f8b39cfe61
commit
0569b5cfaa
@ -376,10 +376,12 @@ func (client *Client) TryResume() {
|
|||||||
|
|
||||||
// apply old client's details to new client
|
// apply old client's details to new client
|
||||||
client.nick = oldClient.nick
|
client.nick = oldClient.nick
|
||||||
|
client.updateNickMaskNoMutex()
|
||||||
|
|
||||||
for channel := range oldClient.channels {
|
for channel := range oldClient.channels {
|
||||||
channel.stateMutex.Lock()
|
channel.stateMutex.Lock()
|
||||||
|
|
||||||
|
client.channels[channel] = true
|
||||||
client.resumeDetails.SendFakeJoinsFor = append(client.resumeDetails.SendFakeJoinsFor, channel.name)
|
client.resumeDetails.SendFakeJoinsFor = append(client.resumeDetails.SendFakeJoinsFor, channel.name)
|
||||||
|
|
||||||
oldModeSet := channel.members[oldClient]
|
oldModeSet := channel.members[oldClient]
|
||||||
@ -387,6 +389,16 @@ func (client *Client) TryResume() {
|
|||||||
channel.members[client] = oldModeSet
|
channel.members[client] = oldModeSet
|
||||||
channel.regenerateMembersCache(true)
|
channel.regenerateMembersCache(true)
|
||||||
|
|
||||||
|
// construct fake modestring if necessary
|
||||||
|
oldModes := oldModeSet.String()
|
||||||
|
var params []string
|
||||||
|
if 0 < len(oldModes) {
|
||||||
|
params = []string{channel.name, "+" + oldModes}
|
||||||
|
for _ = range oldModes {
|
||||||
|
params = append(params, client.nick)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// send join for old clients
|
// send join for old clients
|
||||||
for member := range channel.members {
|
for member := range channel.members {
|
||||||
if member.capabilities.Has(caps.Resume) {
|
if member.capabilities.Has(caps.Resume) {
|
||||||
@ -399,7 +411,10 @@ func (client *Client) TryResume() {
|
|||||||
member.Send(nil, client.nickMaskString, "JOIN", channel.name)
|
member.Send(nil, client.nickMaskString, "JOIN", channel.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO(dan): send priv modes for fake new join
|
// send fake modestring if necessary
|
||||||
|
if 0 < len(oldModes) {
|
||||||
|
member.Send(nil, server.name, "MODE", params...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
channel.stateMutex.Unlock()
|
channel.stateMutex.Unlock()
|
||||||
@ -524,7 +539,11 @@ func (client *Client) updateNickMask(nick string) {
|
|||||||
|
|
||||||
client.stateMutex.Lock()
|
client.stateMutex.Lock()
|
||||||
defer client.stateMutex.Unlock()
|
defer client.stateMutex.Unlock()
|
||||||
|
client.updateNickMaskNoMutex()
|
||||||
|
}
|
||||||
|
|
||||||
|
// updateNickMask updates the casefolded nickname and nickmask, not holding any mutexes.
|
||||||
|
func (client *Client) updateNickMaskNoMutex() {
|
||||||
if len(client.vhost) > 0 {
|
if len(client.vhost) > 0 {
|
||||||
client.hostname = client.vhost
|
client.hostname = client.vhost
|
||||||
} else {
|
} else {
|
||||||
@ -609,13 +628,15 @@ func (client *Client) destroy(beingResumed bool) {
|
|||||||
// allow destroy() to execute at most once
|
// allow destroy() to execute at most once
|
||||||
if !beingResumed {
|
if !beingResumed {
|
||||||
client.stateMutex.Lock()
|
client.stateMutex.Lock()
|
||||||
|
}
|
||||||
isDestroyed := client.isDestroyed
|
isDestroyed := client.isDestroyed
|
||||||
client.isDestroyed = true
|
client.isDestroyed = true
|
||||||
|
if !beingResumed {
|
||||||
client.stateMutex.Unlock()
|
client.stateMutex.Unlock()
|
||||||
|
}
|
||||||
if isDestroyed {
|
if isDestroyed {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if beingResumed {
|
if beingResumed {
|
||||||
client.server.logger.Debug("quit", fmt.Sprintf("%s is being resumed", client.nick))
|
client.server.logger.Debug("quit", fmt.Sprintf("%s is being resumed", client.nick))
|
||||||
|
@ -463,6 +463,23 @@ func (server *Server) tryRegister(c *Client) {
|
|||||||
}
|
}
|
||||||
channel.SendTopic(c)
|
channel.SendTopic(c)
|
||||||
channel.Names(c)
|
channel.Names(c)
|
||||||
|
|
||||||
|
// construct and send fake modestring if necessary
|
||||||
|
c.stateMutex.RLock()
|
||||||
|
myModes := channel.members[c]
|
||||||
|
c.stateMutex.RUnlock()
|
||||||
|
if myModes == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
oldModes := myModes.String()
|
||||||
|
if 0 < len(oldModes) {
|
||||||
|
params := []string{channel.name, "+" + oldModes}
|
||||||
|
for _ = range oldModes {
|
||||||
|
params = append(params, c.nick)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Send(nil, server.name, "MODE", params...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user