Changeset 293 in code for trunk/upstream.go


Ignore:
Timestamp:
May 21, 2020, 8:36:54 PM (5 years ago)
Author:
delthas
Message:

Fix parsing MODE messages by updating channel memberships

Previously, we only considered channel modes in the modes of a MODE
messages, which means channel membership changes were ignored. This
resulted in bugs where users channel memberships would not be properly
updated and cached with wrong values. Further, mode arguments
representing entities were not properly marshaled.

This adds support for correctly parsing and updating channel memberships
when processing MODE messages. Mode arguments corresponding to channel
memberships updates are now also properly marshaled.

MODE messages can't be easily sent from history because marshaling these
messages require knowing about the upstream available channel types and
channel membership types, which is currently only possible when
connected. For now this is not an issue since we do not send MODE
messages in history.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/upstream.go

    r292 r293  
    818818                        }
    819819
    820                         if ch.modes != nil {
    821                                 if err := ch.modes.Apply(uc.availableChannelModes, modeStr, msg.Params[2:]...); err != nil {
    822                                         return err
     820                        needMarshaling, err := applyChannelModes(ch, modeStr, msg.Params[2:])
     821                        if err != nil {
     822                                return err
     823                        }
     824
     825                        uc.appendLog(ch.Name, msg)
     826                        uc.forEachDownstream(func(dc *downstreamConn) {
     827                                params := make([]string, len(msg.Params))
     828                                params[0] = dc.marshalEntity(uc.network, name)
     829                                params[1] = modeStr
     830
     831                                copy(params[2:], msg.Params[2:])
     832                                for i, modeParam := range params[2:] {
     833                                        if _, ok := needMarshaling[i]; ok {
     834                                                params[2+i] = dc.marshalEntity(uc.network, modeParam)
     835                                        }
    823836                                }
    824                         }
    825 
    826                         uc.produce(ch.Name, msg, nil)
     837
     838                                dc.SendMessage(&irc.Message{
     839                                        Prefix:  dc.marshalUserPrefix(uc.network, msg.Prefix),
     840                                        Command: "MODE",
     841                                        Params:  params,
     842                                })
     843                        })
    827844                }
    828845        case irc.RPL_UMODEIS:
     
    857874                firstMode := ch.modes == nil
    858875                ch.modes = make(map[byte]string)
    859                 if err := ch.modes.Apply(uc.availableChannelModes, modeStr, msg.Params[3:]...); err != nil {
     876                if _, err := applyChannelModes(ch, modeStr, msg.Params[3:]); err != nil {
    860877                        return err
    861878                }
Note: See TracChangeset for help on using the changeset viewer.