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 /** Handle /LIST. These command handlers can be reloaded by the core,
17 * and handle basic RFC1459 commands. Commands within modules work
18 * the same way, however, they can be fully unloaded, where these
21 class CommandList : public Command
24 /** Constructor for list.
26 CommandList ( Module* parent) : Command(parent,"LIST", 0, 0) { Penalty = 5; }
28 * @param parameters The parameters to the comamnd
29 * @param pcnt The number of parameters passed to teh command
30 * @param user The user issuing the command
31 * @return A value from CmdResult to indicate command success or failure.
33 CmdResult Handle(const std::vector<std::string>& parameters, User *user);
39 CmdResult CommandList::Handle (const std::vector<std::string>& parameters, User *user)
41 int minusers = 0, maxusers = 0;
43 user->WriteNumeric(321, "%s Channel :Users Name",user->nick.c_str());
45 /* Work around mIRC suckyness. YOU SUCK, KHALED! */
46 if (parameters.size() == 1)
48 if (parameters[0][0] == '<')
50 maxusers = atoi((parameters[0].c_str())+1);
52 else if (parameters[0][0] == '>')
54 minusers = atoi((parameters[0].c_str())+1);
58 for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); i++)
60 // attempt to match a glob pattern
61 long users = i->second->GetUserCounter();
63 bool too_few = (minusers && (users <= minusers));
64 bool too_many = (maxusers && (users >= maxusers));
66 if (too_many || too_few)
69 if (parameters.size() && (parameters[0][0] != '<' && parameters[0][0] != '>'))
71 if (!InspIRCd::Match(i->second->name, parameters[0]) && !InspIRCd::Match(i->second->topic, parameters[0]))
75 // if the channel is not private/secret, OR the user is on the channel anyway
76 bool n = (i->second->HasUser(user) || user->HasPrivPermission("channels/auspex"));
78 if (!n && i->second->IsModeSet('p'))
80 /* Channel is +p and user is outside/not privileged */
81 user->WriteNumeric(322, "%s * %ld :",user->nick.c_str(), users);
85 if (n || !i->second->IsModeSet('s'))
87 /* User is in the channel/privileged, channel is not +s */
88 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());
92 user->WriteNumeric(323, "%s :End of channel list.",user->nick.c_str());
98 COMMAND_INIT(CommandList)