2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2018 B00mX0r <b00mx0r@aureus.pw>
5 * Copyright (C) 2013-2014 Attila Molnar <attilamolnar@hush.com>
6 * Copyright (C) 2013, 2017-2019 Sadie Powell <sadie@witchery.services>
8 * This file is part of InspIRCd. InspIRCd is free software: you can
9 * redistribute it and/or modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation, version 2.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 /** The base class for list modes, should be inherited.
26 class CoreExport ListModeBase : public ModeHandler
29 /** An item in a listmode's list
36 ListItem(const std::string& Mask, const std::string& Setter, time_t Time)
37 : setter(Setter), mask(Mask), time(Time) { }
40 /** Items stored in the channel's list
42 typedef std::vector<ListItem> ModeList;
51 ChanData() : maxitems(-1) { }
54 /** The number of items a listmode's list may contain
60 ListLimit(const std::string& Mask, unsigned int Limit) : mask(Mask), limit(Limit) { }
61 bool operator==(const ListLimit& other) const { return (this->mask == other.mask && this->limit == other.limit); }
64 /** Max items per channel by name
66 typedef std::vector<ListLimit> limitlist;
68 /** The default maximum list size. */
69 static const unsigned int DEFAULT_LIST_SIZE = 100;
71 /** Finds the limit of modes that can be placed on the given channel name according to the config
72 * @param channame The channel name to find the limit for
73 * @return The maximum number of modes of this type that we allow to be set on the given channel name
75 unsigned int FindLimit(const std::string& channame);
77 /** Returns the limit on the given channel for this mode.
78 * If the limit is cached then the cached value is returned,
79 * otherwise the limit is determined using FindLimit() and cached
80 * for later queries before it is returned
81 * @param channame The channel name to find the limit for
82 * @param cd The ChanData associated with channel channame
83 * @return The maximum number of modes of this type that we allow to be set on the given channel
85 unsigned int GetLimitInternal(const std::string& channame, ChanData* cd);
88 /** Numeric to use when outputting the list
90 unsigned int listnumeric;
92 /** Numeric to indicate end of list
94 unsigned int endoflistnumeric;
96 /** String to send for end of list
98 std::string endofliststring;
100 /** Automatically tidy up entries
104 /** Limits on a per-channel basis read from the \<listmode>
107 limitlist chanlimits;
111 SimpleExtItem<ChanData> extItem;
115 * @param Creator The creator of this class
116 * @param Name Mode name
117 * @param modechar Mode character
118 * @param eolstr End of list string
119 * @param lnum List numeric
120 * @param eolnum End of list numeric
121 * @param autotidy Automatically tidy list entries on add
123 ListModeBase(Module* Creator, const std::string& Name, char modechar, const std::string& eolstr, unsigned int lnum, unsigned int eolnum, bool autotidy);
125 /** Determines whether some channels have longer lists than others. */
126 bool HasVariableLength() const { return chanlimits.size() > 1; }
128 /** Get limit of this mode on a channel
129 * @param channel The channel to inspect
130 * @return Maximum number of modes of this type that can be placed on the given channel
132 unsigned int GetLimit(Channel* channel);
134 /** Gets the lower list limit for this listmode.
136 unsigned int GetLowerLimit();
138 /** Retrieves the list of all modes set on the given channel
139 * @param channel Channel to get the list from
140 * @return A list with all modes of this type set on the given channel, can be NULL
142 ModeList* GetList(Channel* channel);
144 /** Display the list for this mode
146 * @param user The user to send the list to
147 * @param channel The channel the user is requesting the list for
149 void DisplayList(User* user, Channel* channel) CXX11_OVERRIDE;
151 /** Tell a user that a list contains no elements.
152 * Sends 'eolnum' numeric with text 'eolstr', unless overridden (see constructor)
153 * @param user The user issuing the command
154 * @param channel The channel that has the empty list
157 void DisplayEmptyList(User* user, Channel* channel) CXX11_OVERRIDE;
159 /** Remove all instances of the mode from a channel.
160 * Populates the given modestack with modes that remove every instance of
161 * this mode from the channel.
162 * See mode.h for more details.
163 * @param channel The channel to remove all instances of the mode from
164 * @param changelist Mode change list to populate with the removal of this mode
166 void RemoveMode(Channel* channel, Modes::ChangeList& changelist) CXX11_OVERRIDE;
168 /** Perform a rehash of this mode's configuration data
172 /** Handle the list mode.
175 ModeAction OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding) CXX11_OVERRIDE;
177 /** Validate parameters.
178 * Overridden by implementing module.
179 * @param user Source user adding the parameter
180 * @param channel Channel the parameter is being added to
181 * @param parameter The actual parameter being added
182 * @return true if the parameter is valid
184 virtual bool ValidateParam(User* user, Channel* channel, std::string& parameter);
186 /** In the event that the mode should be given a parameter, and no parameter was provided, this method is called.
187 * This allows you to give special information to the user, or handle this any way you like.
188 * @param user The user issuing the mode change
189 * @param dest For user mode changes, the target of the mode. For channel mode changes, NULL.
190 * @param channel For channel mode changes, the target of the mode. For user mode changes, NULL.
193 virtual void OnParameterMissing(User* user, User* dest, Channel* channel) CXX11_OVERRIDE;
195 /** Tell the user the list is too long.
196 * Overridden by implementing module.
197 * @param source Source user adding the parameter
198 * @param channel Channel the parameter is being added to
199 * @param parameter The actual parameter being added
201 virtual void TellListTooLong(User* source, Channel* channel, std::string& parameter);
203 /** Tell the user an item is already on the list.
204 * Overridden by implementing module.
205 * @param source Source user adding the parameter
206 * @param channel Channel the parameter is being added to
207 * @param parameter The actual parameter being added
209 virtual void TellAlreadyOnList(User* source, Channel* channel, std::string& parameter);
211 /** Tell the user that the parameter is not in the list.
212 * Overridden by implementing module.
213 * @param source Source user removing the parameter
214 * @param channel Channel the parameter is being removed from
215 * @param parameter The actual parameter being removed
217 virtual void TellNotSet(User* source, Channel* channel, std::string& parameter);
220 inline ListModeBase::ModeList* ListModeBase::GetList(Channel* channel)
222 ChanData* cd = extItem.get(channel);