forked from External/ergo
Apply default user modes just before registration.
Previously, we were applying defaults before the user had completed registration. This meant that the number of invisible users was incremented when the user connected, and then the total was incremented when registration was completed. Now both counters are updated at the same time. If a user disconnects prior to registration, +i has not yet been applied so it would not be decremented.
This commit is contained in:
parent
c1d4c5596d
commit
0241e0c31d
6 changed files with 37 additions and 25 deletions
31
irc/modes.go
31
irc/modes.go
|
|
@ -23,7 +23,7 @@ var (
|
|||
|
||||
// DefaultUserModes are set on all users when they login.
|
||||
// this can be overridden in the `accounts` config, with the `default-user-modes` key
|
||||
DefaultUserModes = modes.ModeChanges{}
|
||||
DefaultUserModes = modes.Modes{}
|
||||
)
|
||||
|
||||
// ApplyUserModeChanges applies the given changes, and returns the applied changes.
|
||||
|
|
@ -110,32 +110,35 @@ func ApplyUserModeChanges(client *Client, changes modes.ModeChanges, force bool,
|
|||
return applied
|
||||
}
|
||||
|
||||
// parseDefaultModes uses the provided mode change parser to parse the rawModes.
|
||||
func parseDefaultModes(rawModes string, parser func(params ...string) (modes.ModeChanges, map[rune]bool)) modes.Modes {
|
||||
modeChangeStrings := strings.Fields(rawModes)
|
||||
modeChanges, _ := parser(modeChangeStrings...)
|
||||
defaultModes := make(modes.Modes, 0)
|
||||
for _, modeChange := range modeChanges {
|
||||
if modeChange.Op == modes.Add {
|
||||
defaultModes = append(defaultModes, modeChange.Mode)
|
||||
}
|
||||
}
|
||||
return defaultModes
|
||||
}
|
||||
|
||||
// ParseDefaultChannelModes parses the `default-modes` line of the config
|
||||
func ParseDefaultChannelModes(rawModes *string) modes.Modes {
|
||||
if rawModes == nil {
|
||||
// not present in config, fall back to compile-time default
|
||||
return DefaultChannelModes
|
||||
}
|
||||
modeChangeStrings := strings.Fields(*rawModes)
|
||||
modeChanges, _ := modes.ParseChannelModeChanges(modeChangeStrings...)
|
||||
defaultChannelModes := make(modes.Modes, 0)
|
||||
for _, modeChange := range modeChanges {
|
||||
if modeChange.Op == modes.Add {
|
||||
defaultChannelModes = append(defaultChannelModes, modeChange.Mode)
|
||||
}
|
||||
}
|
||||
return defaultChannelModes
|
||||
return parseDefaultModes(*rawModes, modes.ParseChannelModeChanges)
|
||||
}
|
||||
|
||||
// ParseDefaultUserModes parses the `default-user-modes` line of the config
|
||||
func ParseDefaultUserModes(rawModes *string) modes.ModeChanges {
|
||||
func ParseDefaultUserModes(rawModes *string) modes.Modes {
|
||||
if rawModes == nil {
|
||||
// not present in config, fall back to compile-time default
|
||||
return DefaultUserModes
|
||||
}
|
||||
modeChangeStrings := strings.Fields(*rawModes)
|
||||
modeChanges, _ := modes.ParseUserModeChanges(modeChangeStrings...)
|
||||
return modeChanges
|
||||
return parseDefaultModes(*rawModes, modes.ParseUserModeChanges)
|
||||
}
|
||||
|
||||
// #1021: channel key must be valid as a non-final parameter
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue