]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_list.cpp
Fix faulty logic, glob patterns may not start with > or <. TODO: iterate comma sep...
[user/henk/code/inspircd.git] / src / commands / cmd_list.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/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 #include "commands/cmd_list.h"
16
17 /** Handle /LIST
18  */
19 extern "C" DllExport Command* init_command(InspIRCd* Instance)
20 {
21         return new CommandList(Instance);
22 }
23
24 CmdResult CommandList::Handle (const std::vector<std::string>& parameters, User *user)
25 {
26         int minusers = 0, maxusers = 0;
27
28         user->WriteNumeric(321, "%s Channel :Users Name",user->nick.c_str());
29
30         /* Work around mIRC suckyness. YOU SUCK, KHALED! */
31         if (parameters.size() == 1)
32         {
33                 if (parameters[0][0] == '<')
34                 {
35                         maxusers = atoi((parameters[0].c_str())+1);
36                 }
37                 else if (parameters[0][0] == '>')
38                 {
39                         minusers = atoi((parameters[0].c_str())+1);
40                 }
41         }
42
43         for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); i++)
44         {
45                 // attempt to match a glob pattern
46                 long users = i->second->GetUserCounter();
47
48                 bool too_few = (minusers && (users <= minusers));
49                 bool too_many = (maxusers && (users >= maxusers));
50
51                 if (too_many || too_few)
52                         continue;
53
54                 if (parameters.size() && (parameters[0][0] != '<' && parameters[0][0] != '>'))
55                 {
56                         if (!InspIRCd::Match(i->second->name, parameters[0]) && !InspIRCd::Match(i->second->topic, parameters[0]))
57                                 continue;
58                 }
59
60                 // if the channel is not private/secret, OR the user is on the channel anyway
61                 bool n = (i->second->HasUser(user) || IS_OPER(user));
62                 if (!IS_OPER(user) && (i->second->IsModeSet('p')) && (!n))
63                 {
64                         user->WriteNumeric(322, "%s * %ld :",user->nick.c_str(), users);
65                 }
66                 else
67                 {
68                         if (IS_OPER(user) || (((!(i->second->IsModeSet('p'))) && (!(i->second->IsModeSet('s')))) || (n)))
69                         {
70                                 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());
71                         }
72                 }
73         }
74         user->WriteNumeric(323, "%s :End of channel list.",user->nick.c_str());
75
76         return CMD_SUCCESS;
77 }
78