]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_channel/cmd_names.cpp
core_list Check whether the chan name/topic has to be Match()ed once, not once per...
[user/henk/code/inspircd.git] / src / coremods / core_channel / cmd_names.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
6  *
7  * This file is part of InspIRCd.  InspIRCd is free software: you can
8  * redistribute it and/or modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation, version 2.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20
21 #include "inspircd.h"
22 #include "core_channel.h"
23
24 CommandNames::CommandNames(Module* parent)
25         : Command(parent, "NAMES", 0, 0)
26         , secretmode(parent, "secret")
27 {
28         syntax = "{<channel>{,<channel>}}";
29 }
30
31 /** Handle /NAMES
32  */
33 CmdResult CommandNames::Handle (const std::vector<std::string>& parameters, User *user)
34 {
35         Channel* c;
36
37         if (!parameters.size())
38         {
39                 user->WriteNumeric(RPL_ENDOFNAMES, "* :End of /NAMES list.");
40                 return CMD_SUCCESS;
41         }
42
43         if (CommandParser::LoopCall(user, this, parameters, 0))
44                 return CMD_SUCCESS;
45
46         c = ServerInstance->FindChan(parameters[0]);
47         if (c)
48         {
49                 // Show the NAMES list if one of the following is true:
50                 // - the channel is not secret
51                 // - the user doing the /NAMES is inside the channel
52                 // - the user doing the /NAMES has the channels/auspex privilege
53
54                 bool has_user = c->HasUser(user);
55                 if ((!c->IsModeSet(secretmode)) || (has_user) || (user->HasPrivPermission("channels/auspex")))
56                 {
57                         c->UserList(user, has_user);
58                         return CMD_SUCCESS;
59                 }
60         }
61
62         user->WriteNumeric(ERR_NOSUCHNICK, "%s :No such nick/channel", parameters[0].c_str());
63         return CMD_FAILURE;
64 }