From 8449c7e81a5e554cc9cb2c0facd113387bd2238a Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 9 Mar 2016 03:04:04 -0500 Subject: [PATCH] Limit the number of nicks that are sent in a single NAMREPLY message --- client.go | 17 ++++++++++++++--- rosella.go | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index 025afde..5cc7adb 100644 --- a/client.go +++ b/client.go @@ -85,7 +85,9 @@ func (c *Client) joinChannel(channelName string) { c.reply(rplNoTopic, channel.name) } - nicks := make([]string, 0, 100) + //The capacity sets the max number of nicks to send per message + nicks := make([]string, 0, 128) + for _, client := range channel.clientMap { prefix := "" @@ -93,10 +95,19 @@ func (c *Client) joinChannel(channelName string) { prefix = mode.Prefix() } + if len(nicks) >= cap(nicks) { + c.reply(rplNames, channelName, strings.Join(nicks, " ")) + nicks = nicks[:0] + } + nicks = append(nicks, fmt.Sprintf("%s%s", prefix, client.nick)) } - c.reply(rplNames, channelName, strings.Join(nicks, " ")) + if len(nicks) > 0 { + c.reply(rplNames, channelName, strings.Join(nicks, " ")) + } + + c.reply(rplEndOfNames, channelName) } func (c *Client) partChannel(channelName, reason string) { @@ -148,8 +159,8 @@ func (c *Client) reply(code replyCode, args ...string) { case rplNoTopic: c.outputChan <- fmt.Sprintf(":%s 331 %s %s :No topic is set", c.server.name, c.nick, args[0]) case rplNames: - //TODO: break long lists up into multiple messages c.outputChan <- fmt.Sprintf(":%s 353 %s = %s :%s", c.server.name, c.nick, args[0], args[1]) + case rplEndOfNames: c.outputChan <- fmt.Sprintf(":%s 366 %s %s :End of NAMES list", c.server.name, c.nick, args[0]) case rplNickChange: c.outputChan <- fmt.Sprintf(":%s NICK %s", args[0], args[1]) diff --git a/rosella.go b/rosella.go index e1805de..df3ea5b 100644 --- a/rosella.go +++ b/rosella.go @@ -116,6 +116,7 @@ const ( rplTopic rplNoTopic rplNames + rplEndOfNames rplNickChange rplKill rplMsg