Browse Source

Add support for setting user modes by default.

tags/v2.1.0-rc1
Alex Jaspersen 4 years ago
parent
commit
df9bf15f00
4 changed files with 40 additions and 8 deletions
  1. 4
    0
      irc/client.go
  2. 4
    0
      irc/config.go
  3. 26
    8
      irc/modes.go
  4. 6
    0
      oragono.yaml

+ 4
- 0
irc/client.go View File

@@ -318,6 +318,10 @@ func (server *Server) RunClient(conn clientConn, proxyLine string) {
318 318
 	session.idletimer.Initialize(session)
319 319
 	session.resetFakelag()
320 320
 
321
+	for _, defaultMode := range config.Accounts.defaultUserModes {
322
+		client.SetMode(defaultMode, true)
323
+	}
324
+
321 325
 	if conn.Config.TLSConfig != nil {
322 326
 		client.SetMode(modes.TLS, true)
323 327
 		// error is not useful to us here anyways so we can ignore it

+ 4
- 0
irc/config.go View File

@@ -261,6 +261,8 @@ type AccountConfig struct {
261 261
 		Exempted     []string
262 262
 		exemptedNets []net.IPNet
263 263
 	} `yaml:"require-sasl"`
264
+	DefaultUserModes   *string `yaml:"default-user-modes"`
265
+	defaultUserModes   modes.Modes
264 266
 	LDAP               ldap.ServerConfig
265 267
 	LoginThrottling    ThrottleConfig `yaml:"login-throttling"`
266 268
 	SkipServerPassword bool           `yaml:"skip-server-password"`
@@ -982,6 +984,8 @@ func LoadConfig(filename string) (config *Config, err error) {
982 984
 		}
983 985
 	}
984 986
 
987
+	config.Accounts.defaultUserModes = ParseDefaultUserModes(config.Accounts.DefaultUserModes)
988
+
985 989
 	config.Accounts.RequireSasl.exemptedNets, err = utils.ParseNetList(config.Accounts.RequireSasl.Exempted)
986 990
 	if err != nil {
987 991
 		return nil, fmt.Errorf("Could not parse require-sasl exempted nets: %v", err.Error())

+ 26
- 8
irc/modes.go View File

@@ -20,6 +20,10 @@ var (
20 20
 	DefaultChannelModes = modes.Modes{
21 21
 		modes.NoOutside, modes.OpOnlyTopic,
22 22
 	}
23
+
24
+	// DefaultUserModes are set on all users when they login.
25
+	// this can be overridden in the `server` config, with the `default-user-modes` key
26
+	DefaultUserModes = modes.Modes{}
23 27
 )
24 28
 
25 29
 // ApplyUserModeChanges applies the given changes, and returns the applied changes.
@@ -102,21 +106,35 @@ func ApplyUserModeChanges(client *Client, changes modes.ModeChanges, force bool,
102 106
 	return applied
103 107
 }
104 108
 
109
+// parseDefaultModes uses the provided mode change parser to parse the rawModes.
110
+func parseDefaultModes(rawModes string, parser func(params ...string) (modes.ModeChanges, map[rune]bool)) modes.Modes {
111
+	modeChangeStrings := strings.Fields(rawModes)
112
+	modeChanges, _ := parser(modeChangeStrings...)
113
+	defaultModes := make(modes.Modes, 0)
114
+	for _, modeChange := range modeChanges {
115
+		if modeChange.Op == modes.Add {
116
+			defaultModes = append(defaultModes, modeChange.Mode)
117
+		}
118
+	}
119
+	return defaultModes
120
+}
121
+
105 122
 // ParseDefaultChannelModes parses the `default-modes` line of the config
106 123
 func ParseDefaultChannelModes(rawModes *string) modes.Modes {
107 124
 	if rawModes == nil {
108 125
 		// not present in config, fall back to compile-time default
109 126
 		return DefaultChannelModes
110 127
 	}
111
-	modeChangeStrings := strings.Fields(*rawModes)
112
-	modeChanges, _ := modes.ParseChannelModeChanges(modeChangeStrings...)
113
-	defaultChannelModes := make(modes.Modes, 0)
114
-	for _, modeChange := range modeChanges {
115
-		if modeChange.Op == modes.Add {
116
-			defaultChannelModes = append(defaultChannelModes, modeChange.Mode)
117
-		}
128
+	return parseDefaultModes(*rawModes, modes.ParseChannelModeChanges)
129
+}
130
+
131
+// ParseDefaultUserModes parses the `default-user-modes` line of the config
132
+func ParseDefaultUserModes(rawModes *string) modes.Modes {
133
+	if rawModes == nil {
134
+		// not present in config, fall back to compile-time default
135
+		return DefaultUserModes
118 136
 	}
119
-	return defaultChannelModes
137
+	return parseDefaultModes(*rawModes, modes.ParseUserModeChanges)
120 138
 }
121 139
 
122 140
 // ApplyChannelModeChanges applies a given set of mode changes.

+ 6
- 0
oragono.yaml View File

@@ -451,6 +451,12 @@ accounts:
451 451
         offer-list:
452 452
             #- "oragono.test"
453 453
 
454
+    # modes that are set by default when a user connects
455
+    # if unset, no user modes will be set by default
456
+    # +i is invisible (a user's channels are hidden from whois replies)
457
+    # see  /QUOTE HELP umodes  for more user modes
458
+    # default-user-modes: +i
459
+
454 460
     # support for deferring password checking to an external LDAP server
455 461
     # you should probably ignore this section! consult the grafana docs for details:
456 462
     # https://grafana.com/docs/grafana/latest/auth/ldap/

Loading…
Cancel
Save