Add downstream TOPIC support

This commit is contained in:
delthas 2020-03-26 00:19:45 +01:00 committed by Simon Ser
parent bab26c7a6f
commit a018f35c42
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 34 additions and 3 deletions

View File

@ -9,6 +9,13 @@ func forwardChannel(dc *downstreamConn, ch *upstreamChannel) {
panic("Tried to forward a partial channel") panic("Tried to forward a partial channel")
} }
sendTopic(dc, ch)
// TODO: rpl_topicwhotime
sendNames(dc, ch)
}
func sendTopic(dc *downstreamConn, ch *upstreamChannel) {
downstreamName := dc.marshalChannel(ch.conn, ch.Name) downstreamName := dc.marshalChannel(ch.conn, ch.Name)
if ch.Topic != "" { if ch.Topic != "" {
@ -24,9 +31,6 @@ func forwardChannel(dc *downstreamConn, ch *upstreamChannel) {
Params: []string{dc.nick, downstreamName, "No topic is set"}, Params: []string{dc.nick, downstreamName, "No topic is set"},
}) })
} }
// TODO: rpl_topicwhotime
sendNames(dc, ch)
} }
func sendNames(dc *downstreamConn, ch *upstreamChannel) { func sendNames(dc *downstreamConn, ch *upstreamChannel) {

View File

@ -1032,6 +1032,33 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
Params: params, Params: params,
}) })
} }
case "TOPIC":
var channel string
if err := parseMessageParams(msg, &channel); err != nil {
return err
}
uc, upstreamChannel, err := dc.unmarshalEntity(channel)
if err != nil {
return err
}
if len(msg.Params) > 1 { // setting topic
topic := msg.Params[1]
uc.SendMessage(&irc.Message{
Command: "TOPIC",
Params: []string{upstreamChannel, topic},
})
} else { // getting topic
ch, ok := uc.channels[upstreamChannel]
if !ok {
return ircError{&irc.Message{
Command: irc.ERR_NOSUCHCHANNEL,
Params: []string{dc.nick, upstreamChannel, "No such channel"},
}}
}
sendTopic(dc, ch)
}
case "NAMES": case "NAMES":
if len(msg.Params) == 0 { if len(msg.Params) == 0 {
dc.SendMessage(&irc.Message{ dc.SendMessage(&irc.Message{