Selaa lähdekoodia

comments and improvements for client set

tags/v0.1.0
Jeremy Latt 10 vuotta sitten
vanhempi
commit
81df7b4a5c
2 muutettua tiedostoa jossa 18 lisäystä ja 3 poistoa
  1. 17
    0
      irc/client_lookup_set.go
  2. 1
    3
      irc/server.go

+ 17
- 0
irc/client_lookup_set.go Näytä tiedosto

@@ -203,6 +203,17 @@ func (set *UserMaskSet) Add(mask string) bool {
203 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 217
 func (set *UserMaskSet) Remove(mask string) bool {
207 218
 	if !set.masks[mask] {
208 219
 		return false
@@ -229,6 +240,12 @@ func (set *UserMaskSet) String() string {
229 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 249
 func (set *UserMaskSet) setRegexp() {
233 250
 	if len(set.masks) == 0 {
234 251
 		set.regexp = nil

+ 1
- 3
irc/server.go Näytä tiedosto

@@ -68,9 +68,7 @@ func loadChannelList(channel *Channel, list string, maskMode ChannelMode) {
68 68
 	if list == "" {
69 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 74
 func (server *Server) loadChannels() {

Loading…
Peruuta
Tallenna