1
0
Fork 0
forked from External/ergo

initial implementation of bouncer functionality

This commit is contained in:
Shivaram Lingamneni 2019-04-12 00:08:46 -04:00
parent a8f04ecc4d
commit c2faeed4b5
19 changed files with 733 additions and 441 deletions

View file

@ -20,6 +20,16 @@ func NewSet(capabs ...Capability) *Set {
return &newSet
}
// NewCompleteSet returns a new Set, with all defined capabilities enabled.
func NewCompleteSet() *Set {
var newSet Set
asSlice := newSet[:]
for i := 0; i < numCapabs; i += 1 {
utils.BitsetSet(asSlice, uint(i), true)
}
return &newSet
}
// Enable enables the given capabilities.
func (s *Set) Enable(capabs ...Capability) {
asSlice := s[:]
@ -53,6 +63,16 @@ func (s *Set) Has(capab Capability) bool {
return utils.BitsetGet(s[:], uint(capab))
}
// HasAll returns true if the set has all the given capabilities.
func (s *Set) HasAll(capabs ...Capability) bool {
for _, capab := range capabs {
if !s.Has(capab) {
return false
}
}
return true
}
// Union adds all the capabilities of another set to this set.
func (s *Set) Union(other *Set) {
utils.BitsetUnion(s[:], other[:])
@ -94,3 +114,9 @@ func (s *Set) String(version Version, values *Values) string {
return strings.Join(strs, " ")
}
// returns whether we should send `znc.in/self-message`-style echo messages
// to sessions other than that which originated the message
func (capabs *Set) SelfMessagesEnabled() bool {
return capabs.Has(EchoMessage) || capabs.Has(ZNCSelfMessage)
}