|
@@ -306,7 +306,7 @@ func (server *Server) RunClient(conn clientConn, proxyLine string) {
|
306
|
306
|
client.run(session, proxyLine)
|
307
|
307
|
}
|
308
|
308
|
|
309
|
|
-func (server *Server) AddAlwaysOnClient(account ClientAccount, chnames []string) {
|
|
309
|
+func (server *Server) AddAlwaysOnClient(account ClientAccount, chnames []string, lastSignoff time.Time) {
|
310
|
310
|
now := time.Now().UTC()
|
311
|
311
|
config := server.Config()
|
312
|
312
|
|
|
@@ -322,7 +322,8 @@ func (server *Server) AddAlwaysOnClient(account ClientAccount, chnames []string)
|
322
|
322
|
rawHostname: server.name,
|
323
|
323
|
realIP: utils.IPv4LoopbackAddress,
|
324
|
324
|
|
325
|
|
- alwaysOn: true,
|
|
325
|
+ alwaysOn: true,
|
|
326
|
+ lastSignoff: lastSignoff,
|
326
|
327
|
}
|
327
|
328
|
|
328
|
329
|
client.SetMode(modes.TLS, true)
|
|
@@ -1187,10 +1188,17 @@ func (client *Client) destroy(session *Session) {
|
1187
|
1188
|
}
|
1188
|
1189
|
if alwaysOn && remainingSessions == 0 {
|
1189
|
1190
|
client.lastSignoff = lastSignoff
|
|
1191
|
+ client.dirtyBits |= IncludeLastSignoff
|
|
1192
|
+ } else {
|
|
1193
|
+ lastSignoff = time.Time{}
|
1190
|
1194
|
}
|
1191
|
1195
|
exitedSnomaskSent := client.exitedSnomaskSent
|
1192
|
1196
|
client.stateMutex.Unlock()
|
1193
|
1197
|
|
|
1198
|
+ if !lastSignoff.IsZero() {
|
|
1199
|
+ client.wakeWriter()
|
|
1200
|
+ }
|
|
1201
|
+
|
1194
|
1202
|
// destroy all applicable sessions:
|
1195
|
1203
|
var quitMessage string
|
1196
|
1204
|
for _, session := range sessionsToDestroy {
|
|
@@ -1573,6 +1581,7 @@ func (client *Client) historyStatus(config *Config) (persistent, ephemeral bool,
|
1573
|
1581
|
// TODO add a dirty flag for lastSignoff
|
1574
|
1582
|
const (
|
1575
|
1583
|
IncludeChannels uint = 1 << iota
|
|
1584
|
+ IncludeLastSignoff
|
1576
|
1585
|
)
|
1577
|
1586
|
|
1578
|
1587
|
func (client *Client) markDirty(dirtyBits uint) {
|
|
@@ -1609,7 +1618,7 @@ func (client *Client) writeLoop() {
|
1609
|
1618
|
|
1610
|
1619
|
func (client *Client) performWrite() {
|
1611
|
1620
|
client.stateMutex.Lock()
|
1612
|
|
- // TODO actually read dirtyBits in the future
|
|
1621
|
+ dirtyBits := client.dirtyBits
|
1613
|
1622
|
client.dirtyBits = 0
|
1614
|
1623
|
account := client.account
|
1615
|
1624
|
client.stateMutex.Unlock()
|
|
@@ -1619,10 +1628,18 @@ func (client *Client) performWrite() {
|
1619
|
1628
|
return
|
1620
|
1629
|
}
|
1621
|
1630
|
|
1622
|
|
- channels := client.Channels()
|
1623
|
|
- channelNames := make([]string, len(channels))
|
1624
|
|
- for i, channel := range channels {
|
1625
|
|
- channelNames[i] = channel.Name()
|
|
1631
|
+ if (dirtyBits & IncludeChannels) != 0 {
|
|
1632
|
+ channels := client.Channels()
|
|
1633
|
+ channelNames := make([]string, len(channels))
|
|
1634
|
+ for i, channel := range channels {
|
|
1635
|
+ channelNames[i] = channel.Name()
|
|
1636
|
+ }
|
|
1637
|
+ client.server.accounts.saveChannels(account, channelNames)
|
|
1638
|
+ }
|
|
1639
|
+ if (dirtyBits & IncludeLastSignoff) != 0 {
|
|
1640
|
+ client.stateMutex.RLock()
|
|
1641
|
+ lastSignoff := client.lastSignoff
|
|
1642
|
+ client.stateMutex.RUnlock()
|
|
1643
|
+ client.server.accounts.saveLastSignoff(account, lastSignoff)
|
1626
|
1644
|
}
|
1627
|
|
- client.server.accounts.saveChannels(account, channelNames)
|
1628
|
1645
|
}
|