]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_list.cpp
Remove out of date doc and fix typo in commands/cmd_*.cpp
[user/henk/code/inspircd.git] / src / commands / cmd_list.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
23 /** Handle /LIST.
24  */
25 class CommandList : public Command
26 {
27         ChanModeReference secretmode;
28         ChanModeReference privatemode;
29
30  public:
31         /** Constructor for list.
32          */
33         CommandList(Module* parent)
34                 : Command(parent,"LIST", 0, 0)
35                 , secretmode(creator, "secret")
36                 , privatemode(creator, "private")
37         {
38                 Penalty = 5;
39         }
40
41         /** Handle command.
42          * @param parameters The parameters to the command
43          * @param user The user issuing the command
44          * @return A value from CmdResult to indicate command success or failure.
45          */
46         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
47 };
48
49
50 /** Handle /LIST
51  */
52 CmdResult CommandList::Handle (const std::vector<std::string>& parameters, User *user)
53 {
54         int minusers = 0, maxusers = 0;
55
56         user->WriteNumeric(RPL_LISTSTART, "Channel :Users Name");
57
58         /* Work around mIRC suckyness. YOU SUCK, KHALED! */
59         if (parameters.size() == 1)
60         {
61                 if (parameters[0][0] == '<')
62                 {
63                         maxusers = atoi((parameters[0].c_str())+1);
64                 }
65                 else if (parameters[0][0] == '>')
66                 {
67                         minusers = atoi((parameters[0].c_str())+1);
68                 }
69         }
70
71         for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); i++)
72         {
73                 // attempt to match a glob pattern
74                 long users = i->second->GetUserCounter();
75
76                 bool too_few = (minusers && (users <= minusers));
77                 bool too_many = (maxusers && (users >= maxusers));
78
79                 if (too_many || too_few)
80                         continue;
81
82                 if (parameters.size() && !parameters[0].empty() && (parameters[0][0] != '<' && parameters[0][0] != '>'))
83                 {
84                         if (!InspIRCd::Match(i->second->name, parameters[0]) && !InspIRCd::Match(i->second->topic, parameters[0]))
85                                 continue;
86                 }
87
88                 // if the channel is not private/secret, OR the user is on the channel anyway
89                 bool n = (i->second->HasUser(user) || user->HasPrivPermission("channels/auspex"));
90
91                 if (!n && i->second->IsModeSet(privatemode))
92                 {
93                         /* Channel is +p and user is outside/not privileged */
94                         user->WriteNumeric(RPL_LIST, "* %ld :", users);
95                 }
96                 else
97                 {
98                         if (n || !i->second->IsModeSet(secretmode))
99                         {
100                                 /* User is in the channel/privileged, channel is not +s */
101                                 user->WriteNumeric(RPL_LIST, "%s %ld :[+%s] %s",i->second->name.c_str(),users,i->second->ChanModes(n),i->second->topic.c_str());
102                         }
103                 }
104         }
105         user->WriteNumeric(RPL_LISTEND, ":End of channel list.");
106
107         return CMD_SUCCESS;
108 }
109
110
111 COMMAND_INIT(CommandList)