mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-11 06:29:29 +01:00
clean up always-on state machine
This commit is contained in:
parent
dc90b3c910
commit
027886046c
@ -903,23 +903,6 @@ func (am *AccountManager) Verify(client *Client, account string, code string) er
|
|||||||
am.server.RandomlyRename(currentClient)
|
am.server.RandomlyRename(currentClient)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// #1216: we may have created an always-on client
|
|
||||||
if client == nil {
|
|
||||||
config := am.server.Config()
|
|
||||||
if persistenceEnabled(config.Accounts.Multiclient.AlwaysOn, PersistentUnspecified) {
|
|
||||||
accountData, err := am.LoadAccount(account)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
am.server.AddAlwaysOnClient(
|
|
||||||
accountData,
|
|
||||||
nil,
|
|
||||||
nil,
|
|
||||||
config.Accounts.defaultUserModes,
|
|
||||||
"",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1242,7 +1242,9 @@ func (client *Client) destroy(session *Session) {
|
|||||||
wasReattach := session != nil && session.client != client
|
wasReattach := session != nil && session.client != client
|
||||||
sessionRemoved := false
|
sessionRemoved := false
|
||||||
registered := client.registered
|
registered := client.registered
|
||||||
alwaysOn := client.alwaysOn
|
// XXX a temporary (reattaching) client can be marked alwaysOn when it logs in,
|
||||||
|
// but then the session attaches to another client and we need to clean it up here
|
||||||
|
alwaysOn := registered && client.alwaysOn
|
||||||
|
|
||||||
var remainingSessions int
|
var remainingSessions int
|
||||||
if session == nil {
|
if session == nil {
|
||||||
|
@ -203,7 +203,7 @@ func (client *Client) SetAway(away bool, awayMessage string) (changed bool) {
|
|||||||
|
|
||||||
func (client *Client) AlwaysOn() (alwaysOn bool) {
|
func (client *Client) AlwaysOn() (alwaysOn bool) {
|
||||||
client.stateMutex.Lock()
|
client.stateMutex.Lock()
|
||||||
alwaysOn = client.alwaysOn
|
alwaysOn = client.registered && client.alwaysOn
|
||||||
client.stateMutex.Unlock()
|
client.stateMutex.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -290,11 +290,8 @@ func (client *Client) Login(account ClientAccount) {
|
|||||||
client.account = account.NameCasefolded
|
client.account = account.NameCasefolded
|
||||||
client.accountName = account.Name
|
client.accountName = account.Name
|
||||||
client.accountSettings = account.Settings
|
client.accountSettings = account.Settings
|
||||||
// check `registered` to avoid incorrectly marking a temporary (pre-reattach),
|
// mark always-on here: it will not be respected until the client is registered
|
||||||
// SASL'ing client as always-on
|
|
||||||
if client.registered {
|
|
||||||
client.alwaysOn = alwaysOn
|
client.alwaysOn = alwaysOn
|
||||||
}
|
|
||||||
client.accountRegDate = account.RegisteredAt
|
client.accountRegDate = account.RegisteredAt
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -375,7 +372,7 @@ func (client *Client) SetMode(mode modes.Mode, on bool) bool {
|
|||||||
func (client *Client) SetRealname(realname string) {
|
func (client *Client) SetRealname(realname string) {
|
||||||
client.stateMutex.Lock()
|
client.stateMutex.Lock()
|
||||||
client.realname = realname
|
client.realname = realname
|
||||||
alwaysOn := client.alwaysOn
|
alwaysOn := client.registered && client.alwaysOn
|
||||||
client.stateMutex.Unlock()
|
client.stateMutex.Unlock()
|
||||||
if alwaysOn {
|
if alwaysOn {
|
||||||
client.markDirty(IncludeRealname)
|
client.markDirty(IncludeRealname)
|
||||||
|
Loading…
Reference in New Issue
Block a user