]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
cmd_names Switch to Numeric::Builder
authorAttila Molnar <attilamolnar@hush.com>
Wed, 30 Dec 2015 12:34:33 +0000 (13:34 +0100)
committerAttila Molnar <attilamolnar@hush.com>
Wed, 30 Dec 2015 12:34:33 +0000 (13:34 +0100)
src/coremods/core_channel/cmd_names.cpp

index 05f16e10b22d30f0e0ff2115349548aa5611bea9..986dbe01889d7daa65b3c5822603f0c20f586c6d 100644 (file)
@@ -68,7 +68,8 @@ CmdResult CommandNames::HandleLocal(const std::vector<std::string>& 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());
 }