2015-08-02 02:46:58 +00:00
|
|
|
package irc
|
|
|
|
|
|
|
|
import "sync"
|
|
|
|
|
2015-08-05 15:33:06 +00:00
|
|
|
// UserMode - RFC 1459 Section 4.2.3.2 and RFC 2812 Section 3.1.5
|
2015-08-02 02:46:58 +00:00
|
|
|
type UserMode rune
|
|
|
|
|
|
|
|
const (
|
|
|
|
UserModeAway UserMode = 'a'
|
|
|
|
UserModeInvisible UserMode = 'i'
|
|
|
|
UserModeWallOps UserMode = 'w'
|
|
|
|
UserModeRestricted UserMode = 'r'
|
|
|
|
UserModeOperator UserMode = 'o'
|
|
|
|
UserModeLocalOperator UserMode = 'O'
|
|
|
|
UserModeServerNotice UserMode = 's' //obsolete
|
|
|
|
)
|
|
|
|
|
2015-08-05 15:33:06 +00:00
|
|
|
// UserModes contains the supported User UserMode types
|
2015-08-02 02:46:58 +00:00
|
|
|
var UserModes = map[UserMode]interface{}{
|
|
|
|
UserModeAway: nil,
|
|
|
|
UserModeInvisible: nil,
|
|
|
|
UserModeWallOps: nil,
|
|
|
|
UserModeRestricted: nil,
|
|
|
|
UserModeOperator: nil,
|
|
|
|
UserModeLocalOperator: nil,
|
|
|
|
UserModeServerNotice: nil,
|
|
|
|
}
|
|
|
|
|
2015-08-05 15:33:06 +00:00
|
|
|
// UserModeSet provides means for storing and checking UserModes
|
2015-08-02 02:46:58 +00:00
|
|
|
type UserModeSet struct {
|
|
|
|
userModes map[UserMode]interface{}
|
2015-08-05 15:33:06 +00:00
|
|
|
mutex sync.RWMutex
|
2015-08-02 02:46:58 +00:00
|
|
|
}
|
|
|
|
|
2015-08-05 15:33:06 +00:00
|
|
|
// NewUserModeSet creates and returns a new UserModeSet
|
|
|
|
func NewUserModeSet() *UserModeSet {
|
2015-08-02 02:46:58 +00:00
|
|
|
u := UserModeSet{}
|
|
|
|
u.userModes = map[UserMode]interface{}{}
|
2015-08-05 15:33:06 +00:00
|
|
|
return &u
|
2015-08-02 02:46:58 +00:00
|
|
|
}
|
|
|
|
|
2015-08-05 15:33:06 +00:00
|
|
|
// AddMode adds a mode to the UserModeSet
|
2015-08-02 02:46:58 +00:00
|
|
|
func (u *UserModeSet) AddMode(mode UserMode) {
|
|
|
|
u.mutex.Lock()
|
|
|
|
defer u.mutex.Unlock()
|
|
|
|
u.userModes[mode] = nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-08-05 15:33:06 +00:00
|
|
|
// RemoveMode removes a mode from the UserModeSet
|
2015-08-02 02:46:58 +00:00
|
|
|
func (u *UserModeSet) RemoveMode(mode UserMode) {
|
|
|
|
u.mutex.Lock()
|
|
|
|
defer u.mutex.Unlock()
|
|
|
|
delete(u.userModes, mode)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-08-05 15:33:06 +00:00
|
|
|
// HasMode detects if a UserMode is contained in the UserModeSet
|
|
|
|
func (u *UserModeSet) HasMode(mode UserMode) bool {
|
|
|
|
u.mutex.RLock()
|
|
|
|
defer u.mutex.RUnlock()
|
|
|
|
_, found := u.userModes[mode]
|
|
|
|
return found
|
|
|
|
}
|
|
|
|
|
|
|
|
// String formats the UserModeString to be returned for MODE queries
|
2015-08-02 02:46:58 +00:00
|
|
|
func (u *UserModeSet) String() string {
|
|
|
|
s := ""
|
2015-08-05 15:33:06 +00:00
|
|
|
if len(u.userModes) > 0 {
|
|
|
|
s = "+"
|
|
|
|
}
|
|
|
|
for m := range u.userModes {
|
2015-08-02 02:46:58 +00:00
|
|
|
s += string(m)
|
|
|
|
}
|
|
|
|
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2015-08-05 15:33:06 +00:00
|
|
|
// ModeModifier - RFC 1459 Section 4.2.3 and RFC 2812 Section 3.1.5
|
2015-08-02 02:46:58 +00:00
|
|
|
type ModeModifier rune
|
|
|
|
|
|
|
|
const (
|
|
|
|
ModeModifierAdd ModeModifier = '+'
|
|
|
|
ModeModifierRemove ModeModifier = '-'
|
|
|
|
)
|
|
|
|
|
2015-08-05 15:33:06 +00:00
|
|
|
// ChannelMode - RFC 1459 Section 4.2.3.1 and RFC 2812 Section 3.2.3 and RFC 2811 Section 4
|
2015-08-02 02:46:58 +00:00
|
|
|
type ChannelMode rune
|
|
|
|
|
|
|
|
const (
|
|
|
|
ChannelModeCreator ChannelMode = 'O'
|
|
|
|
ChannelModeOperator ChannelMode = 'o'
|
|
|
|
ChannelModeVoice ChannelMode = 'v'
|
|
|
|
|
|
|
|
ChannelModeAnonymous ChannelMode = 'a'
|
|
|
|
ChannelModeInviteOnly ChannelMode = 'i'
|
|
|
|
ChannelModeModerated ChannelMode = 'm'
|
|
|
|
ChannelModeNoOutsideMessages ChannelMode = 'n'
|
|
|
|
ChannelModeQuiet ChannelMode = 'q'
|
|
|
|
ChannelModePrivate ChannelMode = 'p'
|
|
|
|
ChannelModeSecret ChannelMode = 's'
|
|
|
|
ChannelModeReOp ChannelMode = 'r'
|
|
|
|
ChannelModeTopic ChannelMode = 't'
|
|
|
|
|
|
|
|
ChannelModeKey ChannelMode = 'k'
|
|
|
|
ChannelModeLimit ChannelMode = 'l'
|
|
|
|
|
|
|
|
ChannelModeBan ChannelMode = 'b'
|
|
|
|
ChannelModeExceptionMask ChannelMode = 'e'
|
|
|
|
ChannelModeInvitationMask ChannelMode = 'I'
|
|
|
|
)
|
|
|
|
|
2015-08-05 15:33:06 +00:00
|
|
|
// ChannelModes contains the supported channel modes
|
|
|
|
// Currently supported modes are just those in RFC 1459
|
|
|
|
var ChannelModes = map[ChannelMode]interface{}{
|
|
|
|
//ChannelModeCreator: nil,
|
|
|
|
ChannelModeOperator: nil,
|
|
|
|
ChannelModeVoice: nil,
|
|
|
|
//ChannelModeAnonymous: nil,
|
|
|
|
ChannelModeInviteOnly: nil,
|
|
|
|
ChannelModeModerated: nil,
|
|
|
|
ChannelModeNoOutsideMessages: nil,
|
|
|
|
//ChannelModeQuiet: nil,
|
|
|
|
ChannelModePrivate: nil,
|
|
|
|
ChannelModeSecret: nil,
|
|
|
|
//ChannelModeReOp: nil,
|
|
|
|
ChannelModeTopic: nil,
|
|
|
|
ChannelModeKey: nil,
|
|
|
|
ChannelModeLimit: nil,
|
|
|
|
ChannelModeBan: nil,
|
|
|
|
//ChannelModeExceptionMask: nil,
|
|
|
|
//ChannelModeInvitationMask: nil,
|
|
|
|
}
|
|
|
|
|
|
|
|
// ChannelModeSet represents a set of active ChannelModes
|
2015-08-02 02:46:58 +00:00
|
|
|
type ChannelModeSet struct {
|
2015-08-05 15:33:06 +00:00
|
|
|
modes map[ChannelMode]interface{}
|
|
|
|
mutex sync.RWMutex
|
2015-08-02 02:46:58 +00:00
|
|
|
}
|
|
|
|
|
2015-08-05 15:33:06 +00:00
|
|
|
// NewChannelModeSet creates and returns a new ChannelModeSet
|
|
|
|
func NewChannelModeSet() *ChannelModeSet {
|
2015-08-02 02:46:58 +00:00
|
|
|
c := ChannelModeSet{}
|
2015-08-05 15:33:06 +00:00
|
|
|
c.modes = map[ChannelMode]interface{}{}
|
|
|
|
return &c
|
2015-08-02 02:46:58 +00:00
|
|
|
}
|
|
|
|
|
2015-08-05 15:33:06 +00:00
|
|
|
// AddMode adds a ChannelMode as active
|
2015-08-02 02:46:58 +00:00
|
|
|
func (c *ChannelModeSet) AddMode(mode ChannelMode) {
|
|
|
|
c.mutex.Lock()
|
|
|
|
defer c.mutex.Unlock()
|
2015-08-05 15:33:06 +00:00
|
|
|
c.modes[mode] = nil
|
2015-08-02 02:46:58 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-08-05 15:33:06 +00:00
|
|
|
// RemoveMode removes the given mode from the active set
|
2015-08-02 02:46:58 +00:00
|
|
|
func (c *ChannelModeSet) RemoveMode(mode ChannelMode) {
|
|
|
|
c.mutex.Lock()
|
|
|
|
defer c.mutex.Unlock()
|
2015-08-05 15:33:06 +00:00
|
|
|
delete(c.modes, mode)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// HasMode determines if the ChannelModeSet contains the given ChannelMode
|
|
|
|
func (c *ChannelModeSet) HasMode(mode ChannelMode) bool {
|
|
|
|
c.mutex.RLock()
|
|
|
|
defer c.mutex.RUnlock()
|
|
|
|
_, found := c.modes[mode]
|
|
|
|
return found
|
2015-08-02 02:46:58 +00:00
|
|
|
|
|
|
|
}
|
2015-08-05 15:33:06 +00:00
|
|
|
|
|
|
|
// String returns the ChannelModeSet formatted for the MODE queries
|
|
|
|
func (c *ChannelModeSet) String() string {
|
|
|
|
s := ""
|
|
|
|
if len(c.modes) > 0 {
|
|
|
|
s = "+"
|
|
|
|
}
|
|
|
|
for m := range c.modes {
|
|
|
|
s += string(m)
|
|
|
|
}
|
|
|
|
|
|
|
|
return s
|
|
|
|
}
|