2 * InspIRCd -- Internet Relay Chat Daemon
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>
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.
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
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/>.
30 #include "core_channel.h"
31 #include "modules/names.h"
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")
40 syntax = "[<channel>[,<channel>]+]";
45 CmdResult CommandNames::HandleLocal(LocalUser* user, const Params& parameters)
49 if (parameters.empty())
51 user->WriteNumeric(RPL_ENDOFNAMES, '*', "End of /NAMES list.");
55 if (CommandParser::LoopCall(user, this, parameters, 0))
58 c = ServerInstance->FindChan(parameters[0]);
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
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)))
70 SendNames(user, c, show_invisible);
75 user->WriteNumeric(Numerics::NoSuchChannel(parameters[0]));
79 void CommandNames::SendNames(LocalUser* user, Channel* chan, bool show_invisible)
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, '*'));
88 numeric.push(std::string(1, '='));
90 numeric.push(chan->name);
91 numeric.push(std::string());
93 std::string prefixlist;
95 const Channel::MemberMap& members = chan->GetUsers();
96 for (Channel::MemberMap::const_iterator i = members.begin(); i != members.end(); ++i)
98 if ((!show_invisible) && (i->first->IsModeSet(invisiblemode)))
100 // Member is invisible and we are not supposed to show them
104 Membership* const memb = i->second;
107 char prefix = memb->GetPrefixChar();
109 prefixlist.push_back(prefix);
110 nick = i->first->nick;
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);
119 user->WriteNumeric(RPL_ENDOFNAMES, chan->name, "End of /NAMES list.");