2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 /** The base class for list modes, should be inherited.
24 class CoreExport ListModeBase : public ModeHandler
27 /** An item in a listmode's list
34 ListItem(const std::string& Mask, const std::string& Setter, time_t Time)
35 : setter(Setter), mask(Mask), time(Time) { }
38 /** Items stored in the channel's list
40 typedef std::list<ListItem> ModeList;
49 ChanData() : maxitems(-1) { }
52 /** The number of items a listmode's list may contain
58 ListLimit(const std::string& Mask, unsigned int Limit) : mask(Mask), limit(Limit) { }
59 bool operator==(const ListLimit& other) const { return (this->mask == other.mask && this->limit == other.limit); }
62 /** Max items per channel by name
64 typedef std::vector<ListLimit> limitlist;
66 /** Finds the limit of modes that can be placed on the given channel name according to the config
67 * @param channame The channel name to find the limit for
68 * @return The maximum number of modes of this type that we allow to be set on the given channel name
70 unsigned int FindLimit(const std::string& channame);
72 /** Returns the limit on the given channel for this mode.
73 * If the limit is cached then the cached value is returned,
74 * otherwise the limit is determined using FindLimit() and cached
75 * for later queries before it is returned
76 * @param channame The channel name to find the limit for
77 * @param cd The ChanData associated with channel channame
78 * @return The maximum number of modes of this type that we allow to be set on the given channel
80 unsigned int GetLimitInternal(const std::string& channame, ChanData* cd);
83 /** Numeric to use when outputting the list
85 unsigned int listnumeric;
86 /** Numeric to indicate end of list
88 unsigned int endoflistnumeric;
89 /** String to send for end of list
91 std::string endofliststring;
92 /** Automatically tidy up entries
95 /** Config tag to check for max items per channel
97 std::string configtag;
98 /** Limits on a per-channel basis read from the tag
99 * specified in ListModeBase::configtag
101 limitlist chanlimits;
105 SimpleExtItem<ChanData> extItem;
109 * @param Creator The creator of this class
110 * @param Name Mode name
111 * @param modechar Mode character
112 * @param eolstr End of list string
113 * @param lnum List numeric
114 * @param eolnum End of list numeric
115 * @param autotidy Automatically tidy list entries on add
116 * @param ctag Configuration tag to get limits from
118 ListModeBase(Module* Creator, const std::string& Name, char modechar, const std::string &eolstr, unsigned int lnum, unsigned int eolnum, bool autotidy, const std::string &ctag = "banlist");
120 /** Get limit of this mode on a channel
121 * @param channel The channel to inspect
122 * @return Maximum number of modes of this type that can be placed on the given channel
124 unsigned int GetLimit(Channel* channel);
126 /** Retrieves the list of all modes set on the given channel
127 * @param channel Channel to get the list from
128 * @return A list with all modes of this type set on the given channel, can be NULL
130 ModeList* GetList(Channel* channel);
132 /** Display the list for this mode
134 * @param user The user to send the list to
135 * @param channel The channel the user is requesting the list for
137 virtual void DisplayList(User* user, Channel* channel);
139 /** Tell a user that a list contains no elements.
140 * Sends 'eolnum' numeric with text 'eolstr', unless overridden (see constructor)
141 * @param user The user issuing the command
142 * @param channel The channel that has the empty list
145 virtual void DisplayEmptyList(User* user, Channel* channel);
147 /** Remove all instances of the mode from a channel.
148 * Populates the given modestack with modes that remove every instance of
149 * this mode from the channel.
150 * See mode.h for more details.
151 * @param channel The channel to remove all instances of the mode from
152 * @param stack The mode stack to add the mode change to
154 virtual void RemoveMode(Channel* channel, irc::modestacker& stack);
156 /** Perform a rehash of this mode's configuration data
158 virtual void DoRehash();
160 /** Handle the list mode.
163 virtual ModeAction OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding);
165 /** Validate parameters.
166 * Overridden by implementing module.
167 * @param user Source user adding the parameter
168 * @param channel Channel the parameter is being added to
169 * @param parameter The actual parameter being added
170 * @return true if the parameter is valid
172 virtual bool ValidateParam(User* user, Channel* channel, std::string& parameter);
174 /** Tell the user the list is too long.
175 * Overridden by implementing module.
176 * @param source Source user adding the parameter
177 * @param channel Channel the parameter is being added to
178 * @param parameter The actual parameter being added
180 virtual void TellListTooLong(User* source, Channel* channel, std::string& parameter);
182 /** Tell the user an item is already on the list.
183 * Overridden by implementing module.
184 * @param source Source user adding the parameter
185 * @param channel Channel the parameter is being added to
186 * @param parameter The actual parameter being added
188 virtual void TellAlreadyOnList(User* source, Channel* channel, std::string& parameter);
190 /** Tell the user that the parameter is not in the list.
191 * Overridden by implementing module.
192 * @param source Source user removing the parameter
193 * @param channel Channel the parameter is being removed from
194 * @param parameter The actual parameter being removed
196 virtual void TellNotSet(User* source, Channel* channel, std::string& parameter);
199 inline ListModeBase::ModeList* ListModeBase::GetList(Channel* channel)
201 ChanData* cd = extItem.get(channel);