]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/mode.h
Create a name -> ModeHandler* map
[user/henk/code/inspircd.git] / include / mode.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2004-2006, 2008 Craig Edwards <craigedwards@brainbox.cc>
6  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
7  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
8  *
9  * This file is part of InspIRCd.  InspIRCd is free software: you can
10  * redistribute it and/or modify it under the terms of the GNU General Public
11  * License as published by the Free Software Foundation, version 2.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22
23 #pragma once
24
25 #include "ctables.h"
26
27 /**
28  * Holds the values for different type of modes
29  * that can exist, USER or CHANNEL type.
30  */
31 enum ModeType
32 {
33         /** User mode */
34         MODETYPE_USER = 0,
35         /** Channel mode */
36         MODETYPE_CHANNEL = 1
37 };
38
39 /**
40  * Holds mode actions - modes can be allowed or denied.
41  */
42 enum ModeAction
43 {
44         MODEACTION_DENY = 0, /* Drop the mode change, AND a parameter if its a parameterized mode */
45         MODEACTION_ALLOW = 1 /* Allow the mode */
46 };
47
48 /**
49  * These fixed values can be used to proportionally compare module-defined prefixes to known values.
50  * For example, if your module queries a Channel, and is told that user 'joebloggs' has the prefix
51  * '$', and you dont know what $ means, then you can compare it to these three values to determine
52  * its worth against them. For example if '$' had a value of 15000, you would know it is of higher
53  * status than voice, but lower status than halfop.
54  * No two modes should have equal prefix values.
55  */
56 enum PrefixModeValue
57 {
58         /* +v */
59         VOICE_VALUE     =       10000,
60         /* +h */
61         HALFOP_VALUE    =       20000,
62         /* +o */
63         OP_VALUE        =       30000
64 };
65
66 enum ParamSpec
67 {
68         /** No parameters */
69         PARAM_NONE,
70         /** Parameter required on mode setting only */
71         PARAM_SETONLY,
72         /** Parameter always required */
73         PARAM_ALWAYS
74 };
75
76 class PrefixMode;
77 class ListModeBase;
78 class ParamModeBase;
79
80 /** Each mode is implemented by ONE ModeHandler class.
81  * You must derive ModeHandler and add the child class to
82  * the list of modes handled by the ircd, using
83  * ModeParser::AddMode. When the mode you implement is
84  * set by a user, the virtual function OnModeChange is
85  * called. If you specify a value greater than 0 for
86  * parameters_on or parameters_off, then when the mode is
87  * set or unset respectively, std::string &parameter will
88  * contain the parameter given by the user, else it will
89  * contain an empty string. You may alter this parameter
90  * string, and if you alter it to an empty string, and your
91  * mode is expected to have a parameter, then this is
92  * equivalent to returning MODEACTION_DENY.
93  */
94 class CoreExport ModeHandler : public ServiceProvider
95 {
96  public:
97         enum Class
98         {
99                 MC_PREFIX,
100                 MC_LIST,
101                 MC_PARAM,
102                 MC_OTHER
103         };
104
105  protected:
106         /**
107          * The mode parameter translation type
108          */
109         TranslateType m_paramtype;
110
111         /** What kind of parameters does the mode take?
112          */
113         ParamSpec parameters_taken;
114
115         /**
116          * The mode letter you're implementing.
117          */
118         char mode;
119
120         /**
121          * True if the mode requires oper status
122          * to set.
123          */
124         bool oper;
125
126         /**
127          * Mode is a 'list' mode. The behaviour
128          * of your mode is now set entirely within
129          * the class as of the 1.1 api, rather than
130          * inside the mode parser as in the 1.0 api,
131          * so the only use of this value (along with
132          * IsListMode()) is for the core to determine
133          * wether your module can produce 'lists' or not
134          * (e.g. banlists, etc)
135          */
136         bool list;
137
138         /**
139          * The mode type, either MODETYPE_USER or
140          * MODETYPE_CHANNEL.
141          */
142         ModeType m_type;
143
144         /** The object type of this mode handler
145          */
146         const Class type_id;
147
148         /** The prefix char needed on channel to use this mode,
149          * only checked for channel modes
150          */
151         int levelrequired;
152
153  public:
154         /**
155          * The constructor for ModeHandler initalizes the mode handler.
156          * The constructor of any class you derive from ModeHandler should
157          * probably call this constructor with the parameters set correctly.
158          * @param me The module which created this mode
159          * @param name A one-word name for the mode
160          * @param modeletter The mode letter you wish to handle
161          * @param params Parameters taken by the mode
162          * @param type Type of the mode (MODETYPE_USER or MODETYPE_CHANNEL)
163          * @param mclass The object type of this mode handler, one of ModeHandler::Class
164          */
165         ModeHandler(Module* me, const std::string& name, char modeletter, ParamSpec params, ModeType type, Class mclass = MC_OTHER);
166         virtual CullResult cull();
167         virtual ~ModeHandler();
168         /**
169          * Returns true if the mode is a list mode
170          */
171         bool IsListMode() const { return list; }
172
173         /**
174          * Check whether this mode is a prefix mode
175          * @return non-NULL if this mode is a prefix mode, NULL otherwise
176          */
177         PrefixMode* IsPrefixMode();
178
179         /**
180          * Check whether this mode handler inherits from ListModeBase
181          * @return non-NULL if this mode handler inherits from ListModeBase, NULL otherwise
182          */
183         ListModeBase* IsListModeBase();
184
185         /**
186          * Check whether this mode handler inherits from ListModeBase
187          * @return non-NULL if this mode handler inherits from ParamModeBase, NULL otherwise
188          */
189         ParamModeBase* IsParameterMode();
190
191         /**
192          * Returns the mode's type
193          */
194         inline ModeType GetModeType() const { return m_type; }
195         /**
196          * Returns the mode's parameter translation type
197          */
198         inline TranslateType GetTranslateType() const { return m_paramtype; }
199         /**
200          * Returns true if the mode can only be set/unset by an oper
201          */
202         inline bool NeedsOper() const { return oper; }
203         /**
204          * Returns the number of parameters for the mode. Any non-zero
205          * value should be considered to be equivalent to one.
206          * @param adding If this is true, the number of parameters required to set the mode should be returned, otherwise the number of parameters required to unset the mode shall be returned.
207          * @return The number of parameters the mode expects
208          */
209         int GetNumParams(bool adding);
210         /**
211          * Returns the mode character this handler handles.
212          * @return The mode character
213          */
214         inline char GetModeChar() { return mode; }
215
216         /** For user modes, return the current parameter, if any
217          */
218         virtual std::string GetUserParameter(User* useor);
219
220         /**
221          * Called when a channel mode change access check for your mode occurs.
222          * @param source Contains the user setting the mode.
223          * @param channel contains the destination channel the modes are being set on.
224          * @param parameter The parameter for your mode. This is modifiable.
225          * @param adding This value is true when the mode is being set, or false when it is being unset.
226          * @return allow, deny, or passthru to check against the required level
227          */
228         virtual ModResult AccessCheck(User* source, Channel* channel, std::string &parameter, bool adding);
229
230         /**
231          * Called when a mode change for your mode occurs.
232          * @param source Contains the user setting the mode.
233          * @param dest For usermodes, contains the destination user the mode is being set on. For channelmodes, this is an undefined value.
234          * @param channel For channel modes, contains the destination channel the modes are being set on. For usermodes, this is an undefined value.
235          * @param parameter The parameter for your mode, if you indicated that your mode requires a parameter when being set or unset. Note that
236          * if you alter this value, the new value becomes the one displayed and send out to the network, also, if you set this to an empty string
237          * but you specified your mode REQUIRES a parameter, this is equivalent to returning MODEACTION_DENY and will prevent the mode from being
238          * displayed.
239          * @param adding This value is true when the mode is being set, or false when it is being unset.
240          * @return MODEACTION_ALLOW to allow the mode, or MODEACTION_DENY to prevent the mode, also see the description of 'parameter'.
241          */
242         virtual ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding); /* Can change the mode parameter as its a ref */
243         /**
244          * If your mode is a listmode, then this method will be called for displaying an item list, e.g. on MODE \#channel +modechar
245          * without any parameter or other modes in the command.
246          * @param user The user issuing the command
247          * @param channel The channel they're requesting an item list of (e.g. a banlist, or an exception list etc)
248          */
249         virtual void DisplayList(User* user, Channel* channel);
250
251         /** In the event that the mode should be given a parameter, and no parameter was provided, this method is called.
252          * This allows you to give special information to the user, or handle this any way you like.
253          * @param user The user issuing the mode change
254          * @param dest For user mode changes, the target of the mode. For channel mode changes, NULL.
255          * @param channel For channel mode changes, the target of the mode. For user mode changes, NULL.
256          */
257         virtual void OnParameterMissing(User* user, User* dest, Channel* channel);
258
259         /**
260          * If your mode is a listmode, this method will be called to display an empty list (just the end of list numeric)
261          * @param user The user issuing the command
262          * @param channel The channel tehy're requesting an item list of (e.g. a banlist, or an exception list etc)
263          */
264         virtual void DisplayEmptyList(User* user, Channel* channel);
265
266         /**
267          * If your mode needs special action during a server sync to determine which side wins when comparing timestamps,
268          * override this function and use it to return true or false. The default implementation just returns true if
269          * theirs < ours. This will only be called for non-listmodes with parameters, when adding the mode and where
270          * theirs == ours (therefore the default implementation will always return false).
271          * @param their_param Their parameter if the mode has a parameter
272          * @param our_param Our parameter if the mode has a parameter
273          * @param channel The channel we are checking against
274          * @return True if the other side wins the merge, false if we win the merge for this mode.
275          */
276         virtual bool ResolveModeConflict(std::string &their_param, const std::string &our_param, Channel* channel);
277
278         /**
279          * When a MODETYPE_USER mode handler is being removed, the core will call this method for every user on the server.
280          * The usermode will be removed using the appropiate server mode using InspIRCd::SendMode().
281          * @param user The user which the server wants to remove your mode from
282          */
283         void RemoveMode(User* user);
284
285         /**
286          * When a MODETYPE_CHANNEL mode handler is being removed, the server will call this method for every channel on the server.
287          * The mode handler has to populate the given modestacker with mode changes that remove the mode from the channel.
288          * The default implementation of this method can remove all kinds of channel modes except listmodes.
289          * In the case of listmodes, the entire list of items must be added to the modestacker (which is handled by ListModeBase,
290          * so if you inherit from it or your mode can be removed by the default implementation then you do not have to implement
291          * this function).
292          * @param channel The channel which the server wants to remove your mode from
293          * @param stack The mode stack to add the mode change to
294          */
295         virtual void RemoveMode(Channel* channel, irc::modestacker& stack);
296
297         inline unsigned int GetLevelRequired() const { return levelrequired; }
298 };
299
300 /**
301  * Prefix modes are channel modes that grant a specific rank to members having prefix mode set.
302  * They require a parameter when setting and unsetting; the parameter is always a member of the channel.
303  * A prefix mode may be set on any number of members on a channel, but for a given member a given prefix
304  * mode is either set or not set, in other words members cannot have the same prefix mode set more than once.
305  *
306  * A rank of a member is defined as the rank given by the 'strongest' prefix mode that member has.
307  * Other parts of the IRCd use this rank to determine whether a channel action is allowable for a user or not.
308  * The rank of a prefix mode is constant, i.e. the same rank value is given to all users having that prefix mode set.
309  *
310  * Note that it is possible that the same action requires a different rank on a different channel;
311  * for example changing the topic on a channel having +t set requires a rank that is >= than the rank of a halfop,
312  * but there is no such restriction when +t isn't set.
313  */
314 class CoreExport PrefixMode : public ModeHandler
315 {
316  protected:
317         /** The prefix character granted by this mode. '@' for op, '+' for voice, etc.
318          * If 0, this mode does not have a visible prefix character.
319          */
320         char prefix;
321
322         /** The prefix rank of this mode, used to compare prefix
323          * modes
324          */
325         unsigned int prefixrank;
326
327  public:
328         /**
329          * Constructor
330          * @param Creator The module creating this mode
331          * @param Name The user-friendly one word name of the prefix mode, e.g.: "op", "voice"
332          * @param ModeLetter The mode letter of this mode
333          */
334         PrefixMode(Module* Creator, const std::string& Name, char ModeLetter);
335
336         /**
337          * Handles setting and unsetting the prefix mode.
338          * Finds the given member of the given channel, if it's not found an error message is sent to 'source'
339          * and MODEACTION_DENY is returned. Otherwise the mode change is attempted.
340          * @param source Source of the mode change, an error message is sent to this user if the target is not found
341          * @param dest Unused
342          * @param channel The channel the mode change is happening on
343          * @param param The nickname or uuid of the target user
344          * @param adding True when the mode is being set, false when it is being unset
345          * @return MODEACTION_ALLOW if the change happened, MODEACTION_DENY if no change happened
346          * The latter occurs either when the member cannot be found or when the member already has this prefix set
347          * (when setting) or doesn't have this prefix set (when unsetting).
348          */
349         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& param, bool adding);
350
351         /**
352          * Removes this prefix mode from all users on the given channel
353          * @param chan The channel which the server wants to remove your mode from
354          * @param stack The mode stack to add the mode change to
355          */
356         void RemoveMode(Channel* chan, irc::modestacker& stack);
357
358         /**
359          * Mode prefix or 0. If this is defined, you should
360          * also implement GetPrefixRank() to return an integer
361          * value for this mode prefix.
362          */
363         char GetPrefix() const { return prefix; }
364
365         /**
366          * Get the 'value' of this modes prefix.
367          * determines which to display when there are multiple.
368          * The mode with the highest value is ranked first. See the
369          * PrefixModeValue enum and Channel::GetPrefixValue() for
370          * more information.
371          */
372         unsigned int GetPrefixRank() const { return prefixrank; }
373 };
374
375 /** A prebuilt mode handler which handles a simple user mode, e.g. no parameters, usable by any user, with no extra
376  * behaviour to the mode beyond the basic setting and unsetting of the mode, not allowing the mode to be set if it
377  * is already set and not allowing it to be unset if it is already unset.
378  * An example of a simple user mode is user mode +w.
379  */
380 class CoreExport SimpleUserModeHandler : public ModeHandler
381 {
382  public:
383         SimpleUserModeHandler(Module* Creator, const std::string& Name, char modeletter)
384                 : ModeHandler(Creator, Name, modeletter, PARAM_NONE, MODETYPE_USER) {}
385         virtual ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding);
386 };
387
388 /** A prebuilt mode handler which handles a simple channel mode, e.g. no parameters, usable by any user, with no extra
389  * behaviour to the mode beyond the basic setting and unsetting of the mode, not allowing the mode to be set if it
390  * is already set and not allowing it to be unset if it is already unset.
391  * An example of a simple channel mode is channel mode +s.
392  */
393 class CoreExport SimpleChannelModeHandler : public ModeHandler
394 {
395  public:
396         SimpleChannelModeHandler(Module* Creator, const std::string& Name, char modeletter)
397                 : ModeHandler(Creator, Name, modeletter, PARAM_NONE, MODETYPE_CHANNEL) {}
398         virtual ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding);
399 };
400
401 /**
402  * The ModeWatcher class can be used to alter the behaviour of a mode implemented
403  * by the core or by another module. To use ModeWatcher, derive a class from it,
404  * and attach it to the mode using Server::AddModeWatcher and Server::DelModeWatcher.
405  * A ModeWatcher will be called both before and after the mode change.
406  */
407 class CoreExport ModeWatcher : public classbase
408 {
409  private:
410         /**
411          * The mode name this class is watching
412          */
413         const std::string mode;
414
415         /**
416          * The mode type being watched (user or channel)
417          */
418         ModeType m_type;
419
420  public:
421         ModuleRef creator;
422         /**
423          * The constructor initializes the mode and the mode type
424          */
425         ModeWatcher(Module* creator, const std::string& modename, ModeType type);
426         /**
427          * The default destructor does nothing.
428          */
429         virtual ~ModeWatcher();
430
431         /**
432          * Get the mode name being watched
433          * @return The mode name being watched
434          */
435         const std::string& GetModeName() const { return mode; }
436
437         /**
438          * Get the mode type being watched
439          * @return The mode type being watched (user or channel)
440          */
441         ModeType GetModeType();
442
443         /**
444          * Before the mode character is processed by its handler, this method will be called.
445          * @param source The sender of the mode
446          * @param dest The target user for the mode, if you are watching a user mode
447          * @param channel The target channel for the mode, if you are watching a channel mode
448          * @param parameter The parameter of the mode, if the mode is supposed to have a parameter.
449          * If you alter the parameter you are given, the mode handler will see your atered version
450          * when it handles the mode.
451          * @param adding True if the mode is being added and false if it is being removed
452          * @return True to allow the mode change to go ahead, false to abort it. If you abort the
453          * change, the mode handler (and ModeWatcher::AfterMode()) will never see the mode change.
454          */
455         virtual bool BeforeMode(User* source, User* dest, Channel* channel, std::string& parameter, bool adding);
456         /**
457          * After the mode character has been processed by the ModeHandler, this method will be called.
458          * @param source The sender of the mode
459          * @param dest The target user for the mode, if you are watching a user mode
460          * @param channel The target channel for the mode, if you are watching a channel mode
461          * @param parameter The parameter of the mode, if the mode is supposed to have a parameter.
462          * You cannot alter the parameter here, as the mode handler has already processed it.
463          * @param adding True if the mode is being added and false if it is being removed
464          */
465         virtual void AfterMode(User* source, User* dest, Channel* channel, const std::string& parameter, bool adding);
466 };
467
468 typedef std::multimap<std::string, ModeWatcher*>::iterator ModeWatchIter;
469
470 /** The mode parser handles routing of modes and handling of mode strings.
471  * It marshalls, controls and maintains both ModeWatcher and ModeHandler classes,
472  * parses client to server MODE strings for user and channel modes, and performs
473  * processing for the 004 mode list numeric, amongst other things.
474  */
475 class CoreExport ModeParser
476 {
477  private:
478         /** Last item in the ModeType enum
479          */
480         static const unsigned int MODETYPE_LAST = 2;
481
482         /** Type of the container that maps mode names to ModeHandlers
483          */
484         typedef TR1NS::unordered_map<std::string, ModeHandler*, irc::insensitive, irc::StrHashComp> ModeHandlerMap;
485
486         /** Mode handlers for each mode, to access a handler subtract
487          * 65 from the ascii value of the mode letter.
488          * The upper bit of the value indicates if its a usermode
489          * or a channel mode, so we have 256 of them not 64.
490          */
491         ModeHandler* modehandlers[MODETYPE_LAST][128];
492
493         /** A map of mode handlers keyed by their name
494          */
495         ModeHandlerMap modehandlersbyname[MODETYPE_LAST];
496
497         /** Lists of mode handlers by type
498          */
499         struct
500         {
501                 /** List of mode handlers that inherit from ListModeBase
502                  */
503                 std::vector<ListModeBase*> list;
504
505                 /** List of mode handlers that inherit from PrefixMode
506                  */
507                 std::vector<PrefixMode*> prefix;
508         } mhlist;
509
510         /** Mode watcher classes
511          */
512         std::multimap<std::string, ModeWatcher*> modewatchermap;
513
514         /** Displays the current modes of a channel or user.
515          * Used by ModeParser::Process.
516          */
517         void DisplayCurrentModes(User *user, User* targetuser, Channel* targetchannel, const char* text);
518         /** Displays the value of a list mode
519          * Used by ModeParser::Process.
520          */
521         void DisplayListModes(User* user, Channel* chan, std::string &mode_sequence);
522
523         /**
524          * Attempts to apply a mode change to a user or channel
525          */
526         ModeAction TryMode(User* user, User* targu, Channel* targc, bool adding, unsigned char mode, std::string &param, bool SkipACL);
527
528         /** Returns a list of user or channel mode characters.
529          * Used for constructing the parts of the mode list in the 004 numeric.
530          * @param mt Controls whether to list user modes or channel modes
531          * @param needparam Return modes only if they require a parameter to be set
532          * @return The available mode letters that satisfy the given conditions
533          */
534         std::string CreateModeList(ModeType mt, bool needparam = false);
535
536         /** Recreate the cached mode list that is displayed in the 004 numeric
537          * in Cached004ModeList.
538          * Called when a mode handler is added or removed.
539          */
540         void RecreateModeListFor004Numeric();
541
542         /** The string representing the last set of modes to be parsed.
543          * Use GetLastParse() to get this value, to be used for  display purposes.
544          */
545         std::string LastParse;
546         std::vector<std::string> LastParseParams;
547         std::vector<TranslateType> LastParseTranslate;
548
549         unsigned int sent[256];
550
551         unsigned int seq;
552
553         /** Cached mode list for use in 004 numeric
554          */
555         std::string Cached004ModeList;
556
557  public:
558         typedef std::vector<ListModeBase*> ListModeList;
559         typedef std::vector<PrefixMode*> PrefixModeList;
560
561         typedef unsigned int ModeProcessFlag;
562         enum ModeProcessFlags
563         {
564                 /** If only this flag is specified, the mode change will be global
565                  * and parameter modes will have their parameters explicitly set
566                  * (not merged). This is the default.
567                  */
568                 MODE_NONE = 0,
569
570                 /** If this flag is set then the parameters of non-listmodes will be
571                  * merged according to their conflict resolution rules.
572                  * Does not affect user modes, channel modes without a parameter and
573                  * listmodes.
574                  */
575                 MODE_MERGE = 1,
576
577                 /** If this flag is set then the mode change won't be handed over to
578                  * the linking module to be sent to other servers, but will be processed
579                  * locally and sent to local user(s) as usual.
580                  */
581                 MODE_LOCALONLY = 2
582         };
583
584         ModeParser();
585         ~ModeParser();
586
587         /** Initialize all built-in modes
588          */
589         static void InitBuiltinModes();
590
591         /** Tidy a banmask. This makes a banmask 'acceptable' if fields are left out.
592          * E.g.
593          *
594          * nick -> nick!*@*
595          *
596          * nick!ident -> nick!ident@*
597          *
598          * host.name -> *!*\@host.name
599          *
600          * ident@host.name -> *!ident\@host.name
601          *
602          * This method can be used on both IPV4 and IPV6 user masks.
603          */
604         static void CleanMask(std::string &mask);
605         /** Get the last string to be processed, as it was sent to the user or channel.
606          * Use this to display a string you just sent to be parsed, as the actual output
607          * may be different to what you sent after it has been 'cleaned up' by the parser.
608          * @return Last parsed string, as seen by users.
609          */
610         const std::string& GetLastParse() const { return LastParse; }
611         const std::vector<std::string>& GetLastParseParams() { return LastParseParams; }
612         const std::vector<TranslateType>& GetLastParseTranslate() { return LastParseTranslate; }
613         /** Add a mode to the mode parser.
614          * @return True if the mode was successfully added.
615          */
616         bool AddMode(ModeHandler* mh);
617         /** Delete a mode from the mode parser.
618          * When a mode is deleted, the mode handler will be called
619          * for every user (if it is a user mode) or for every  channel
620          * (if it is a channel mode) to unset the mode on all objects.
621          * This prevents modes staying in the system which no longer exist.
622          * @param mh The mode handler to remove
623          * @return True if the mode was successfully removed.
624          */
625         bool DelMode(ModeHandler* mh);
626
627         /** Add a mode watcher.
628          * A mode watcher is triggered before and after a mode handler is
629          * triggered. See the documentation of class ModeWatcher for more
630          * information.
631          * @param mw The ModeWatcher you want to add
632          */
633         void AddModeWatcher(ModeWatcher* mw);
634
635         /** Delete a mode watcher.
636          * A mode watcher is triggered before and after a mode handler is
637          * triggered. See the documentation of class ModeWatcher for more
638          * information.
639          * @param mw The ModeWatcher you want to delete
640          * @return True if the ModeWatcher was deleted correctly
641          */
642         bool DelModeWatcher(ModeWatcher* mw);
643         /** Process a set of mode changes from a server or user.
644          * @param parameters The parameters of the mode change, in the format
645          * they would be from a MODE command.
646          * @param user The source of the mode change, can be a server user.
647          * @param flags Optional flags controlling how the mode change is processed,
648          * defaults to MODE_NONE.
649          */
650         void Process(const std::vector<std::string>& parameters, User* user, ModeProcessFlag flags = MODE_NONE);
651
652         /** Find the mode handler for a given mode and type.
653          * @param modeletter mode letter to search for
654          * @param mt type of mode to search for, user or channel
655          * @returns a pointer to a ModeHandler class, or NULL of there isnt a handler for the given mode
656          */
657         ModeHandler* FindMode(unsigned const char modeletter, ModeType mt);
658
659         /** Find the mode handler for the given prefix mode
660          * @param modeletter The mode letter to search for
661          * @return A pointer to the PrefixMode or NULL if the mode wasn't found or it isn't a prefix mode
662          */
663         PrefixMode* FindPrefixMode(unsigned char modeletter);
664
665         /** Find a mode handler by its prefix.
666          * If there is no mode handler with the given prefix, NULL will be returned.
667          * @param pfxletter The prefix to find, e.g. '@'
668          * @return The mode handler which handles this prefix, or NULL if there is none.
669          */
670         PrefixMode* FindPrefix(unsigned const char pfxletter);
671
672         /** Returns a list of modes, space seperated by type:
673          * 1. User modes
674          * 2. Channel modes
675          * 3. Channel modes that require a parameter when set
676          * This is sent to users as the last part of the 004 numeric
677          */
678         const std::string& GetModeListFor004Numeric();
679
680         /** Generates a list of modes, comma seperated by type:
681          *  1; Listmodes EXCEPT those with a prefix
682          *  2; Modes that take a param when adding or removing
683          *  3; Modes that only take a param when adding
684          *  4; Modes that dont take a param
685          */
686         std::string GiveModeList(ModeType mt);
687
688         /** This returns the PREFIX=(ohv)@%+ section of the 005 numeric, or
689          * just the "@%+" part if the parameter false
690          */
691         std::string BuildPrefixes(bool lettersAndModes = true);
692
693         /** Get a list of all mode handlers that inherit from ListModeBase
694          * @return A list containing ListModeBase modes
695          */
696         const ListModeList& GetListModes() const { return mhlist.list; }
697
698         /** Get a list of all prefix modes
699          * @return A list containing all prefix modes
700          */
701         const PrefixModeList& GetPrefixModes() const { return mhlist.prefix; }
702 };
703
704 inline const std::string& ModeParser::GetModeListFor004Numeric()
705 {
706         return Cached004ModeList;
707 }
708
709 inline PrefixMode* ModeHandler::IsPrefixMode()
710 {
711         return (this->type_id == MC_PREFIX ? static_cast<PrefixMode*>(this) : NULL);
712 }
713
714 inline ListModeBase* ModeHandler::IsListModeBase()
715 {
716         return (this->type_id == MC_LIST ? reinterpret_cast<ListModeBase*>(this) : NULL);
717 }
718
719 inline ParamModeBase* ModeHandler::IsParameterMode()
720 {
721         return (this->type_id == MC_PARAM ? reinterpret_cast<ParamModeBase*>(this) : NULL);
722 }