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/>.
21 /** The base class for list modes, should be inherited.
23 class ListModeBase : public ModeHandler
26 /** An item in a listmode's list
33 ListItem(const std::string& Mask, const std::string& Setter, time_t Time)
34 : setter(Setter), mask(Mask), time(Time) { }
37 /** Items stored in the channel's list
39 typedef std::list<ListItem> ModeList;
42 /** The number of items a listmode's list may contain
48 ListLimit(const std::string& Mask, unsigned int Limit) : mask(Mask), limit(Limit) { }
51 /** Max items per channel by name
53 typedef std::vector<ListLimit> limitlist;
56 /** Numeric to use when outputting the list
58 unsigned int listnumeric;
59 /** Numeric to indicate end of list
61 unsigned int endoflistnumeric;
62 /** String to send for end of list
64 std::string endofliststring;
65 /** Automatically tidy up entries
68 /** Config tag to check for max items per channel
70 std::string configtag;
71 /** Limits on a per-channel basis read from the tag
72 * specified in ListModeBase::configtag
78 SimpleExtItem<ModeList> extItem;
82 * @param Instance The creator of this class
83 * @param modechar Mode character
84 * @param eolstr End of list string
85 * @param lnum List numeric
86 * @param eolnum End of list numeric
87 * @param autotidy Automatically tidy list entries on add
88 * @param ctag Configuration tag to get limits from
90 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");
92 /** Get limit of this mode on a channel
93 * @param channel The channel to inspect
94 * @return Maximum number of modes of this type that can be placed on the given channel
96 unsigned int GetLimit(Channel* channel);
98 /** Retrieves the list of all modes set on the given channel
99 * @param channel Channel to get the list from
100 * @return A list with all modes of this type set on the given channel, can be NULL
102 ModeList* GetList(Channel* channel);
104 /** Display the list for this mode
106 * @param user The user to send the list to
107 * @param channel The channel the user is requesting the list for
109 virtual void DisplayList(User* user, Channel* channel);
111 /** Tell a user that a list contains no elements.
112 * Sends 'eolnum' numeric with text 'eolstr', unless overridden (see constructor)
113 * @param user The user issuing the command
114 * @param channel The channel that has the empty list
117 virtual void DisplayEmptyList(User* user, Channel* channel);
119 /** Remove all instances of the mode from a channel.
121 * @param channel The channel to remove all instances of the mode from
123 virtual void RemoveMode(Channel* channel, irc::modestacker* stack);
125 /** Listmodes don't get set on users, no-op
127 virtual void RemoveMode(User*, irc::modestacker* stack);
129 /** Perform a rehash of this mode's configuration data
131 virtual void DoRehash();
133 /** Populate the Implements list with the correct events for a List Mode
135 virtual void DoImplements(Module* m);
137 /** Handle the list mode.
140 virtual ModeAction OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding);
142 /** Syncronize channel item list with another server.
144 * @param chan Channel to syncronize
145 * @param proto Protocol module pointer
146 * @param opaque Opaque connection handle
148 virtual void DoSyncChannel(Channel* chan, Module* proto, void* opaque);
150 /** Validate parameters.
151 * Overridden by implementing module.
152 * @param source Source user adding the parameter
153 * @param channel Channel the parameter is being added to
154 * @param parameter The actual parameter being added
155 * @return true if the parameter is valid
157 virtual bool ValidateParam(User* user, Channel* channel, std::string& parameter);
159 /** Tell the user the list is too long.
160 * Overridden by implementing module.
161 * @param source Source user adding the parameter
162 * @param channel Channel the parameter is being added to
163 * @param parameter The actual parameter being added
165 virtual void TellListTooLong(User* source, Channel* channel, std::string& parameter);
167 /** Tell the user an item is already on the list.
168 * Overridden by implementing module.
169 * @param source Source user adding the parameter
170 * @param channel Channel the parameter is being added to
171 * @param parameter The actual parameter being added
173 virtual void TellAlreadyOnList(User* source, Channel* channel, std::string& parameter);
175 /** Tell the user that the parameter is not in the list.
176 * Overridden by implementing module.
177 * @param source Source user removing the parameter
178 * @param channel Channel the parameter is being removed from
179 * @param parameter The actual parameter being removed
181 virtual void TellNotSet(User* source, Channel* channel, std::string& parameter);
184 inline ListModeBase::ModeList* ListModeBase::GetList(Channel* channel)
186 return extItem.get(channel);