1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 #ifndef __CMD_LIST_H__
17 #define __CMD_LIST_H__
19 // include the common header files
24 /** Handle /LIST. These command handlers can be reloaded by the core,
25 * and handle basic RFC1459 commands. Commands within modules work
26 * the same way, however, they can be fully unloaded, where these
29 class CommandList : public Command
32 /** Constructor for list.
34 CommandList (InspIRCd* Instance, Module* parent) : Command(Instance,parent,"LIST", 0, 0, false, 5) { }
36 * @param parameters The parameters to the comamnd
37 * @param pcnt The number of parameters passed to teh command
38 * @param user The user issuing the command
39 * @return A value from CmdResult to indicate command success or failure.
41 CmdResult Handle(const std::vector<std::string>& parameters, User *user);
49 CmdResult CommandList::Handle (const std::vector<std::string>& parameters, User *user)
51 int minusers = 0, maxusers = 0;
53 user->WriteNumeric(321, "%s Channel :Users Name",user->nick.c_str());
55 /* Work around mIRC suckyness. YOU SUCK, KHALED! */
56 if (parameters.size() == 1)
58 if (parameters[0][0] == '<')
60 maxusers = atoi((parameters[0].c_str())+1);
62 else if (parameters[0][0] == '>')
64 minusers = atoi((parameters[0].c_str())+1);
68 for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); i++)
70 // attempt to match a glob pattern
71 long users = i->second->GetUserCounter();
73 bool too_few = (minusers && (users <= minusers));
74 bool too_many = (maxusers && (users >= maxusers));
76 if (too_many || too_few)
79 if (parameters.size() && (parameters[0][0] != '<' && parameters[0][0] != '>'))
81 if (!InspIRCd::Match(i->second->name, parameters[0]) && !InspIRCd::Match(i->second->topic, parameters[0]))
85 // if the channel is not private/secret, OR the user is on the channel anyway
86 bool n = (i->second->HasUser(user) || user->HasPrivPermission("channels/auspex"));
88 if (!n && i->second->IsModeSet('p'))
90 /* Channel is +p and user is outside/not privileged */
91 user->WriteNumeric(322, "%s * %ld :",user->nick.c_str(), users);
95 if (n || !i->second->IsModeSet('s'))
97 /* User is in the channel/privileged, channel is not +s */
98 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());
102 user->WriteNumeric(323, "%s :End of channel list.",user->nick.c_str());
108 COMMAND_INIT(CommandList)