source: code/trunk/bridge.go@ 150

Last change on this file since 150 was 140, checked in by delthas, 5 years ago

Add downstream NAMES support

NAMES reply for channels currently joined will be returned from cache;
requests for channels not joined will be forwarded from upstream.

File size: 1.2 KB
Line 
1package soju
2
3import (
4 "gopkg.in/irc.v3"
5)
6
7func forwardChannel(dc *downstreamConn, ch *upstreamChannel) {
8 if !ch.complete {
9 panic("Tried to forward a partial channel")
10 }
11
12 downstreamName := dc.marshalChannel(ch.conn, ch.Name)
13
14 if ch.Topic != "" {
15 dc.SendMessage(&irc.Message{
16 Prefix: dc.srv.prefix(),
17 Command: irc.RPL_TOPIC,
18 Params: []string{dc.nick, downstreamName, ch.Topic},
19 })
20 } else {
21 dc.SendMessage(&irc.Message{
22 Prefix: dc.srv.prefix(),
23 Command: irc.RPL_NOTOPIC,
24 Params: []string{dc.nick, downstreamName, "No topic is set"},
25 })
26 }
27
28 // TODO: rpl_topicwhotime
29 sendNames(dc, ch)
30}
31
32func sendNames(dc *downstreamConn, ch *upstreamChannel) {
33 // TODO: send multiple members in each message
34
35 downstreamName := dc.marshalChannel(ch.conn, ch.Name)
36
37 for nick, membership := range ch.Members {
38 s := membership.String() + dc.marshalNick(ch.conn, nick)
39
40 dc.SendMessage(&irc.Message{
41 Prefix: dc.srv.prefix(),
42 Command: irc.RPL_NAMREPLY,
43 Params: []string{dc.nick, string(ch.Status), downstreamName, s},
44 })
45 }
46
47 dc.SendMessage(&irc.Message{
48 Prefix: dc.srv.prefix(),
49 Command: irc.RPL_ENDOFNAMES,
50 Params: []string{dc.nick, downstreamName, "End of /NAMES list"},
51 })
52}
Note: See TracBrowser for help on using the repository browser.