mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-22 10:42:52 +01:00
Call ApplyUserModeChanges for default user modes.
This ensures that counts like the number of invisible users are updated correctly.
This commit is contained in:
parent
93f1e5b5b8
commit
d5cec62df3
@ -326,9 +326,7 @@ func (server *Server) RunClient(conn IRCConn) {
|
||||
session.idletimer.Initialize(session)
|
||||
session.resetFakelag()
|
||||
|
||||
for _, defaultMode := range config.Accounts.defaultUserModes {
|
||||
client.SetMode(defaultMode, true)
|
||||
}
|
||||
ApplyUserModeChanges(client, config.Accounts.defaultUserModes, false, nil)
|
||||
|
||||
if proxiedConn.Config.TLSConfig != nil {
|
||||
client.SetMode(modes.TLS, true)
|
||||
@ -377,9 +375,7 @@ func (server *Server) AddAlwaysOnClient(account ClientAccount, chnames []string,
|
||||
alwaysOn: true,
|
||||
}
|
||||
|
||||
for _, defaultMode := range config.Accounts.defaultUserModes {
|
||||
client.SetMode(defaultMode, true)
|
||||
}
|
||||
ApplyUserModeChanges(client, config.Accounts.defaultUserModes, false, nil)
|
||||
|
||||
client.SetMode(modes.TLS, true)
|
||||
client.writerSemaphore.Initialize(1)
|
||||
|
@ -254,7 +254,7 @@ type AccountConfig struct {
|
||||
exemptedNets []net.IPNet
|
||||
} `yaml:"require-sasl"`
|
||||
DefaultUserModes *string `yaml:"default-user-modes"`
|
||||
defaultUserModes modes.Modes
|
||||
defaultUserModes modes.ModeChanges
|
||||
LDAP ldap.ServerConfig
|
||||
LoginThrottling ThrottleConfig `yaml:"login-throttling"`
|
||||
SkipServerPassword bool `yaml:"skip-server-password"`
|
||||
|
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.Modes{}
|
||||
DefaultUserModes = modes.ModeChanges{}
|
||||
)
|
||||
|
||||
// ApplyUserModeChanges applies the given changes, and returns the applied changes.
|
||||
@ -106,35 +106,32 @@ 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
|
||||
}
|
||||
return parseDefaultModes(*rawModes, modes.ParseChannelModeChanges)
|
||||
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
|
||||
}
|
||||
|
||||
// ParseDefaultUserModes parses the `default-user-modes` line of the config
|
||||
func ParseDefaultUserModes(rawModes *string) modes.Modes {
|
||||
func ParseDefaultUserModes(rawModes *string) modes.ModeChanges {
|
||||
if rawModes == nil {
|
||||
// not present in config, fall back to compile-time default
|
||||
return DefaultUserModes
|
||||
}
|
||||
return parseDefaultModes(*rawModes, modes.ParseUserModeChanges)
|
||||
modeChangeStrings := strings.Fields(*rawModes)
|
||||
modeChanges, _ := modes.ParseUserModeChanges(modeChangeStrings...)
|
||||
return modeChanges
|
||||
}
|
||||
|
||||
// ApplyChannelModeChanges applies a given set of mode changes.
|
||||
|
@ -43,19 +43,19 @@ func TestParseDefaultUserModes(t *testing.T) {
|
||||
|
||||
var parseTests = []struct {
|
||||
raw *string
|
||||
expected modes.Modes
|
||||
expected modes.ModeChanges
|
||||
}{
|
||||
{&iR, modes.Modes{modes.Invisible, modes.RegisteredOnly}},
|
||||
{&i, modes.Modes{modes.Invisible}},
|
||||
{&empty, modes.Modes{}},
|
||||
{&rminusi, modes.Modes{modes.RegisteredOnly}},
|
||||
{nil, modes.Modes{}},
|
||||
{&iR, modes.ModeChanges{{Mode: modes.Invisible, Op: modes.Add}, {Mode: modes.RegisteredOnly, Op: modes.Add}}},
|
||||
{&i, modes.ModeChanges{{Mode: modes.Invisible, Op: modes.Add}}},
|
||||
{&empty, modes.ModeChanges{}},
|
||||
{&rminusi, modes.ModeChanges{{Mode: modes.RegisteredOnly, Op: modes.Add}}},
|
||||
{nil, modes.ModeChanges{}},
|
||||
}
|
||||
|
||||
for _, testcase := range parseTests {
|
||||
result := ParseDefaultUserModes(testcase.raw)
|
||||
if !reflect.DeepEqual(result, testcase.expected) {
|
||||
t.Errorf("expected modes %s, got %s", testcase.expected, result)
|
||||
t.Errorf("expected modes %v, got %v", testcase.expected, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user