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