Changeset 346 in code for trunk


Ignore:
Timestamp:
Jun 30, 2020, 8:28:05 AM (5 years ago)
Author:
hubert
Message:

Send compact channel name lists

This commit resolves sendNames' TODO.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bridge.go

    r292 r346  
    33import (
    44        "gopkg.in/irc.v3"
     5        "strings"
    56)
    67
     
    3536
    3637func sendNames(dc *downstreamConn, ch *upstreamChannel) {
    37         // TODO: send multiple members in each message
    38 
    3938        downstreamName := dc.marshalEntity(ch.conn.network, ch.Name)
    4039
     40        emptyNameReply := &irc.Message{
     41                Prefix:  dc.srv.prefix(),
     42                Command: irc.RPL_NAMREPLY,
     43                Params:  []string{dc.nick, string(ch.Status), downstreamName, ""},
     44        }
     45        maxLength := maxMessageLength - len(emptyNameReply.String())
     46
     47        var buf strings.Builder
    4148        for nick, memberships := range ch.Members {
    4249                s := memberships.Format(dc) + dc.marshalEntity(ch.conn.network, nick)
    4350
     51                if buf.Len() != 0 && maxLength < buf.Len()+1+len(s) {
     52                        // There's not enough space for the next space + nick.
     53                        dc.SendMessage(&irc.Message{
     54                                Prefix:  dc.srv.prefix(),
     55                                Command: irc.RPL_NAMREPLY,
     56                                Params:  []string{dc.nick, string(ch.Status), downstreamName, buf.String()},
     57                        })
     58                        buf.Reset()
     59                }
     60
     61                if buf.Len() != 0 {
     62                        buf.WriteByte(' ')
     63                }
     64                buf.WriteString(s)
     65        }
     66
     67        if buf.Len() != 0 {
    4468                dc.SendMessage(&irc.Message{
    4569                        Prefix:  dc.srv.prefix(),
    4670                        Command: irc.RPL_NAMREPLY,
    47                         Params:  []string{dc.nick, string(ch.Status), downstreamName, s},
     71                        Params:  []string{dc.nick, string(ch.Status), downstreamName, buf.String()},
    4872                })
    4973        }
  • trunk/irc.go

    r303 r346  
    1616        err_invalidcapcmd = "410"
    1717)
     18
     19const maxMessageLength = 512
    1820
    1921type userModes string
Note: See TracChangeset for help on using the changeset viewer.