mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-22 11:59:40 +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]) {
|
switch strings.ToUpper(msg.Params[0]) {
|
||||||
case "GET":
|
case "GET":
|
||||||
reportPersistenceStatus(client, rb)
|
reportPersistenceStatus(client, rb, false)
|
||||||
case "SET":
|
case "SET":
|
||||||
if len(msg.Params) == 1 {
|
if len(msg.Params) == 1 {
|
||||||
goto fail
|
goto fail
|
||||||
@ -2626,10 +2626,12 @@ func persistenceHandler(server *Server, client *Client, msg ircmsg.Message, rb *
|
|||||||
goto fail
|
goto fail
|
||||||
}
|
}
|
||||||
|
|
||||||
|
broadcast := false
|
||||||
_, err := server.accounts.ModifyAccountSettings(account,
|
_, err := server.accounts.ModifyAccountSettings(account,
|
||||||
func(input AccountSettings) (output AccountSettings, err error) {
|
func(input AccountSettings) (output AccountSettings, err error) {
|
||||||
output = input
|
output = input
|
||||||
output.AlwaysOn = desiredSetting
|
output.AlwaysOn = desiredSetting
|
||||||
|
broadcast = output.AlwaysOn != input.AlwaysOn
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -2638,7 +2640,7 @@ func persistenceHandler(server *Server, client *Client, msg ircmsg.Message, rb *
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
reportPersistenceStatus(client, rb)
|
reportPersistenceStatus(client, rb, broadcast)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
goto fail
|
goto fail
|
||||||
@ -2651,7 +2653,7 @@ fail:
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func reportPersistenceStatus(client *Client, rb *ResponseBuffer) {
|
func reportPersistenceStatus(client *Client, rb *ResponseBuffer, broadcast bool) {
|
||||||
settings := client.AccountSettings()
|
settings := client.AccountSettings()
|
||||||
serverSetting := client.server.Config().Accounts.Multiclient.AlwaysOn
|
serverSetting := client.server.Config().Accounts.Multiclient.AlwaysOn
|
||||||
effectiveSetting := persistenceEnabled(serverSetting, settings.AlwaysOn)
|
effectiveSetting := persistenceEnabled(serverSetting, settings.AlwaysOn)
|
||||||
@ -2667,11 +2669,19 @@ func reportPersistenceStatus(client *Client, rb *ResponseBuffer) {
|
|||||||
return "*" // impossible
|
return "*" // impossible
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
storedSettingStr := toString(settings.AlwaysOn)
|
||||||
effectiveSettingStr := "OFF"
|
effectiveSettingStr := "OFF"
|
||||||
if effectiveSetting {
|
if effectiveSetting {
|
||||||
effectiveSettingStr = "ON"
|
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...]
|
// PING [params...]
|
||||||
|
@ -421,7 +421,7 @@ func (server *Server) playRegistrationBurst(session *Session) {
|
|||||||
rb := NewResponseBuffer(session)
|
rb := NewResponseBuffer(session)
|
||||||
server.RplISupport(c, rb)
|
server.RplISupport(c, rb)
|
||||||
if d.account != "" && session.capabilities.Has(caps.Persistence) {
|
if d.account != "" && session.capabilities.Has(caps.Persistence) {
|
||||||
reportPersistenceStatus(c, rb)
|
reportPersistenceStatus(c, rb, false)
|
||||||
}
|
}
|
||||||
server.Lusers(c, rb)
|
server.Lusers(c, rb)
|
||||||
server.MOTD(c, rb)
|
server.MOTD(c, rb)
|
||||||
|
Loading…
Reference in New Issue
Block a user