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
36 /** Items stored in the channel's list
38 typedef std::list<ListItem> ModeList;
41 /** The number of items a listmode's list may contain
50 /** Max items per channel by name
52 typedef std::list<ListLimit> limitlist;
55 /** Numeric to use when outputting the list
57 unsigned int listnumeric;
58 /** Numeric to indicate end of list
60 unsigned int endoflistnumeric;
61 /** String to send for end of list
63 std::string endofliststring;
64 /** Automatically tidy up entries
67 /** Config tag to check for max items per channel
69 std::string configtag;
70 /** Limits on a per-channel basis read from the tag
71 * specified in ListModeBase::configtag
77 SimpleExtItem<ModeList> extItem;
81 * @param Instance The creator of this class
82 * @param modechar Mode character
83 * @param eolstr End of list string
84 * @param lnum List numeric
85 * @param eolnum End of list numeric
86 * @param autotidy Automatically tidy list entries on add
87 * @param ctag Configuration tag to get limits from
89 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");
91 /** Get limit of this mode on a channel
92 * @param channel The channel to inspect
93 * @return Maximum number of modes of this type that can be placed on the given channel
95 unsigned int GetLimit(Channel* channel);
97 /** Retrieves the list of all modes set on the given channel
98 * @param channel Channel to get the list from
99 * @return A list with all modes of this type set on the given channel, can be NULL
101 ModeList* GetList(Channel* channel);
103 /** Display the list for this mode
105 * @param user The user to send the list to
106 * @param channel The channel the user is requesting the list for
108 virtual void DisplayList(User* user, Channel* channel);
110 /** Tell a user that a list contains no elements.
111 * Sends 'eolnum' numeric with text 'eolstr', unless overridden (see constructor)
112 * @param user The user issuing the command
113 * @param channel The channel that has the empty list
116 virtual void DisplayEmptyList(User* user, Channel* channel);
118 /** Remove all instances of the mode from a channel.
120 * @param channel The channel to remove all instances of the mode from
122 virtual void RemoveMode(Channel* channel, irc::modestacker* stack);
124 /** Listmodes don't get set on users, no-op
126 virtual void RemoveMode(User*, irc::modestacker* stack);
128 /** Perform a rehash of this mode's configuration data
130 virtual void DoRehash();
132 /** Populate the Implements list with the correct events for a List Mode
134 virtual void DoImplements(Module* m);
136 /** Handle the list mode.
139 virtual ModeAction OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding);
141 /** Syncronize channel item list with another server.
143 * @param chan Channel to syncronize
144 * @param proto Protocol module pointer
145 * @param opaque Opaque connection handle
147 virtual void DoSyncChannel(Channel* chan, Module* proto, void* opaque);
149 /** Validate parameters.
150 * Overridden by implementing module.
151 * @param source Source user adding the parameter
152 * @param channel Channel the parameter is being added to
153 * @param parameter The actual parameter being added
154 * @return true if the parameter is valid
156 virtual bool ValidateParam(User* user, Channel* channel, std::string& parameter);
158 /** Tell the user the list is too long.
159 * Overridden by implementing module.
160 * @param source Source user adding the parameter
161 * @param channel Channel the parameter is being added to
162 * @param parameter The actual parameter being added
164 virtual void TellListTooLong(User* source, Channel* channel, std::string& parameter);
166 /** Tell the user an item is already on the list.
167 * Overridden by implementing module.
168 * @param source Source user adding the parameter
169 * @param channel Channel the parameter is being added to
170 * @param parameter The actual parameter being added
172 virtual void TellAlreadyOnList(User* source, Channel* channel, std::string& parameter);
174 /** Tell the user that the parameter is not in the list.
175 * Overridden by implementing module.
176 * @param source Source user removing the parameter
177 * @param channel Channel the parameter is being removed from
178 * @param parameter The actual parameter being removed
180 virtual void TellNotSet(User* source, Channel* channel, std::string& parameter);
183 inline ListModeBase::ModeList* ListModeBase::GetList(Channel* channel)
185 return extItem.get(channel);