source: code/trunk/bridge.go@ 421

Last change on this file since 421 was 405, checked in by hubert, 5 years ago

Forward RPL_TOPICWHOTIME to downstreams

File size: 2.2 KB
RevLine 
[98]1package soju
[32]2
3import (
[405]4 "strconv"
5 "strings"
6
[32]7 "gopkg.in/irc.v3"
8)
9
10func forwardChannel(dc *downstreamConn, ch *upstreamChannel) {
11 if !ch.complete {
12 panic("Tried to forward a partial channel")
13 }
14
[160]15 sendTopic(dc, ch)
16 sendNames(dc, ch)
17}
18
19func sendTopic(dc *downstreamConn, ch *upstreamChannel) {
[260]20 downstreamName := dc.marshalEntity(ch.conn.network, ch.Name)
[69]21
[32]22 if ch.Topic != "" {
[54]23 dc.SendMessage(&irc.Message{
[32]24 Prefix: dc.srv.prefix(),
25 Command: irc.RPL_TOPIC,
[69]26 Params: []string{dc.nick, downstreamName, ch.Topic},
[54]27 })
[405]28 if ch.TopicWho != nil {
29 topicWho := dc.marshalUserPrefix(ch.conn.network, ch.TopicWho)
30 topicTime := strconv.FormatInt(ch.TopicTime.Unix(), 10)
31 dc.SendMessage(&irc.Message{
32 Prefix: dc.srv.prefix(),
33 Command: rpl_topicwhotime,
34 Params: []string{dc.nick, downstreamName, topicWho.String(), topicTime},
35 })
36 }
[32]37 } else {
[54]38 dc.SendMessage(&irc.Message{
[32]39 Prefix: dc.srv.prefix(),
40 Command: irc.RPL_NOTOPIC,
[69]41 Params: []string{dc.nick, downstreamName, "No topic is set"},
[54]42 })
[32]43 }
[140]44}
[32]45
[140]46func sendNames(dc *downstreamConn, ch *upstreamChannel) {
[260]47 downstreamName := dc.marshalEntity(ch.conn.network, ch.Name)
[140]48
[346]49 emptyNameReply := &irc.Message{
50 Prefix: dc.srv.prefix(),
51 Command: irc.RPL_NAMREPLY,
52 Params: []string{dc.nick, string(ch.Status), downstreamName, ""},
53 }
54 maxLength := maxMessageLength - len(emptyNameReply.String())
55
56 var buf strings.Builder
[292]57 for nick, memberships := range ch.Members {
58 s := memberships.Format(dc) + dc.marshalEntity(ch.conn.network, nick)
[32]59
[349]60 n := buf.Len() + 1 + len(s)
61 if buf.Len() != 0 && n > maxLength {
[346]62 // There's not enough space for the next space + nick.
63 dc.SendMessage(&irc.Message{
64 Prefix: dc.srv.prefix(),
65 Command: irc.RPL_NAMREPLY,
66 Params: []string{dc.nick, string(ch.Status), downstreamName, buf.String()},
67 })
68 buf.Reset()
69 }
70
71 if buf.Len() != 0 {
72 buf.WriteByte(' ')
73 }
74 buf.WriteString(s)
75 }
76
77 if buf.Len() != 0 {
[54]78 dc.SendMessage(&irc.Message{
[32]79 Prefix: dc.srv.prefix(),
80 Command: irc.RPL_NAMREPLY,
[346]81 Params: []string{dc.nick, string(ch.Status), downstreamName, buf.String()},
[54]82 })
[32]83 }
84
[54]85 dc.SendMessage(&irc.Message{
[32]86 Prefix: dc.srv.prefix(),
87 Command: irc.RPL_ENDOFNAMES,
[69]88 Params: []string{dc.nick, downstreamName, "End of /NAMES list"},
[54]89 })
[32]90}
Note: See TracBrowser for help on using the repository browser.