]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/listmode.h
ListModeBase: Minor changes to original u_listmode code
[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         struct ListItem
29         {
30                 std::string setter;
31                 std::string mask;
32                 time_t time;
33                 ListItem(const std::string& Mask, const std::string& Setter, time_t Time)
34                         : setter(Setter), mask(Mask), time(Time) { }
35         };
36
37         /** Items stored in the channel's list
38          */
39         typedef std::list<ListItem> ModeList;
40
41  private:
42         /** The number of items a listmode's list may contain
43          */
44         struct ListLimit
45         {
46                 std::string mask;
47                 unsigned int limit;
48                 ListLimit(const std::string& Mask, unsigned int Limit) : mask(Mask), limit(Limit) { }
49         };
50
51         /** Max items per channel by name
52          */
53         typedef std::vector<ListLimit> limitlist;
54
55  protected:
56         /** Numeric to use when outputting the list
57          */
58         unsigned int listnumeric;
59         /** Numeric to indicate end of list
60          */
61         unsigned int endoflistnumeric;
62         /** String to send for end of list
63          */
64         std::string endofliststring;
65         /** Automatically tidy up entries
66          */
67         bool tidy;
68         /** Config tag to check for max items per channel
69          */
70         std::string configtag;
71         /** Limits on a per-channel basis read from the tag
72          * specified in ListModeBase::configtag
73          */
74         limitlist chanlimits;
75
76         /** Storage key
77          */
78         SimpleExtItem<ModeList> extItem;
79
80  public:
81         /** Constructor.
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
89          */
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");
91
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
95          */
96         unsigned int GetLimit(Channel* channel);
97
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
101          */
102         ModeList* GetList(Channel* channel);
103
104         /** Display the list for this mode
105          * See mode.h
106          * @param user The user to send the list to
107          * @param channel The channel the user is requesting the list for
108          */
109         virtual void DisplayList(User* user, Channel* channel);
110
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
115          * See mode.h
116          */
117         virtual void DisplayEmptyList(User* user, Channel* channel);
118
119         /** Remove all instances of the mode from a channel.
120          * See mode.h
121          * @param channel The channel to remove all instances of the mode from
122          */
123         virtual void RemoveMode(Channel* channel, irc::modestacker* stack);
124
125         /** Listmodes don't get set on users, no-op
126         */
127         virtual void RemoveMode(User*, irc::modestacker* stack);
128
129         /** Perform a rehash of this mode's configuration data
130          */
131         virtual void DoRehash();
132
133         /** Populate the Implements list with the correct events for a List Mode
134          */
135         virtual void DoImplements(Module* m);
136
137         /** Handle the list mode.
138          * See mode.h
139          */
140         virtual ModeAction OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding);
141
142         /** Syncronize channel item list with another server.
143          * See modules.h
144          * @param chan Channel to syncronize
145          * @param proto Protocol module pointer
146          * @param opaque Opaque connection handle
147          */
148         virtual void DoSyncChannel(Channel* chan, Module* proto, void* opaque);
149
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
156          */
157         virtual bool ValidateParam(User* user, Channel* channel, std::string& parameter);
158
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
164          */
165         virtual void TellListTooLong(User* source, Channel* channel, std::string& parameter);
166
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
172          */
173         virtual void TellAlreadyOnList(User* source, Channel* channel, std::string& parameter);
174
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
180          */
181         virtual void TellNotSet(User* source, Channel* channel, std::string& parameter);
182 };
183
184 inline ListModeBase::ModeList* ListModeBase::GetList(Channel* channel)
185 {
186         return extItem.get(channel);
187 }