]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/coremods/core_channel/cmd_names.cpp
Allow modules to prevent a failed connection from being closed.
[user/henk/code/inspircd.git] / src / coremods / core_channel / cmd_names.cpp
index 986dbe01889d7daa65b3c5822603f0c20f586c6d..d503702465ee39d6a6d8e903c55aa10e6a6559c4 100644 (file)
 
 #include "inspircd.h"
 #include "core_channel.h"
+#include "modules/names.h"
 
 CommandNames::CommandNames(Module* parent)
        : SplitCommand(parent, "NAMES", 0, 0)
        , secretmode(parent, "secret")
        , privatemode(parent, "private")
        , invisiblemode(parent, "invisible")
+       , namesevprov(parent, "event/names")
 {
-       syntax = "{<channel>{,<channel>}}";
+       syntax = "[<channel>[,<channel>]+]";
 }
 
 /** 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,24 +64,23 @@ 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)
 {
-       Numeric::Builder<' '> reply(user, RPL_NAMREPLY, false);
-       std::string& list = reply.GetNumeric();
+       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(" :");
-       reply.SaveBeginPos();
+       numeric.push(chan->name);
+       numeric.push(std::string());
 
        std::string prefixlist;
        std::string nick;
@@ -101,15 +102,11 @@ void CommandNames::SendNames(LocalUser* user, Channel* chan, bool show_invisible
                nick = i->first->nick;
 
                ModResult res;
-               FIRST_MOD_RESULT(OnNamesListItem, res, (user, memb, prefixlist, nick));
-
-               // See if a module wants us to exclude this user from NAMES
-               if (res == MOD_RES_DENY)
-                       continue;
-
-               reply.Add(prefixlist, nick);
+               FIRST_MOD_RESULT_CUSTOM(namesevprov, Names::EventListener, OnNamesListItem, res, (user, memb, prefixlist, nick));
+               if (res != MOD_RES_DENY)
+                       reply.Add(prefixlist, nick);
        }
 
        reply.Flush();
-       user->WriteNumeric(RPL_ENDOFNAMES, "%s :End of /NAMES list.", chan->name.c_str());
+       user->WriteNumeric(RPL_ENDOFNAMES, chan->name, "End of /NAMES list.");
 }