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