xirc: move over CapRegistry
This commit is contained in:
parent
fa6f52ed08
commit
9b37bd2eaa
@ -327,7 +327,7 @@ type downstreamConn struct {
|
||||
account string // RPL_LOGGEDIN/OUT state
|
||||
|
||||
capVersion int
|
||||
caps capRegistry
|
||||
caps xirc.CapRegistry
|
||||
sasl *downstreamSASL // nil unless SASL is underway
|
||||
registration *downstreamRegistration // nil after RPL_WELCOME
|
||||
|
||||
@ -346,7 +346,7 @@ func newDownstreamConn(srv *Server, ic ircConn, id uint64) *downstreamConn {
|
||||
nick: "*",
|
||||
nickCM: "*",
|
||||
username: "~u",
|
||||
caps: newCapRegistry(),
|
||||
caps: xirc.NewCapRegistry(),
|
||||
monitored: newCasemapMap(0),
|
||||
registration: new(downstreamRegistration),
|
||||
}
|
||||
|
35
irc.go
35
irc.go
@ -592,41 +592,6 @@ func generateWHOXReply(prefix *irc.Prefix, nick, fields string, info *whoxInfo)
|
||||
}
|
||||
}
|
||||
|
||||
type capRegistry struct {
|
||||
Available map[string]string
|
||||
Enabled map[string]struct{}
|
||||
}
|
||||
|
||||
func newCapRegistry() capRegistry {
|
||||
return capRegistry{
|
||||
Available: make(map[string]string),
|
||||
Enabled: make(map[string]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
func (cr *capRegistry) IsAvailable(name string) bool {
|
||||
_, ok := cr.Available[name]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (cr *capRegistry) IsEnabled(name string) bool {
|
||||
_, ok := cr.Enabled[name]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (cr *capRegistry) Del(name string) {
|
||||
delete(cr.Available, name)
|
||||
delete(cr.Enabled, name)
|
||||
}
|
||||
|
||||
func (cr *capRegistry) SetEnabled(name string, enabled bool) {
|
||||
if enabled {
|
||||
cr.Enabled[name] = struct{}{}
|
||||
} else {
|
||||
delete(cr.Enabled, name)
|
||||
}
|
||||
}
|
||||
|
||||
func isNumeric(cmd string) bool {
|
||||
if len(cmd) != 3 {
|
||||
return false
|
||||
|
@ -130,7 +130,7 @@ type upstreamConn struct {
|
||||
hostname string
|
||||
modes userModes
|
||||
channels upstreamChannelCasemapMap
|
||||
caps capRegistry
|
||||
caps xirc.CapRegistry
|
||||
batches map[string]batch
|
||||
away bool
|
||||
account string
|
||||
@ -249,7 +249,7 @@ func connectToUpstream(ctx context.Context, network *network) (*upstreamConn, er
|
||||
network: network,
|
||||
user: network.user,
|
||||
channels: upstreamChannelCasemapMap{newCasemapMap(0)},
|
||||
caps: newCapRegistry(),
|
||||
caps: xirc.NewCapRegistry(),
|
||||
batches: make(map[string]batch),
|
||||
serverPrefix: &irc.Prefix{Name: "*"},
|
||||
availableChannelTypes: stdChannelTypes,
|
||||
|
36
xirc/caps.go
Normal file
36
xirc/caps.go
Normal file
@ -0,0 +1,36 @@
|
||||
package xirc
|
||||
|
||||
type CapRegistry struct {
|
||||
Available map[string]string
|
||||
Enabled map[string]struct{}
|
||||
}
|
||||
|
||||
func NewCapRegistry() CapRegistry {
|
||||
return CapRegistry{
|
||||
Available: make(map[string]string),
|
||||
Enabled: make(map[string]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
func (cr *CapRegistry) IsAvailable(name string) bool {
|
||||
_, ok := cr.Available[name]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (cr *CapRegistry) IsEnabled(name string) bool {
|
||||
_, ok := cr.Enabled[name]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (cr *CapRegistry) Del(name string) {
|
||||
delete(cr.Available, name)
|
||||
delete(cr.Enabled, name)
|
||||
}
|
||||
|
||||
func (cr *CapRegistry) SetEnabled(name string, enabled bool) {
|
||||
if enabled {
|
||||
cr.Enabled[name] = struct{}{}
|
||||
} else {
|
||||
delete(cr.Enabled, name)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user