From 5d050846f7f3f152422e56e5c871302ee7a5a1ed Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Wed, 30 Dec 2015 13:34:33 +0100 Subject: [PATCH] cmd_names Switch to Numeric::Builder --- src/coremods/core_channel/cmd_names.cpp | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/coremods/core_channel/cmd_names.cpp b/src/coremods/core_channel/cmd_names.cpp index 05f16e10b..986dbe018 100644 --- a/src/coremods/core_channel/cmd_names.cpp +++ b/src/coremods/core_channel/cmd_names.cpp @@ -68,7 +68,8 @@ CmdResult CommandNames::HandleLocal(const std::vector& parameters, void CommandNames::SendNames(LocalUser* user, Channel* chan, bool show_invisible) { - std::string list; + Numeric::Builder<' '> reply(user, RPL_NAMREPLY, false); + std::string& list = reply.GetNumeric(); if (chan->IsModeSet(secretmode)) list.push_back('@'); else if (chan->IsModeSet(privatemode)) @@ -78,9 +79,8 @@ void CommandNames::SendNames(LocalUser* user, Channel* chan, bool show_invisible list.push_back(' '); list.append(chan->name).append(" :"); - std::string::size_type pos = list.size(); + reply.SaveBeginPos(); - const size_t maxlen = ServerInstance->Config->Limits.MaxLine - 10 - ServerInstance->Config->ServerName.size() - user->nick.size(); std::string prefixlist; std::string nick; const Channel::MemberMap& members = chan->GetUsers(); @@ -107,21 +107,9 @@ void CommandNames::SendNames(LocalUser* user, Channel* chan, bool show_invisible if (res == MOD_RES_DENY) continue; - if (list.size() + prefixlist.length() + nick.length() + 1 > maxlen) - { - // List overflowed into multiple numerics - user->WriteNumeric(RPL_NAMREPLY, list); - - // Erase all nicks, keep the constant part - list.erase(pos); - } - - list.append(prefixlist).append(nick).push_back(' '); + reply.Add(prefixlist, nick); } - // Only send the user list numeric if there is at least one user in it - if (list.size() != pos) - user->WriteNumeric(RPL_NAMREPLY, list); - + reply.Flush(); user->WriteNumeric(RPL_ENDOFNAMES, "%s :End of /NAMES list.", chan->name.c_str()); } -- 2.39.5