]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - 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
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2018-2019 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2018 Dylan Frank <b00mx0r@aureus.pw>
6  *   Copyright (C) 2017 B00mX0r <b00mx0r@aureus.pw>
7  *   Copyright (C) 2013-2016 Attila Molnar <attilamolnar@hush.com>
8  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
9  *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
10  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
11  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
12  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
13  *   Copyright (C) 2006, 2008, 2010 Craig Edwards <brain@inspircd.org>
14  *
15  * This file is part of InspIRCd.  InspIRCd is free software: you can
16  * redistribute it and/or modify it under the terms of the GNU General Public
17  * License as published by the Free Software Foundation, version 2.
18  *
19  * This program is distributed in the hope that it will be useful, but WITHOUT
20  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
22  * details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
26  */
27
28
29 #include "inspircd.h"
30 #include "core_channel.h"
31 #include "modules/names.h"
32
33 CommandNames::CommandNames(Module* parent)
34         : SplitCommand(parent, "NAMES", 0, 0)
35         , secretmode(parent, "secret")
36         , privatemode(parent, "private")
37         , invisiblemode(parent, "invisible")
38         , namesevprov(parent, "event/names")
39 {
40         syntax = "[<channel>[,<channel>]+]";
41 }
42
43 /** Handle /NAMES
44  */
45 CmdResult CommandNames::HandleLocal(LocalUser* user, const Params& parameters)
46 {
47         Channel* c;
48
49         if (parameters.empty())
50         {
51                 user->WriteNumeric(RPL_ENDOFNAMES, '*', "End of /NAMES list.");
52                 return CMD_SUCCESS;
53         }
54
55         if (CommandParser::LoopCall(user, this, parameters, 0))
56                 return CMD_SUCCESS;
57
58         c = ServerInstance->FindChan(parameters[0]);
59         if (c)
60         {
61                 // Show the NAMES list if one of the following is true:
62                 // - the channel is not secret
63                 // - the user doing the /NAMES is inside the channel
64                 // - the user doing the /NAMES has the channels/auspex privilege
65
66                 // If the user is inside the channel or has privs, instruct SendNames() to show invisible (+i) members
67                 bool show_invisible = ((c->HasUser(user)) || (user->HasPrivPermission("channels/auspex")));
68                 if ((show_invisible) || (!c->IsModeSet(secretmode)))
69                 {
70                         SendNames(user, c, show_invisible);
71                         return CMD_SUCCESS;
72                 }
73         }
74
75         user->WriteNumeric(Numerics::NoSuchChannel(parameters[0]));
76         return CMD_FAILURE;
77 }
78
79 void CommandNames::SendNames(LocalUser* user, Channel* chan, bool show_invisible)
80 {
81         Numeric::Builder<' '> reply(user, RPL_NAMREPLY, false, chan->name.size() + 3);
82         Numeric::Numeric& numeric = reply.GetNumeric();
83         if (chan->IsModeSet(secretmode))
84                 numeric.push(std::string(1, '@'));
85         else if (chan->IsModeSet(privatemode))
86                 numeric.push(std::string(1, '*'));
87         else
88                 numeric.push(std::string(1, '='));
89
90         numeric.push(chan->name);
91         numeric.push(std::string());
92
93         std::string prefixlist;
94         std::string nick;
95         const Channel::MemberMap& members = chan->GetUsers();
96         for (Channel::MemberMap::const_iterator i = members.begin(); i != members.end(); ++i)
97         {
98                 if ((!show_invisible) && (i->first->IsModeSet(invisiblemode)))
99                 {
100                         // Member is invisible and we are not supposed to show them
101                         continue;
102                 }
103
104                 Membership* const memb = i->second;
105
106                 prefixlist.clear();
107                 char prefix = memb->GetPrefixChar();
108                 if (prefix)
109                         prefixlist.push_back(prefix);
110                 nick = i->first->nick;
111
112                 ModResult res;
113                 FIRST_MOD_RESULT_CUSTOM(namesevprov, Names::EventListener, OnNamesListItem, res, (user, memb, prefixlist, nick));
114                 if (res != MOD_RES_DENY)
115                         reply.Add(prefixlist, nick);
116         }
117
118         reply.Flush();
119         user->WriteNumeric(RPL_ENDOFNAMES, chan->name, "End of /NAMES list.");
120 }