3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-23 03:02:48 +01:00

Merge remote-tracking branch 'origin/master' into issue996_proto.1

This commit is contained in:
Shivaram Lingamneni 2020-05-11 02:04:20 -04:00
commit 548a2f814a
5 changed files with 29 additions and 31 deletions

View File

@ -515,8 +515,13 @@ func channelUserModeHasPrivsOver(clientMode modes.Mode, targetMode modes.Mode) b
func (channel *Channel) ClientIsAtLeast(client *Client, permission modes.Mode) bool { func (channel *Channel) ClientIsAtLeast(client *Client, permission modes.Mode) bool {
channel.stateMutex.RLock() channel.stateMutex.RLock()
clientModes := channel.members[client] clientModes := channel.members[client]
founder := channel.registeredFounder
channel.stateMutex.RUnlock() channel.stateMutex.RUnlock()
if founder != "" && founder == client.Account() {
return true
}
for _, mode := range modes.ChannelUserModes { for _, mode := range modes.ChannelUserModes {
if clientModes.HasMode(mode) { if clientModes.HasMode(mode) {
return true return true

View File

@ -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.Secure { if proxiedConn.Secure {
client.SetMode(modes.TLS, true) client.SetMode(modes.TLS, true)
} }
@ -374,9 +372,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)

View File

@ -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"`

View File

@ -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.

View File

@ -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)
} }
} }
} }