]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/coremods/core_channel/cmd_names.cpp
Use ircd-hybrid's numerics for the "pending invites" list.
[user/henk/code/inspircd.git] / src / coremods / core_channel / cmd_names.cpp
index 9ae58d6fa0d1a6b981b765107e6f7d3f8ac446d8..bf13fac65a82a7fdaa32464fd014da4230259e57 100644 (file)
@@ -1,8 +1,16 @@
 /*
  * InspIRCd -- Internet Relay Chat Daemon
  *
+ *   Copyright (C) 2018-2019 Sadie Powell <sadie@witchery.services>
+ *   Copyright (C) 2018 Dylan Frank <b00mx0r@aureus.pw>
+ *   Copyright (C) 2017 B00mX0r <b00mx0r@aureus.pw>
+ *   Copyright (C) 2013-2016 Attila Molnar <attilamolnar@hush.com>
+ *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
+ *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
+ *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
+ *   Copyright (C) 2006, 2008, 2010 Craig Edwards <brain@inspircd.org>
  *
  * This file is part of InspIRCd.  InspIRCd is free software: you can
  * redistribute it and/or modify it under the terms of the GNU General Public
 
 #include "inspircd.h"
 #include "core_channel.h"
+#include "modules/names.h"
 
 CommandNames::CommandNames(Module* parent)
-       : Command(parent, "NAMES", 0, 0)
+       : 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::Handle (const std::vector<std::string>& parameters, User *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;
        }
 
@@ -53,41 +63,39 @@ CmdResult CommandNames::Handle (const std::vector<std::string>& parameters, User
                // - the user doing the /NAMES is inside the channel
                // - the user doing the /NAMES has the channels/auspex privilege
 
-               bool has_user = c->HasUser(user);
-               if ((!c->IsModeSet(secretmode)) || (has_user) || (user->HasPrivPermission("channels/auspex")))
+               // If the user is inside the channel or has privs, instruct SendNames() to show invisible (+i) members
+               bool show_invisible = ((c->HasUser(user)) || (user->HasPrivPermission("channels/auspex")));
+               if ((show_invisible) || (!c->IsModeSet(secretmode)))
                {
-                       SendNames(user, c, has_user);
+                       SendNames(user, c, show_invisible);
                        return CMD_SUCCESS;
                }
        }
 
-       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(User* user, Channel* chan, bool isinside)
+void CommandNames::SendNames(LocalUser* user, Channel* chan, bool show_invisible)
 {
-       bool has_privs = user->HasPrivPermission("channels/auspex");
-
-       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();
        for (Channel::MemberMap::const_iterator i = members.begin(); i != members.end(); ++i)
        {
-               if ((!isinside) && (i->first->IsModeSet(invisiblemode)) && (!has_privs))
+               if ((!show_invisible) && (i->first->IsModeSet(invisiblemode)))
                {
                        // Member is invisible and we are not supposed to show them
                        continue;
@@ -102,27 +110,11 @@ void CommandNames::SendNames(User* user, Channel* chan, bool isinside)
                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;
-
-               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(' ');
+               FIRST_MOD_RESULT_CUSTOM(namesevprov, Names::EventListener, OnNamesListItem, res, (user, memb, prefixlist, nick));
+               if (res != MOD_RES_DENY)
+                       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.");
 }