Add user.forEachUpstream
This commit is contained in:
parent
3586ca3d26
commit
059a799d16
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/irc.v3"
|
||||
)
|
||||
@ -167,8 +168,9 @@ func (c *downstreamConn) handleMessageUnregistered(msg *irc.Message) error {
|
||||
}
|
||||
|
||||
func (c *downstreamConn) register() error {
|
||||
u := c.srv.getUser(c.username)
|
||||
u := c.srv.getUser(strings.TrimPrefix(c.username, "~"))
|
||||
if u == nil {
|
||||
c.logger.Printf("failed authentication: unknown username %q", c.username)
|
||||
c.messages <- &irc.Message{
|
||||
Prefix: c.srv.prefix(),
|
||||
Command: irc.ERR_PASSWDMISMATCH,
|
||||
@ -206,20 +208,14 @@ func (c *downstreamConn) register() error {
|
||||
Params: []string{c.nick, "No MOTD"},
|
||||
}
|
||||
|
||||
u.lock.Lock()
|
||||
for _, uc := range u.upstreamConns {
|
||||
u.forEachUpstream(func(uc *upstreamConn) {
|
||||
// TODO: fix races accessing upstream connection data
|
||||
if !uc.registered {
|
||||
continue
|
||||
}
|
||||
for _, ch := range uc.channels {
|
||||
if ch.complete {
|
||||
forwardChannel(c, ch)
|
||||
}
|
||||
}
|
||||
}
|
||||
u.lock.Unlock()
|
||||
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
|
11
server.go
11
server.go
@ -39,6 +39,17 @@ type user struct {
|
||||
upstreamConns []*upstreamConn
|
||||
}
|
||||
|
||||
func (u *user) forEachUpstream(f func(uc *upstreamConn)) {
|
||||
u.lock.Lock()
|
||||
for _, uc := range u.upstreamConns {
|
||||
if !uc.registered {
|
||||
continue
|
||||
}
|
||||
f(uc)
|
||||
}
|
||||
u.lock.Unlock()
|
||||
}
|
||||
|
||||
type Upstream struct {
|
||||
Addr string
|
||||
Nick string
|
||||
|
Loading…
Reference in New Issue
Block a user