Changeset 303 in code


Ignore:
Timestamp:
May 27, 2020, 9:48:08 PM (5 years ago)
Author:
delthas
Message:

Add support for TAGMSG and client message tags

Previously we dropped all TAGMSG as well as any client message tag sent
from downstream.

This adds support for properly forwarding TAGMSG and client message tags
from downstreams and upstreams.

TAGMSG messages are intentionally not logged, because they are currently
typically used for +typing, which can generate a lot of traffic and is
only useful for a few seconds after it is sent.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/downstream.go

    r301 r303  
    251251func (dc *downstreamConn) SendMessage(msg *irc.Message) {
    252252        if !dc.caps["message-tags"] {
     253                if msg.Command == "TAGMSG" {
     254                        return
     255                }
    253256                msg = msg.Copy()
    254257                for name := range msg.Tags {
     
    275278
    276279        switch msg.Command {
    277         case "PRIVMSG", "NOTICE":
     280        case "PRIVMSG", "NOTICE", "TAGMSG":
    278281                msg.Params[0] = dc.marshalEntity(net, msg.Params[0])
    279282        case "NICK":
     
    13981401                        return err
    13991402                }
     1403                tags := copyClientTags(msg.Tags)
    14001404
    14011405                for _, name := range strings.Split(targetsStr, ",") {
     
    14191423                        }
    14201424                        uc.SendMessageLabeled(dc.id, &irc.Message{
     1425                                Tags:    tags,
    14211426                                Command: "PRIVMSG",
    14221427                                Params:  []string{upstreamName, unmarshaledText},
    14231428                        })
    14241429
     1430                        echoTags := tags.Copy()
     1431                        echoTags["time"] = irc.TagValue(time.Now().UTC().Format(serverTimeLayout))
    14251432                        echoMsg := &irc.Message{
    1426                                 Tags: irc.Tags{
    1427                                         "time": irc.TagValue(time.Now().UTC().Format(serverTimeLayout)),
    1428                                 },
     1433                                Tags: echoTags,
    14291434                                Prefix: &irc.Prefix{
    14301435                                        Name: uc.nick,
     
    14411446                        return err
    14421447                }
     1448                tags := copyClientTags(msg.Tags)
    14431449
    14441450                for _, name := range strings.Split(targetsStr, ",") {
     
    14531459                        }
    14541460                        uc.SendMessageLabeled(dc.id, &irc.Message{
     1461                                Tags:    tags,
    14551462                                Command: "NOTICE",
    14561463                                Params:  []string{upstreamName, unmarshaledText},
     1464                        })
     1465                }
     1466        case "TAGMSG":
     1467                var targetsStr string
     1468                if err := parseMessageParams(msg, &targetsStr); err != nil {
     1469                        return err
     1470                }
     1471                tags := copyClientTags(msg.Tags)
     1472
     1473                for _, name := range strings.Split(targetsStr, ",") {
     1474                        uc, upstreamName, err := dc.unmarshalEntity(name)
     1475                        if err != nil {
     1476                                return err
     1477                        }
     1478
     1479                        uc.SendMessageLabeled(dc.id, &irc.Message{
     1480                                Tags:    tags,
     1481                                Command: "TAGMSG",
     1482                                Params:  []string{upstreamName},
    14571483                        })
    14581484                }
  • trunk/irc.go

    r293 r303  
    275275}
    276276
     277func copyClientTags(tags irc.Tags) irc.Tags {
     278        t := make(irc.Tags, len(tags))
     279        for k, v := range tags {
     280                if strings.HasPrefix(k, "+") {
     281                        t[k] = v
     282                }
     283        }
     284        return t
     285}
     286
    277287type batch struct {
    278288        Type   string
  • trunk/upstream.go

    r302 r303  
    321321                })
    322322                return nil
    323         case "NOTICE", "PRIVMSG":
     323        case "NOTICE", "PRIVMSG", "TAGMSG":
    324324                if msg.Prefix == nil {
    325325                        return fmt.Errorf("expected a prefix")
     
    327327
    328328                var entity, text string
    329                 if err := parseMessageParams(msg, &entity, &text); err != nil {
    330                         return err
     329                if msg.Command != "TAGMSG" {
     330                        if err := parseMessageParams(msg, &entity, &text); err != nil {
     331                                return err
     332                        }
     333                } else {
     334                        if err := parseMessageParams(msg, &entity); err != nil {
     335                                return err
     336                        }
    331337                }
    332338
     
    342348                if msg.Prefix.User == "" && msg.Prefix.Host == "" { // server message
    343349                        uc.produce("", msg, nil)
    344                 } else { // regular user NOTICE or PRIVMSG
     350                } else { // regular user message
    345351                        target := entity
    346352                        if target == uc.nick {
     
    12751281                        })
    12761282                }
    1277         case "TAGMSG":
    1278                 // TODO: relay to downstream connections that accept message-tags
    12791283        case "ACK":
    12801284                // Ignore
     
    14881492}
    14891493
     1494func (uc *upstreamConn) SendMessage(msg *irc.Message) {
     1495        if !uc.caps["message-tags"] {
     1496                msg = msg.Copy()
     1497                msg.Tags = nil
     1498        }
     1499
     1500        uc.conn.SendMessage(msg)
     1501}
     1502
    14901503func (uc *upstreamConn) SendMessageLabeled(downstreamID uint64, msg *irc.Message) {
    14911504        if uc.caps["labeled-response"] {
Note: See TracChangeset for help on using the changeset viewer.