Browse Source

comments and improvements for client set

tags/v0.1.0
Jeremy Latt 10 years ago
parent
commit
81df7b4a5c
2 changed files with 18 additions and 3 deletions
  1. 17
    0
      irc/client_lookup_set.go
  2. 1
    3
      irc/server.go

+ 17
- 0
irc/client_lookup_set.go View File

203
 	return true
203
 	return true
204
 }
204
 }
205
 
205
 
206
+func (set *UserMaskSet) AddAll(masks []string) (added bool) {
207
+	for _, mask := range masks {
208
+		if !added && !set.masks[mask] {
209
+			added = true
210
+		}
211
+		set.masks[mask] = true
212
+	}
213
+	set.setRegexp()
214
+	return
215
+}
216
+
206
 func (set *UserMaskSet) Remove(mask string) bool {
217
 func (set *UserMaskSet) Remove(mask string) bool {
207
 	if !set.masks[mask] {
218
 	if !set.masks[mask] {
208
 		return false
219
 		return false
229
 	return strings.Join(masks, " ")
240
 	return strings.Join(masks, " ")
230
 }
241
 }
231
 
242
 
243
+// Generate a regular expression from the set of user mask
244
+// strings. Masks are split at the two types of wildcards, `*` and
245
+// `?`. All the pieces are meta-escaped. `*` is replaced with `.*`,
246
+// the regexp equivalent. Likewise, `?` is replaced with `.`. The
247
+// parts are re-joined and finally all masks are joined into a big
248
+// or-expression.
232
 func (set *UserMaskSet) setRegexp() {
249
 func (set *UserMaskSet) setRegexp() {
233
 	if len(set.masks) == 0 {
250
 	if len(set.masks) == 0 {
234
 		set.regexp = nil
251
 		set.regexp = nil

+ 1
- 3
irc/server.go View File

68
 	if list == "" {
68
 	if list == "" {
69
 		return
69
 		return
70
 	}
70
 	}
71
-	for _, mask := range strings.Split(list, " ") {
72
-		channel.lists[maskMode].Add(mask)
73
-	}
71
+	channel.lists[maskMode].AddAll(strings.Split(list, " "))
74
 }
72
 }
75
 
73
 
76
 func (server *Server) loadChannels() {
74
 func (server *Server) loadChannels() {

Loading…
Cancel
Save