]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_list.cpp
b820135f87fcf99d6a9e503d85c708ffcfccedce
[user/henk/code/inspircd.git] / src / commands / cmd_list.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 /** Handle /LIST. These command handlers can be reloaded by the core,
17  * and handle basic RFC1459 commands. Commands within modules work
18  * the same way, however, they can be fully unloaded, where these
19  * may not.
20  */
21 class CommandList : public Command
22 {
23  public:
24         /** Constructor for list.
25          */
26         CommandList ( Module* parent) : Command(parent,"LIST", 0, 0) { Penalty = 5; }
27         /** Handle command.
28          * @param parameters The parameters to the comamnd
29          * @param pcnt The number of parameters passed to teh command
30          * @param user The user issuing the command
31          * @return A value from CmdResult to indicate command success or failure.
32          */
33         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
34 };
35
36
37 /** Handle /LIST
38  */
39 CmdResult CommandList::Handle (const std::vector<std::string>& parameters, User *user)
40 {
41         int minusers = 0, maxusers = 0;
42
43         user->WriteNumeric(321, "%s Channel :Users Name",user->nick.c_str());
44
45         /* Work around mIRC suckyness. YOU SUCK, KHALED! */
46         if (parameters.size() == 1)
47         {
48                 if (parameters[0][0] == '<')
49                 {
50                         maxusers = atoi((parameters[0].c_str())+1);
51                 }
52                 else if (parameters[0][0] == '>')
53                 {
54                         minusers = atoi((parameters[0].c_str())+1);
55                 }
56         }
57
58         for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); i++)
59         {
60                 // attempt to match a glob pattern
61                 long users = i->second->GetUserCounter();
62
63                 bool too_few = (minusers && (users <= minusers));
64                 bool too_many = (maxusers && (users >= maxusers));
65
66                 if (too_many || too_few)
67                         continue;
68
69                 if (parameters.size() && (parameters[0][0] != '<' && parameters[0][0] != '>'))
70                 {
71                         if (!InspIRCd::Match(i->second->name, parameters[0]) && !InspIRCd::Match(i->second->topic, parameters[0]))
72                                 continue;
73                 }
74
75                 // if the channel is not private/secret, OR the user is on the channel anyway
76                 bool n = (i->second->HasUser(user) || user->HasPrivPermission("channels/auspex"));
77
78                 if (!n && i->second->IsModeSet('p'))
79                 {
80                         /* Channel is +p and user is outside/not privileged */
81                         user->WriteNumeric(322, "%s * %ld :",user->nick.c_str(), users);
82                 }
83                 else
84                 {
85                         if (n || !i->second->IsModeSet('s'))
86                         {
87                                 /* User is in the channel/privileged, channel is not +s */
88                                 user->WriteNumeric(322, "%s %s %ld :[+%s] %s",user->nick.c_str(),i->second->name.c_str(),users,i->second->ChanModes(n),i->second->topic.c_str());
89                         }
90                 }
91         }
92         user->WriteNumeric(323, "%s :End of channel list.",user->nick.c_str());
93
94         return CMD_SUCCESS;
95 }
96
97
98 COMMAND_INIT(CommandList)