Store the channel-user modes of always-on clients along with their
channel memberships, restore them on server startup. This will coexist
alongside /CS AMODE, which autoapplies modes to clients on join regardless
of their always-on status.
This commit is contained in:
Shivaram Lingamneni 2020-12-02 03:56:00 -05:00
parent 3aeac42978
commit 51f279289d
4 changed files with 63 additions and 18 deletions

View file

@ -404,7 +404,7 @@ func (server *Server) RunClient(conn IRCConn) {
client.run(session)
}
func (server *Server) AddAlwaysOnClient(account ClientAccount, chnames []string, lastSeen map[string]time.Time, uModes modes.Modes, realname string) {
func (server *Server) AddAlwaysOnClient(account ClientAccount, channelToModes map[string]string, lastSeen map[string]time.Time, uModes modes.Modes, realname string) {
now := time.Now().UTC()
config := server.Config()
if lastSeen == nil && account.Settings.AutoreplayMissed {
@ -463,10 +463,15 @@ func (server *Server) AddAlwaysOnClient(account ClientAccount, chnames []string,
// XXX set this last to avoid confusing SetNick:
client.registered = true
for _, chname := range chnames {
for chname, modeStr := range channelToModes {
// XXX we're using isSajoin=true, to make these joins succeed even without channel key
// this is *probably* ok as long as the persisted memberships are accurate
server.channels.Join(client, chname, "", true, nil)
if channel := server.channels.Get(chname); channel != nil {
channel.setModesForClient(client, modeStr)
} else {
server.logger.Error("internal", "could not create channel", chname)
}
}
if persistenceEnabled(config.Accounts.Multiclient.AutoAway, client.accountSettings.AutoAway) {
@ -1967,11 +1972,12 @@ func (client *Client) performWrite(additionalDirtyBits uint) {
if (dirtyBits & IncludeChannels) != 0 {
channels := client.Channels()
channelNames := make([]string, len(channels))
for i, channel := range channels {
channelNames[i] = channel.Name()
channelToModes := make(map[string]string, len(channels))
for _, channel := range channels {
chname, modes := channel.nameAndModes(client)
channelToModes[chname] = modes
}
client.server.accounts.saveChannels(account, channelNames)
client.server.accounts.saveChannels(account, channelToModes)
}
if (dirtyBits & IncludeLastSeen) != 0 {
client.server.accounts.saveLastSeen(account, client.copyLastSeen())