Changeset 245 in code for trunk/downstream.go


Ignore:
Timestamp:
Apr 7, 2020, 5:45:29 PM (5 years ago)
Author:
contact
Message:

Centralize logged messages marshaling

This allows messages added to logs to be handled just like messages
added to the ring buffer.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/downstream.go

    r242 r245  
    223223}
    224224
    225 func (dc *downstreamConn) sendFromUpstream(msg *irc.Message, uc *upstreamConn) {
     225// marshalMessage re-formats a message coming from an upstream connection so
     226// that it's suitable for being sent on this downstream connection. Only
     227// messages that may appear in logs are supported.
     228func (dc *downstreamConn) marshalMessage(msg *irc.Message, uc *upstreamConn) *irc.Message {
    226229        msg = msg.Copy()
     230        msg.Prefix = dc.marshalUserPrefix(uc, msg.Prefix)
     231
    227232        switch msg.Command {
    228233        case "PRIVMSG", "NOTICE":
    229                 msg.Prefix = dc.marshalUserPrefix(uc, msg.Prefix)
    230234                msg.Params[0] = dc.marshalEntity(uc, msg.Params[0])
     235        case "NICK":
     236                // Nick change for another user
     237                msg.Params[0] = dc.marshalNick(uc, msg.Params[0])
     238        case "JOIN", "PART":
     239                msg.Params[0] = dc.marshalChannel(uc, msg.Params[0])
     240        case "KICK":
     241                msg.Params[0] = dc.marshalChannel(uc, msg.Params[0])
     242                msg.Params[1] = dc.marshalNick(uc, msg.Params[1])
     243        case "TOPIC":
     244                msg.Params[0] = dc.marshalChannel(uc, msg.Params[0])
     245        case "MODE":
     246                msg.Params[0] = dc.marshalEntity(uc, msg.Params[0])
     247        case "QUIT":
     248                // This space is intentinally left blank
    231249        default:
    232250                panic(fmt.Sprintf("unexpected %q message", msg.Command))
    233251        }
    234252
    235         dc.SendMessage(msg)
     253        return msg
    236254}
    237255
     
    685703                        }
    686704
    687                         dc.sendFromUpstream(msg, uc)
     705                        // Don't replay all messages, because that would mess up client
     706                        // state. For instance we just sent the list of users, sending
     707                        // PART messages for one of these users would be incorrect.
     708                        ignore := true
     709                        switch msg.Command {
     710                        case "PRIVMSG", "NOTICE":
     711                                ignore = false
     712                        }
     713                        if ignore {
     714                                continue
     715                        }
     716
     717                        dc.SendMessage(dc.marshalMessage(msg, uc))
    688718                }
    689719        })
Note: See TracChangeset for help on using the changeset viewer.