From 5cf876cb89d7df8ba86eb43f2e6188086ff2bfb6 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 16 Apr 2020 16:57:33 +0200 Subject: [PATCH] Kill downstreamConn.marshal{Nick,Channel} We can just use downstreamConn.marshalEntity instead. --- bridge.go | 6 +++--- downstream.go | 20 ++++++-------------- upstream.go | 32 ++++++++++++++++---------------- 3 files changed, 25 insertions(+), 33 deletions(-) diff --git a/bridge.go b/bridge.go index 026e07d..6633932 100644 --- a/bridge.go +++ b/bridge.go @@ -16,7 +16,7 @@ func forwardChannel(dc *downstreamConn, ch *upstreamChannel) { } func sendTopic(dc *downstreamConn, ch *upstreamChannel) { - downstreamName := dc.marshalChannel(ch.conn, ch.Name) + downstreamName := dc.marshalEntity(ch.conn, ch.Name) if ch.Topic != "" { dc.SendMessage(&irc.Message{ @@ -36,10 +36,10 @@ func sendTopic(dc *downstreamConn, ch *upstreamChannel) { func sendNames(dc *downstreamConn, ch *upstreamChannel) { // TODO: send multiple members in each message - downstreamName := dc.marshalChannel(ch.conn, ch.Name) + downstreamName := dc.marshalEntity(ch.conn, ch.Name) for nick, membership := range ch.Members { - s := membership.String() + dc.marshalNick(ch.conn, nick) + s := membership.String() + dc.marshalEntity(ch.conn, nick) dc.SendMessage(&irc.Message{ Prefix: dc.srv.prefix(), diff --git a/downstream.go b/downstream.go index 849745e..8ed3c3c 100644 --- a/downstream.go +++ b/downstream.go @@ -139,14 +139,6 @@ func (dc *downstreamConn) marshalEntity(uc *upstreamConn, name string) string { return name + "/" + uc.network.GetName() } -func (dc *downstreamConn) marshalChannel(uc *upstreamConn, name string) string { - return dc.marshalEntity(uc, name) -} - -func (dc *downstreamConn) marshalNick(uc *upstreamConn, name string) string { - return dc.marshalEntity(uc, name) -} - func (dc *downstreamConn) marshalUserPrefix(uc *upstreamConn, prefix *irc.Prefix) *irc.Prefix { if prefix.Name == uc.nick { return dc.prefix() @@ -243,14 +235,14 @@ func (dc *downstreamConn) marshalMessage(msg *irc.Message, uc *upstreamConn) *ir msg.Params[0] = dc.marshalEntity(uc, msg.Params[0]) case "NICK": // Nick change for another user - msg.Params[0] = dc.marshalNick(uc, msg.Params[0]) + msg.Params[0] = dc.marshalEntity(uc, msg.Params[0]) case "JOIN", "PART": - msg.Params[0] = dc.marshalChannel(uc, msg.Params[0]) + msg.Params[0] = dc.marshalEntity(uc, msg.Params[0]) case "KICK": - msg.Params[0] = dc.marshalChannel(uc, msg.Params[0]) - msg.Params[1] = dc.marshalNick(uc, msg.Params[1]) + msg.Params[0] = dc.marshalEntity(uc, msg.Params[0]) + msg.Params[1] = dc.marshalEntity(uc, msg.Params[1]) case "TOPIC": - msg.Params[0] = dc.marshalChannel(uc, msg.Params[0]) + msg.Params[0] = dc.marshalEntity(uc, msg.Params[0]) case "MODE": msg.Params[0] = dc.marshalEntity(uc, msg.Params[0]) case "QUIT": @@ -670,7 +662,7 @@ func (dc *downstreamConn) welcome() error { dc.SendMessage(&irc.Message{ Prefix: dc.prefix(), Command: "JOIN", - Params: []string{dc.marshalChannel(ch.conn, ch.Name)}, + Params: []string{dc.marshalEntity(ch.conn, ch.Name)}, }) forwardChannel(dc, ch) diff --git a/upstream.go b/upstream.go index 42d9792..946e8c6 100644 --- a/upstream.go +++ b/upstream.go @@ -764,7 +764,7 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error { modeStr, modeParams := ch.modes.Format() uc.forEachDownstream(func(dc *downstreamConn) { - params := []string{dc.nick, dc.marshalChannel(uc, channel), modeStr} + params := []string{dc.nick, dc.marshalEntity(uc, channel), modeStr} params = append(params, modeParams...) dc.SendMessage(&irc.Message{ @@ -826,7 +826,7 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error { dc.SendMessage(&irc.Message{ Prefix: dc.srv.prefix(), Command: irc.RPL_LIST, - Params: []string{dc.nick, dc.marshalChannel(uc, channel), clients, topic}, + Params: []string{dc.nick, dc.marshalEntity(uc, channel), clients, topic}, }) }) case irc.RPL_LISTEND: @@ -844,11 +844,11 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error { if !ok { // NAMES on a channel we have not joined, forward to downstream uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) { - channel := dc.marshalChannel(uc, name) + channel := dc.marshalEntity(uc, name) members := splitSpace(members) for i, member := range members { membership, nick := uc.parseMembershipPrefix(member) - members[i] = membership.String() + dc.marshalNick(uc, nick) + members[i] = membership.String() + dc.marshalEntity(uc, nick) } memberStr := strings.Join(members, " ") @@ -881,7 +881,7 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error { if !ok { // NAMES on a channel we have not joined, forward to downstream uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) { - channel := dc.marshalChannel(uc, name) + channel := dc.marshalEntity(uc, name) dc.SendMessage(&irc.Message{ Prefix: dc.srv.prefix(), @@ -922,9 +922,9 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error { uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) { channel := channel if channel != "*" { - channel = dc.marshalChannel(uc, channel) + channel = dc.marshalEntity(uc, channel) } - nick := dc.marshalNick(uc, nick) + nick := dc.marshalEntity(uc, nick) dc.SendMessage(&irc.Message{ Prefix: dc.srv.prefix(), Command: irc.RPL_WHOREPLY, @@ -956,7 +956,7 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error { } uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) { - nick := dc.marshalNick(uc, nick) + nick := dc.marshalEntity(uc, nick) dc.SendMessage(&irc.Message{ Prefix: dc.srv.prefix(), Command: irc.RPL_WHOISUSER, @@ -970,7 +970,7 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error { } uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) { - nick := dc.marshalNick(uc, nick) + nick := dc.marshalEntity(uc, nick) dc.SendMessage(&irc.Message{ Prefix: dc.srv.prefix(), Command: irc.RPL_WHOISSERVER, @@ -984,7 +984,7 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error { } uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) { - nick := dc.marshalNick(uc, nick) + nick := dc.marshalEntity(uc, nick) dc.SendMessage(&irc.Message{ Prefix: dc.srv.prefix(), Command: irc.RPL_WHOISOPERATOR, @@ -998,7 +998,7 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error { } uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) { - nick := dc.marshalNick(uc, nick) + nick := dc.marshalEntity(uc, nick) params := []string{dc.nick, nick} params = append(params, msg.Params[2:]...) dc.SendMessage(&irc.Message{ @@ -1015,11 +1015,11 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error { channels := splitSpace(channelList) uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) { - nick := dc.marshalNick(uc, nick) + nick := dc.marshalEntity(uc, nick) channelList := make([]string, len(channels)) for i, channel := range channels { prefix, channel := uc.parseMembershipPrefix(channel) - channel = dc.marshalChannel(uc, channel) + channel = dc.marshalEntity(uc, channel) channelList[i] = prefix.String() + channel } channels := strings.Join(channelList, " ") @@ -1036,7 +1036,7 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error { } uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) { - nick := dc.marshalNick(uc, nick) + nick := dc.marshalEntity(uc, nick) dc.SendMessage(&irc.Message{ Prefix: dc.srv.prefix(), Command: irc.RPL_ENDOFWHOIS, @@ -1078,7 +1078,7 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error { dc.SendMessage(&irc.Message{ Prefix: dc.marshalUserPrefix(uc, msg.Prefix), Command: "INVITE", - Params: []string{dc.marshalNick(uc, nick), dc.marshalChannel(uc, channel)}, + Params: []string{dc.marshalEntity(uc, nick), dc.marshalEntity(uc, channel)}, }) }) case irc.RPL_INVITING: @@ -1092,7 +1092,7 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error { dc.SendMessage(&irc.Message{ Prefix: dc.srv.prefix(), Command: irc.RPL_INVITING, - Params: []string{dc.nick, dc.marshalNick(uc, nick), dc.marshalChannel(uc, channel)}, + Params: []string{dc.nick, dc.marshalEntity(uc, nick), dc.marshalEntity(uc, channel)}, }) }) case irc.ERR_UNKNOWNCOMMAND, irc.RPL_TRYAGAIN: