source: code/trunk/bridge.go@ 772

Last change on this file since 772 was 764, checked in by contact, 3 years ago

Don't send RPL_NOTOPIC on JOIN

As per https://modern.ircdocs.horse/#join-message

File size: 2.4 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
[764]15 // RPL_NOTOPIC shouldn't be sent on JOIN
16 if ch.Topic != "" {
17 sendTopic(dc, ch)
18 }
[160]19 sendNames(dc, ch)
20}
21
22func sendTopic(dc *downstreamConn, ch *upstreamChannel) {
[260]23 downstreamName := dc.marshalEntity(ch.conn.network, ch.Name)
[69]24
[32]25 if ch.Topic != "" {
[54]26 dc.SendMessage(&irc.Message{
[32]27 Prefix: dc.srv.prefix(),
28 Command: irc.RPL_TOPIC,
[69]29 Params: []string{dc.nick, downstreamName, ch.Topic},
[54]30 })
[405]31 if ch.TopicWho != nil {
32 topicWho := dc.marshalUserPrefix(ch.conn.network, ch.TopicWho)
33 topicTime := strconv.FormatInt(ch.TopicTime.Unix(), 10)
34 dc.SendMessage(&irc.Message{
35 Prefix: dc.srv.prefix(),
36 Command: rpl_topicwhotime,
37 Params: []string{dc.nick, downstreamName, topicWho.String(), topicTime},
38 })
39 }
[32]40 } else {
[54]41 dc.SendMessage(&irc.Message{
[32]42 Prefix: dc.srv.prefix(),
43 Command: irc.RPL_NOTOPIC,
[69]44 Params: []string{dc.nick, downstreamName, "No topic is set"},
[54]45 })
[32]46 }
[140]47}
[32]48
[140]49func sendNames(dc *downstreamConn, ch *upstreamChannel) {
[260]50 downstreamName := dc.marshalEntity(ch.conn.network, ch.Name)
[140]51
[346]52 emptyNameReply := &irc.Message{
53 Prefix: dc.srv.prefix(),
54 Command: irc.RPL_NAMREPLY,
55 Params: []string{dc.nick, string(ch.Status), downstreamName, ""},
56 }
57 maxLength := maxMessageLength - len(emptyNameReply.String())
58
59 var buf strings.Builder
[478]60 for _, entry := range ch.Members.innerMap {
61 nick := entry.originalKey
62 memberships := entry.value.(*memberships)
[292]63 s := memberships.Format(dc) + dc.marshalEntity(ch.conn.network, nick)
[32]64
[349]65 n := buf.Len() + 1 + len(s)
66 if buf.Len() != 0 && n > maxLength {
[346]67 // There's not enough space for the next space + nick.
68 dc.SendMessage(&irc.Message{
69 Prefix: dc.srv.prefix(),
70 Command: irc.RPL_NAMREPLY,
71 Params: []string{dc.nick, string(ch.Status), downstreamName, buf.String()},
72 })
73 buf.Reset()
74 }
75
76 if buf.Len() != 0 {
77 buf.WriteByte(' ')
78 }
79 buf.WriteString(s)
80 }
81
82 if buf.Len() != 0 {
[54]83 dc.SendMessage(&irc.Message{
[32]84 Prefix: dc.srv.prefix(),
85 Command: irc.RPL_NAMREPLY,
[346]86 Params: []string{dc.nick, string(ch.Status), downstreamName, buf.String()},
[54]87 })
[32]88 }
89
[54]90 dc.SendMessage(&irc.Message{
[32]91 Prefix: dc.srv.prefix(),
92 Command: irc.RPL_ENDOFNAMES,
[69]93 Params: []string{dc.nick, downstreamName, "End of /NAMES list"},
[54]94 })
[32]95}
Note: See TracBrowser for help on using the repository browser.