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