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::vector<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 /** The default maximum list size. */
67 static const unsigned int DEFAULT_LIST_SIZE = 100;
69 /** Finds the limit of modes that can be placed on the given channel name according to the config
70 * @param channame The channel name to find the limit for
71 * @return The maximum number of modes of this type that we allow to be set on the given channel name
73 unsigned int FindLimit(const std::string& channame);
75 /** Returns the limit on the given channel for this mode.
76 * If the limit is cached then the cached value is returned,
77 * otherwise the limit is determined using FindLimit() and cached
78 * for later queries before it is returned
79 * @param channame The channel name to find the limit for
80 * @param cd The ChanData associated with channel channame
81 * @return The maximum number of modes of this type that we allow to be set on the given channel
83 unsigned int GetLimitInternal(const std::string& channame, ChanData* cd);
86 /** Numeric to use when outputting the list
88 unsigned int listnumeric;
89 /** Numeric to indicate end of list
91 unsigned int endoflistnumeric;
92 /** String to send for end of list
94 std::string endofliststring;
95 /** Automatically tidy up entries
98 /** Config tag to check for max items per channel
100 std::string configtag;
101 /** Limits on a per-channel basis read from the tag
102 * specified in ListModeBase::configtag
104 limitlist chanlimits;
108 SimpleExtItem<ChanData> extItem;
112 * @param Creator The creator of this class
113 * @param Name Mode name
114 * @param modechar Mode character
115 * @param eolstr End of list string
116 * @param lnum List numeric
117 * @param eolnum End of list numeric
118 * @param autotidy Automatically tidy list entries on add
119 * @param ctag Configuration tag to get limits from
121 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");
123 /** Get limit of this mode on a channel
124 * @param channel The channel to inspect
125 * @return Maximum number of modes of this type that can be placed on the given channel
127 unsigned int GetLimit(Channel* channel);
129 /** Gets the lower list limit for this listmode.
131 unsigned int GetLowerLimit();
133 /** Retrieves the list of all modes set on the given channel
134 * @param channel Channel to get the list from
135 * @return A list with all modes of this type set on the given channel, can be NULL
137 ModeList* GetList(Channel* channel);
139 /** Display the list for this mode
141 * @param user The user to send the list to
142 * @param channel The channel the user is requesting the list for
144 void DisplayList(User* user, Channel* channel) CXX11_OVERRIDE;
146 /** Tell a user that a list contains no elements.
147 * Sends 'eolnum' numeric with text 'eolstr', unless overridden (see constructor)
148 * @param user The user issuing the command
149 * @param channel The channel that has the empty list
152 void DisplayEmptyList(User* user, Channel* channel) CXX11_OVERRIDE;
154 /** Remove all instances of the mode from a channel.
155 * Populates the given modestack with modes that remove every instance of
156 * this mode from the channel.
157 * See mode.h for more details.
158 * @param channel The channel to remove all instances of the mode from
159 * @param changelist Mode change list to populate with the removal of this mode
161 void RemoveMode(Channel* channel, Modes::ChangeList& changelist) CXX11_OVERRIDE;
163 /** Perform a rehash of this mode's configuration data
167 /** Handle the list mode.
170 ModeAction OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding) CXX11_OVERRIDE;
172 /** Validate parameters.
173 * Overridden by implementing module.
174 * @param user Source user adding the parameter
175 * @param channel Channel the parameter is being added to
176 * @param parameter The actual parameter being added
177 * @return true if the parameter is valid
179 virtual bool ValidateParam(User* user, Channel* channel, std::string& parameter);
181 /** In the event that the mode should be given a parameter, and no parameter was provided, this method is called.
182 * This allows you to give special information to the user, or handle this any way you like.
183 * @param user The user issuing the mode change
184 * @param dest For user mode changes, the target of the mode. For channel mode changes, NULL.
185 * @param channel For channel mode changes, the target of the mode. For user mode changes, NULL.
188 virtual void OnParameterMissing(User* user, User* dest, Channel* channel) CXX11_OVERRIDE;
190 /** Tell the user the list is too long.
191 * Overridden by implementing module.
192 * @param source Source user adding the parameter
193 * @param channel Channel the parameter is being added to
194 * @param parameter The actual parameter being added
196 virtual void TellListTooLong(User* source, Channel* channel, std::string& parameter);
198 /** Tell the user an item is already on the list.
199 * Overridden by implementing module.
200 * @param source Source user adding the parameter
201 * @param channel Channel the parameter is being added to
202 * @param parameter The actual parameter being added
204 virtual void TellAlreadyOnList(User* source, Channel* channel, std::string& parameter);
206 /** Tell the user that the parameter is not in the list.
207 * Overridden by implementing module.
208 * @param source Source user removing the parameter
209 * @param channel Channel the parameter is being removed from
210 * @param parameter The actual parameter being removed
212 virtual void TellNotSet(User* source, Channel* channel, std::string& parameter);
215 inline ListModeBase::ModeList* ListModeBase::GetList(Channel* channel)
217 ChanData* cd = extItem.get(channel);