]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/listmode.h
40c28f67f076d1a87b109b05dd92ba020304107f
[user/henk/code/inspircd.git] / include / listmode.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *
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.
9  *
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
13  * details.
14  *
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/>.
17  */
18
19 #pragma once
20
21 /** The base class for list modes, should be inherited.
22  */
23 class ListModeBase : public ModeHandler
24 {
25  public:
26         /** An item in a listmode's list
27          */
28         class ListItem
29         {
30         public:
31                 std::string nick;
32                 std::string mask;
33                 std::string time;
34         };
35
36         /** Items stored in the channel's list
37          */
38         typedef std::list<ListItem> ModeList;
39
40  private:
41         /** The number of items a listmode's list may contain
42          */
43         class ListLimit
44         {
45         public:
46                 std::string mask;
47                 unsigned int limit;
48         };
49
50         /** Max items per channel by name
51          */
52         typedef std::list<ListLimit> limitlist;
53
54  protected:
55         /** Numeric to use when outputting the list
56          */
57         unsigned int listnumeric;
58         /** Numeric to indicate end of list
59          */
60         unsigned int endoflistnumeric;
61         /** String to send for end of list
62          */
63         std::string endofliststring;
64         /** Automatically tidy up entries
65          */
66         bool tidy;
67         /** Config tag to check for max items per channel
68          */
69         std::string configtag;
70         /** Limits on a per-channel basis read from the tag
71          * specified in ListModeBase::configtag
72          */
73         limitlist chanlimits;
74
75         /** Storage key
76          */
77         SimpleExtItem<ModeList> extItem;
78
79  public:
80         /** Constructor.
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
88          */
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");
90
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
94          */
95         unsigned int GetLimit(Channel* channel);
96
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
100          */
101         ModeList* GetList(Channel* channel);
102
103         /** Display the list for this mode
104          * See mode.h
105          * @param user The user to send the list to
106          * @param channel The channel the user is requesting the list for
107          */
108         virtual void DisplayList(User* user, Channel* channel);
109
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
114          * See mode.h
115          */
116         virtual void DisplayEmptyList(User* user, Channel* channel);
117
118         /** Remove all instances of the mode from a channel.
119          * See mode.h
120          * @param channel The channel to remove all instances of the mode from
121          */
122         virtual void RemoveMode(Channel* channel, irc::modestacker* stack);
123
124         /** Listmodes don't get set on users, no-op
125         */
126         virtual void RemoveMode(User*, irc::modestacker* stack);
127
128         /** Perform a rehash of this mode's configuration data
129          */
130         virtual void DoRehash();
131
132         /** Populate the Implements list with the correct events for a List Mode
133          */
134         virtual void DoImplements(Module* m);
135
136         /** Handle the list mode.
137          * See mode.h
138          */
139         virtual ModeAction OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding);
140
141         /** Syncronize channel item list with another server.
142          * See modules.h
143          * @param chan Channel to syncronize
144          * @param proto Protocol module pointer
145          * @param opaque Opaque connection handle
146          */
147         virtual void DoSyncChannel(Channel* chan, Module* proto, void* opaque);
148
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
155          */
156         virtual bool ValidateParam(User* user, Channel* channel, std::string& parameter);
157
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
163          */
164         virtual void TellListTooLong(User* source, Channel* channel, std::string& parameter);
165
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
171          */
172         virtual void TellAlreadyOnList(User* source, Channel* channel, std::string& parameter);
173
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
179          */
180         virtual void TellNotSet(User* source, Channel* channel, std::string& parameter);
181 };
182
183 inline ListModeBase::ModeList* ListModeBase::GetList(Channel* channel)
184 {
185         return extItem.get(channel);
186 }