diff --git a/irc/client_lookup_set.go b/irc/client_lookup_set.go index 6506741e..261461d9 100644 --- a/irc/client_lookup_set.go +++ b/irc/client_lookup_set.go @@ -203,6 +203,17 @@ func (set *UserMaskSet) Add(mask string) bool { return true } +func (set *UserMaskSet) AddAll(masks []string) (added bool) { + for _, mask := range masks { + if !added && !set.masks[mask] { + added = true + } + set.masks[mask] = true + } + set.setRegexp() + return +} + func (set *UserMaskSet) Remove(mask string) bool { if !set.masks[mask] { return false @@ -229,6 +240,12 @@ func (set *UserMaskSet) String() string { return strings.Join(masks, " ") } +// Generate a regular expression from the set of user mask +// strings. Masks are split at the two types of wildcards, `*` and +// `?`. All the pieces are meta-escaped. `*` is replaced with `.*`, +// the regexp equivalent. Likewise, `?` is replaced with `.`. The +// parts are re-joined and finally all masks are joined into a big +// or-expression. func (set *UserMaskSet) setRegexp() { if len(set.masks) == 0 { set.regexp = nil diff --git a/irc/server.go b/irc/server.go index 6d83fc50..652d1c5e 100644 --- a/irc/server.go +++ b/irc/server.go @@ -68,9 +68,7 @@ func loadChannelList(channel *Channel, list string, maskMode ChannelMode) { if list == "" { return } - for _, mask := range strings.Split(list, " ") { - channel.lists[maskMode].Add(mask) - } + channel.lists[maskMode].AddAll(strings.Split(list, " ")) } func (server *Server) loadChannels() {