]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/coremods/core_channel/cmd_names.cpp
Make more modules rehash atomically (#1535)
[user/henk/code/inspircd.git] / src / coremods / core_channel / cmd_names.cpp
index 05f16e10b22d30f0e0ff2115349548aa5611bea9..28273c90394ce80567eadd98b24af23bc1b2e4e0 100644 (file)
@@ -32,13 +32,13 @@ CommandNames::CommandNames(Module* parent)
 
 /** Handle /NAMES
  */
-CmdResult CommandNames::HandleLocal(const std::vector<std::string>& parameters, LocalUser* user)
+CmdResult CommandNames::HandleLocal(LocalUser* user, const Params& parameters)
 {
        Channel* c;
 
-       if (!parameters.size())
+       if (parameters.empty())
        {
-               user->WriteNumeric(RPL_ENDOFNAMES, "* :End of /NAMES list.");
+               user->WriteNumeric(RPL_ENDOFNAMES, '*', "End of /NAMES list.");
                return CMD_SUCCESS;
        }
 
@@ -62,25 +62,24 @@ CmdResult CommandNames::HandleLocal(const std::vector<std::string>& parameters,
                }
        }
 
-       user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such nick/channel", parameters[0].c_str());
+       user->WriteNumeric(Numerics::NoSuchChannel(parameters[0]));
        return CMD_FAILURE;
 }
 
 void CommandNames::SendNames(LocalUser* user, Channel* chan, bool show_invisible)
 {
-       std::string list;
+       Numeric::Builder<' '> reply(user, RPL_NAMREPLY, false, chan->name.size() + 3);
+       Numeric::Numeric& numeric = reply.GetNumeric();
        if (chan->IsModeSet(secretmode))
-               list.push_back('@');
+               numeric.push(std::string(1, '@'));
        else if (chan->IsModeSet(privatemode))
-               list.push_back('*');
+               numeric.push(std::string(1, '*'));
        else
-               list.push_back('=');
+               numeric.push(std::string(1, '='));
 
-       list.push_back(' ');
-       list.append(chan->name).append(" :");
-       std::string::size_type pos = list.size();
+       numeric.push(chan->name);
+       numeric.push(std::string());
 
-       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 +106,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);
-
-       user->WriteNumeric(RPL_ENDOFNAMES, "%s :End of /NAMES list.", chan->name.c_str());
+       reply.Flush();
+       user->WriteNumeric(RPL_ENDOFNAMES, chan->name, "End of /NAMES list.");
 }