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.idletimer.Initialize(session)
|
||||||
session.resetFakelag()
|
session.resetFakelag()
|
||||||
|
|
||||||
for _, defaultMode := range config.Accounts.defaultUserModes {
|
ApplyUserModeChanges(client, config.Accounts.defaultUserModes, false, nil)
|
||||||
client.SetMode(defaultMode, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
if proxiedConn.Config.TLSConfig != nil {
|
if proxiedConn.Config.TLSConfig != nil {
|
||||||
client.SetMode(modes.TLS, true)
|
client.SetMode(modes.TLS, true)
|
||||||
@ -377,9 +375,7 @@ func (server *Server) AddAlwaysOnClient(account ClientAccount, chnames []string,
|
|||||||
alwaysOn: true,
|
alwaysOn: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, defaultMode := range config.Accounts.defaultUserModes {
|
ApplyUserModeChanges(client, config.Accounts.defaultUserModes, false, nil)
|
||||||
client.SetMode(defaultMode, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
client.SetMode(modes.TLS, true)
|
client.SetMode(modes.TLS, true)
|
||||||
client.writerSemaphore.Initialize(1)
|
client.writerSemaphore.Initialize(1)
|
||||||
|
@ -254,7 +254,7 @@ type AccountConfig struct {
|
|||||||
exemptedNets []net.IPNet
|
exemptedNets []net.IPNet
|
||||||
} `yaml:"require-sasl"`
|
} `yaml:"require-sasl"`
|
||||||
DefaultUserModes *string `yaml:"default-user-modes"`
|
DefaultUserModes *string `yaml:"default-user-modes"`
|
||||||
defaultUserModes modes.Modes
|
defaultUserModes modes.ModeChanges
|
||||||
LDAP ldap.ServerConfig
|
LDAP ldap.ServerConfig
|
||||||
LoginThrottling ThrottleConfig `yaml:"login-throttling"`
|
LoginThrottling ThrottleConfig `yaml:"login-throttling"`
|
||||||
SkipServerPassword bool `yaml:"skip-server-password"`
|
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.
|
// DefaultUserModes are set on all users when they login.
|
||||||
// this can be overridden in the `accounts` config, with the `default-user-modes` key
|
// 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.
|
// 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
|
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
|
// ParseDefaultChannelModes parses the `default-modes` line of the config
|
||||||
func ParseDefaultChannelModes(rawModes *string) modes.Modes {
|
func ParseDefaultChannelModes(rawModes *string) modes.Modes {
|
||||||
if rawModes == nil {
|
if rawModes == nil {
|
||||||
// not present in config, fall back to compile-time default
|
// not present in config, fall back to compile-time default
|
||||||
return DefaultChannelModes
|
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
|
// 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 {
|
if rawModes == nil {
|
||||||
// not present in config, fall back to compile-time default
|
// not present in config, fall back to compile-time default
|
||||||
return DefaultUserModes
|
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.
|
// ApplyChannelModeChanges applies a given set of mode changes.
|
||||||
|
@ -43,19 +43,19 @@ func TestParseDefaultUserModes(t *testing.T) {
|
|||||||
|
|
||||||
var parseTests = []struct {
|
var parseTests = []struct {
|
||||||
raw *string
|
raw *string
|
||||||
expected modes.Modes
|
expected modes.ModeChanges
|
||||||
}{
|
}{
|
||||||
{&iR, modes.Modes{modes.Invisible, modes.RegisteredOnly}},
|
{&iR, modes.ModeChanges{{Mode: modes.Invisible, Op: modes.Add}, {Mode: modes.RegisteredOnly, Op: modes.Add}}},
|
||||||
{&i, modes.Modes{modes.Invisible}},
|
{&i, modes.ModeChanges{{Mode: modes.Invisible, Op: modes.Add}}},
|
||||||
{&empty, modes.Modes{}},
|
{&empty, modes.ModeChanges{}},
|
||||||
{&rminusi, modes.Modes{modes.RegisteredOnly}},
|
{&rminusi, modes.ModeChanges{{Mode: modes.RegisteredOnly, Op: modes.Add}}},
|
||||||
{nil, modes.Modes{}},
|
{nil, modes.ModeChanges{}},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testcase := range parseTests {
|
for _, testcase := range parseTests {
|
||||||
result := ParseDefaultUserModes(testcase.raw)
|
result := ParseDefaultUserModes(testcase.raw)
|
||||||
if !reflect.DeepEqual(result, testcase.expected) {
|
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