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