]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_list.cpp
d5ceef9e34be95223fca103ee40c998e97392fcc
[user/henk/code/inspircd.git] / src / commands / cmd_list.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 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 char** parameters, int pcnt, User *user)
26 {
27         int minusers = 0, maxusers = 0;
28
29         user->WriteServ("321 %s Channel :Users Name",user->nick);
30
31         /* Work around mIRC suckyness. YOU SUCK, KHALED! */
32         if (pcnt == 1)
33         {
34                 if (*parameters[0] == '<')
35                 {
36                         maxusers = atoi(parameters[0]+1);
37                         pcnt = 0;
38                 }
39                 else if (*parameters[0] == '>')
40                 {
41                         minusers = atoi(parameters[0]+1);
42                         pcnt = 0;
43                 }
44         }
45
46         for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); i++)
47         {
48                 // attempt to match a glob pattern
49                 long users = i->second->GetUserCounter();
50
51                 bool too_few = (minusers && (users <= minusers));
52                 bool too_many = (maxusers && (users >= maxusers));
53
54                 if (too_many || too_few)
55                         continue;
56
57                 if (pcnt)
58                 {
59                         if (!match(i->second->name, parameters[0]) && !match(i->second->topic, parameters[0]))
60                                 continue;
61                 }
62
63                 // if the channel is not private/secret, OR the user is on the channel anyway
64                 bool n = i->second->HasUser(user);
65                 if ((i->second->IsModeSet('p')) && (!n))
66                 {
67                         user->WriteServ("322 %s *",user->nick,i->second->name);
68                 }
69                 else
70                 {
71                         if (((!(i->second->IsModeSet('p'))) && (!(i->second->IsModeSet('s')))) || (n))
72                         {
73                                 user->WriteServ("322 %s %s %d :[+%s] %s",user->nick,i->second->name,users,i->second->ChanModes(n),i->second->topic);
74                         }
75                 }
76         }
77         user->WriteServ("323 %s :End of channel list.",user->nick);
78
79         return CMD_SUCCESS;
80 }
81