Pass-through QUIT messages

This commit is contained in:
Simon Ser 2020-03-06 18:51:11 +01:00
parent 7883e8fa23
commit 2a1db4cb8d
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

View File

@ -190,6 +190,10 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
uc.channelModesWithParam = msg.Params[5] uc.channelModesWithParam = msg.Params[5]
} }
case "NICK": case "NICK":
if msg.Prefix == nil {
return fmt.Errorf("expected a prefix")
}
var newNick string var newNick string
if err := parseMessageParams(msg, &newNick); err != nil { if err := parseMessageParams(msg, &newNick); err != nil {
return err return err
@ -280,6 +284,28 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
}) })
}) })
} }
case "QUIT":
if msg.Prefix == nil {
return fmt.Errorf("expected a prefix")
}
if msg.Prefix.Name == uc.nick {
uc.logger.Printf("quit")
}
for _, ch := range uc.channels {
delete(ch.Members, msg.Prefix.Name)
}
if msg.Prefix.Name != uc.nick {
uc.forEachDownstream(func(dc *downstreamConn) {
dc.SendMessage(&irc.Message{
Prefix: dc.marshalUserPrefix(uc, msg.Prefix),
Command: "QUIT",
Params: msg.Params,
})
})
}
case irc.RPL_TOPIC, irc.RPL_NOTOPIC: case irc.RPL_TOPIC, irc.RPL_NOTOPIC:
var name, topic string var name, topic string
if err := parseMessageParams(msg, nil, &name, &topic); err != nil { if err := parseMessageParams(msg, nil, &name, &topic); err != nil {