mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-21 19:39:43 +01:00
add persistence broadcasting
This commit is contained in:
parent
893922afe0
commit
ae1de2554e
@ -2609,7 +2609,7 @@ func persistenceHandler(server *Server, client *Client, msg ircmsg.Message, rb *
|
||||
|
||||
switch strings.ToUpper(msg.Params[0]) {
|
||||
case "GET":
|
||||
reportPersistenceStatus(client, rb)
|
||||
reportPersistenceStatus(client, rb, false)
|
||||
case "SET":
|
||||
if len(msg.Params) == 1 {
|
||||
goto fail
|
||||
@ -2626,10 +2626,12 @@ func persistenceHandler(server *Server, client *Client, msg ircmsg.Message, rb *
|
||||
goto fail
|
||||
}
|
||||
|
||||
broadcast := false
|
||||
_, err := server.accounts.ModifyAccountSettings(account,
|
||||
func(input AccountSettings) (output AccountSettings, err error) {
|
||||
output = input
|
||||
output.AlwaysOn = desiredSetting
|
||||
broadcast = output.AlwaysOn != input.AlwaysOn
|
||||
return
|
||||
})
|
||||
if err != nil {
|
||||
@ -2638,7 +2640,7 @@ func persistenceHandler(server *Server, client *Client, msg ircmsg.Message, rb *
|
||||
return false
|
||||
}
|
||||
|
||||
reportPersistenceStatus(client, rb)
|
||||
reportPersistenceStatus(client, rb, broadcast)
|
||||
|
||||
default:
|
||||
goto fail
|
||||
@ -2651,7 +2653,7 @@ fail:
|
||||
return false
|
||||
}
|
||||
|
||||
func reportPersistenceStatus(client *Client, rb *ResponseBuffer) {
|
||||
func reportPersistenceStatus(client *Client, rb *ResponseBuffer, broadcast bool) {
|
||||
settings := client.AccountSettings()
|
||||
serverSetting := client.server.Config().Accounts.Multiclient.AlwaysOn
|
||||
effectiveSetting := persistenceEnabled(serverSetting, settings.AlwaysOn)
|
||||
@ -2667,11 +2669,19 @@ func reportPersistenceStatus(client *Client, rb *ResponseBuffer) {
|
||||
return "*" // impossible
|
||||
}
|
||||
}
|
||||
storedSettingStr := toString(settings.AlwaysOn)
|
||||
effectiveSettingStr := "OFF"
|
||||
if effectiveSetting {
|
||||
effectiveSettingStr = "ON"
|
||||
}
|
||||
rb.Add(nil, client.server.name, "PERSISTENCE", "STATUS", toString(settings.AlwaysOn), effectiveSettingStr)
|
||||
rb.Add(nil, client.server.name, "PERSISTENCE", "STATUS", storedSettingStr, effectiveSettingStr)
|
||||
if broadcast {
|
||||
for _, session := range client.Sessions() {
|
||||
if session != rb.session {
|
||||
session.Send(nil, client.server.name, "PERSISTENCE", "STATUS", storedSettingStr, effectiveSettingStr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PING [params...]
|
||||
|
@ -421,7 +421,7 @@ func (server *Server) playRegistrationBurst(session *Session) {
|
||||
rb := NewResponseBuffer(session)
|
||||
server.RplISupport(c, rb)
|
||||
if d.account != "" && session.capabilities.Has(caps.Persistence) {
|
||||
reportPersistenceStatus(c, rb)
|
||||
reportPersistenceStatus(c, rb, false)
|
||||
}
|
||||
server.Lusers(c, rb)
|
||||
server.MOTD(c, rb)
|
||||
|
Loading…
Reference in New Issue
Block a user