2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
7 * This file is part of InspIRCd. InspIRCd is free software: you can
8 * redistribute it and/or modify it under the terms of the GNU General Public
9 * License as published by the Free Software Foundation, version 2.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 class CommandList : public Command
27 ChanModeReference secretmode;
28 ChanModeReference privatemode;
31 /** Constructor for list.
33 CommandList(Module* parent)
34 : Command(parent,"LIST", 0, 0)
35 , secretmode(creator, "secret")
36 , privatemode(creator, "private")
42 * @param parameters The parameters to the command
43 * @param user The user issuing the command
44 * @return A value from CmdResult to indicate command success or failure.
46 CmdResult Handle(const std::vector<std::string>& parameters, User *user);
52 CmdResult CommandList::Handle (const std::vector<std::string>& parameters, User *user)
54 int minusers = 0, maxusers = 0;
56 user->WriteNumeric(RPL_LISTSTART, "Channel", "Users Name");
58 /* Work around mIRC suckyness. YOU SUCK, KHALED! */
59 if (parameters.size() == 1)
61 if (parameters[0][0] == '<')
63 maxusers = atoi((parameters[0].c_str())+1);
65 else if (parameters[0][0] == '>')
67 minusers = atoi((parameters[0].c_str())+1);
71 const bool has_privs = user->HasPrivPermission("channels/auspex");
72 const bool match_name_topic = ((!parameters.empty()) && (!parameters[0].empty()) && (parameters[0][0] != '<') && (parameters[0][0] != '>'));
74 const chan_hash& chans = ServerInstance->GetChans();
75 for (chan_hash::const_iterator i = chans.begin(); i != chans.end(); ++i)
77 Channel* const chan = i->second;
79 // attempt to match a glob pattern
80 long users = chan->GetUserCounter();
82 bool too_few = (minusers && (users <= minusers));
83 bool too_many = (maxusers && (users >= maxusers));
85 if (too_many || too_few)
90 if (!InspIRCd::Match(chan->name, parameters[0]) && !InspIRCd::Match(chan->topic, parameters[0]))
94 // if the channel is not private/secret, OR the user is on the channel anyway
95 bool n = (has_privs || chan->HasUser(user));
97 // If we're not in the channel and +s is set on it, we want to ignore it
98 if ((n) || (!chan->IsModeSet(secretmode)))
100 if ((!n) && (chan->IsModeSet(privatemode)))
102 // Channel is private (+p) and user is outside/not privileged
103 user->WriteNumeric(RPL_LIST, '*', users, "");
107 /* User is in the channel/privileged, channel is not +s */
108 user->WriteNumeric(RPL_LIST, chan->name, users, InspIRCd::Format("[+%s] %s", chan->ChanModes(n), chan->topic.c_str()));
112 user->WriteNumeric(RPL_LISTEND, "End of channel list.");
118 COMMAND_INIT(CommandList)