Handle third-party JOIN and PART messages

This commit is contained in:
Simon Ser 2020-02-07 10:54:03 +01:00
parent 8493f5b255
commit bd54c57d71
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

View File

@ -135,13 +135,51 @@ func (c *upstreamConn) handleMessage(msg *irc.Message) error {
if len(msg.Params) < 1 {
return newNeedMoreParamsError(msg.Command)
}
for _, ch := range strings.Split(msg.Params[0], ",") {
if msg.Prefix.Name == c.upstream.Nick {
c.logger.Printf("joined channel %q", ch)
c.channels[ch] = &upstreamChannel{
Name: ch,
Members: make(map[string]membership),
}
} else {
ch, err := c.getChannel(ch)
if err != nil {
return err
}
ch.Members[msg.Prefix.Name] = 0
}
}
c.srv.lock.Lock()
for _, dc := range c.srv.downstreamConns {
dc.messages <- msg
}
c.srv.lock.Unlock()
case "PART":
if len(msg.Params) < 1 {
return newNeedMoreParamsError(msg.Command)
}
for _, ch := range strings.Split(msg.Params[0], ",") {
if msg.Prefix.Name == c.upstream.Nick {
c.logger.Printf("parted channel %q", ch)
delete(c.channels, ch)
} else {
ch, err := c.getChannel(ch)
if err != nil {
return err
}
delete(ch.Members, msg.Prefix.Name)
}
}
c.srv.lock.Lock()
for _, dc := range c.srv.downstreamConns {
dc.messages <- msg
}
c.srv.lock.Unlock()
case irc.RPL_TOPIC, irc.RPL_NOTOPIC:
if len(msg.Params) < 3 {
return newNeedMoreParamsError(msg.Command)
@ -210,6 +248,9 @@ func (c *upstreamConn) handleMessage(msg *irc.Message) error {
return err
}
if ch.complete {
return fmt.Errorf("received unexpected RPL_ENDOFNAMES")
}
ch.complete = true
c.srv.lock.Lock()