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
|
account string // RPL_LOGGEDIN/OUT state
|
||||||
|
|
||||||
capVersion int
|
capVersion int
|
||||||
caps capRegistry
|
caps xirc.CapRegistry
|
||||||
sasl *downstreamSASL // nil unless SASL is underway
|
sasl *downstreamSASL // nil unless SASL is underway
|
||||||
registration *downstreamRegistration // nil after RPL_WELCOME
|
registration *downstreamRegistration // nil after RPL_WELCOME
|
||||||
|
|
||||||
@ -346,7 +346,7 @@ func newDownstreamConn(srv *Server, ic ircConn, id uint64) *downstreamConn {
|
|||||||
nick: "*",
|
nick: "*",
|
||||||
nickCM: "*",
|
nickCM: "*",
|
||||||
username: "~u",
|
username: "~u",
|
||||||
caps: newCapRegistry(),
|
caps: xirc.NewCapRegistry(),
|
||||||
monitored: newCasemapMap(0),
|
monitored: newCasemapMap(0),
|
||||||
registration: new(downstreamRegistration),
|
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 {
|
func isNumeric(cmd string) bool {
|
||||||
if len(cmd) != 3 {
|
if len(cmd) != 3 {
|
||||||
return false
|
return false
|
||||||
|
@ -130,7 +130,7 @@ type upstreamConn struct {
|
|||||||
hostname string
|
hostname string
|
||||||
modes userModes
|
modes userModes
|
||||||
channels upstreamChannelCasemapMap
|
channels upstreamChannelCasemapMap
|
||||||
caps capRegistry
|
caps xirc.CapRegistry
|
||||||
batches map[string]batch
|
batches map[string]batch
|
||||||
away bool
|
away bool
|
||||||
account string
|
account string
|
||||||
@ -249,7 +249,7 @@ func connectToUpstream(ctx context.Context, network *network) (*upstreamConn, er
|
|||||||
network: network,
|
network: network,
|
||||||
user: network.user,
|
user: network.user,
|
||||||
channels: upstreamChannelCasemapMap{newCasemapMap(0)},
|
channels: upstreamChannelCasemapMap{newCasemapMap(0)},
|
||||||
caps: newCapRegistry(),
|
caps: xirc.NewCapRegistry(),
|
||||||
batches: make(map[string]batch),
|
batches: make(map[string]batch),
|
||||||
serverPrefix: &irc.Prefix{Name: "*"},
|
serverPrefix: &irc.Prefix{Name: "*"},
|
||||||
availableChannelTypes: stdChannelTypes,
|
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