2 * InspIRCd -- Internet Relay Chat Daemon
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>
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.
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
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/>.
26 #include "modechange.h"
29 * Holds the values for different type of modes
30 * that can exist, USER or CHANNEL type.
41 * Holds mode actions - modes can be allowed or denied.
45 MODEACTION_DENY = 0, /* Drop the mode change, AND a parameter if its a parameterized mode */
46 MODEACTION_ALLOW = 1 /* Allow the mode */
50 * These fixed values can be used to proportionally compare module-defined prefixes to known values.
51 * For example, if your module queries a Channel, and is told that user 'joebloggs' has the prefix
52 * '$', and you dont know what $ means, then you can compare it to these three values to determine
53 * its worth against them. For example if '$' had a value of 15000, you would know it is of higher
54 * status than voice, but lower status than halfop.
55 * No two modes should have equal prefix values.
71 /** Parameter required on mode setting only */
73 /** Parameter always required */
81 /** Each mode is implemented by ONE ModeHandler class.
82 * You must derive ModeHandler and add the child class to
83 * the list of modes handled by the ircd, using
84 * ModeParser::AddMode. When the mode you implement is
85 * set by a user, the virtual function OnModeChange is
86 * called. If you specify a value greater than 0 for
87 * parameters_on or parameters_off, then when the mode is
88 * set or unset respectively, std::string ¶meter will
89 * contain the parameter given by the user, else it will
90 * contain an empty string. You may alter this parameter
91 * string, and if you alter it to an empty string, and your
92 * mode is expected to have a parameter, then this is
93 * equivalent to returning MODEACTION_DENY.
95 class CoreExport ModeHandler : public ServiceProvider
109 /** The opaque id of this mode assigned by the mode parser
114 /** What kind of parameters does the mode take?
116 ParamSpec parameters_taken;
119 * The mode letter you're implementing.
124 * True if the mode requires oper status
130 * Mode is a 'list' mode. The behaviour
131 * of your mode is now set entirely within
132 * the class as of the 1.1 api, rather than
133 * inside the mode parser as in the 1.0 api,
134 * so the only use of this value (along with
135 * IsListMode()) is for the core to determine
136 * wether your module can produce 'lists' or not
137 * (e.g. banlists, etc)
142 * The mode type, either MODETYPE_USER or
147 /** The object type of this mode handler
151 /** The prefix char needed on channel to use this mode,
152 * only checked for channel modes
158 * The constructor for ModeHandler initalizes the mode handler.
159 * The constructor of any class you derive from ModeHandler should
160 * probably call this constructor with the parameters set correctly.
161 * @param me The module which created this mode
162 * @param name A one-word name for the mode
163 * @param modeletter The mode letter you wish to handle
164 * @param params Parameters taken by the mode
165 * @param type Type of the mode (MODETYPE_USER or MODETYPE_CHANNEL)
166 * @param mclass The object type of this mode handler, one of ModeHandler::Class
168 ModeHandler(Module* me, const std::string& name, char modeletter, ParamSpec params, ModeType type, Class mclass = MC_OTHER);
169 virtual CullResult cull();
170 virtual ~ModeHandler();
172 /** Register this object in the ModeParser
174 void RegisterService() CXX11_OVERRIDE;
177 * Returns true if the mode is a list mode
179 bool IsListMode() const { return list; }
182 * Check whether this mode is a prefix mode
183 * @return non-NULL if this mode is a prefix mode, NULL otherwise
185 PrefixMode* IsPrefixMode();
188 * Check whether this mode handler inherits from ListModeBase
189 * @return non-NULL if this mode handler inherits from ListModeBase, NULL otherwise
191 ListModeBase* IsListModeBase();
194 * Check whether this mode handler inherits from ListModeBase
195 * @return non-NULL if this mode handler inherits from ParamModeBase, NULL otherwise
197 ParamModeBase* IsParameterMode();
200 * Returns the mode's type
202 inline ModeType GetModeType() const { return m_type; }
204 * Returns true if the mode can only be set/unset by an oper
206 inline bool NeedsOper() const { return oper; }
208 * Returns the number of parameters for the mode. Any non-zero
209 * value should be considered to be equivalent to one.
210 * @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.
211 * @return The number of parameters the mode expects
213 int GetNumParams(bool adding);
215 * Returns the mode character this handler handles.
216 * @return The mode character
218 inline char GetModeChar() { return mode; }
220 /** Return the id of this mode which is used in User::modes and
221 * Channel::modes as the index to determine whether a mode is set.
223 Id GetId() const { return modeid; }
225 /** For user modes, return the current parameter, if any
227 virtual std::string GetUserParameter(User* useor);
230 * Called when a channel mode change access check for your mode occurs.
231 * @param source Contains the user setting the mode.
232 * @param channel contains the destination channel the modes are being set on.
233 * @param parameter The parameter for your mode. This is modifiable.
234 * @param adding This value is true when the mode is being set, or false when it is being unset.
235 * @return allow, deny, or passthru to check against the required level
237 virtual ModResult AccessCheck(User* source, Channel* channel, std::string ¶meter, bool adding);
240 * Called when a mode change for your mode occurs.
241 * @param source Contains the user setting the mode.
242 * @param dest For usermodes, contains the destination user the mode is being set on. For channelmodes, this is an undefined value.
243 * @param channel For channel modes, contains the destination channel the modes are being set on. For usermodes, this is an undefined value.
244 * @param parameter The parameter for your mode, if you indicated that your mode requires a parameter when being set or unset. Note that
245 * 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
246 * but you specified your mode REQUIRES a parameter, this is equivalent to returning MODEACTION_DENY and will prevent the mode from being
248 * @param adding This value is true when the mode is being set, or false when it is being unset.
249 * @return MODEACTION_ALLOW to allow the mode, or MODEACTION_DENY to prevent the mode, also see the description of 'parameter'.
251 virtual ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding); /* Can change the mode parameter as its a ref */
253 * If your mode is a listmode, then this method will be called for displaying an item list, e.g. on MODE \#channel +modechar
254 * without any parameter or other modes in the command.
255 * @param user The user issuing the command
256 * @param channel The channel they're requesting an item list of (e.g. a banlist, or an exception list etc)
258 virtual void DisplayList(User* user, Channel* channel);
260 /** In the event that the mode should be given a parameter, and no parameter was provided, this method is called.
261 * This allows you to give special information to the user, or handle this any way you like.
262 * @param user The user issuing the mode change
263 * @param dest For user mode changes, the target of the mode. For channel mode changes, NULL.
264 * @param channel For channel mode changes, the target of the mode. For user mode changes, NULL.
266 virtual void OnParameterMissing(User* user, User* dest, Channel* channel);
269 * If your mode is a listmode, this method will be called to display an empty list (just the end of list numeric)
270 * @param user The user issuing the command
271 * @param channel The channel tehy're requesting an item list of (e.g. a banlist, or an exception list etc)
273 virtual void DisplayEmptyList(User* user, Channel* channel);
276 * If your mode needs special action during a server sync to determine which side wins when comparing timestamps,
277 * override this function and use it to return true or false. The default implementation just returns true if
278 * theirs < ours. This will only be called for non-listmodes with parameters, when adding the mode and where
279 * theirs == ours (therefore the default implementation will always return false).
280 * @param their_param Their parameter if the mode has a parameter
281 * @param our_param Our parameter if the mode has a parameter
282 * @param channel The channel we are checking against
283 * @return True if the other side wins the merge, false if we win the merge for this mode.
285 virtual bool ResolveModeConflict(std::string &their_param, const std::string &our_param, Channel* channel);
288 * When a MODETYPE_USER mode handler is being removed, the core will call this method for every user on the server.
289 * The usermode will be removed using the appropiate server mode using InspIRCd::SendMode().
290 * @param user The user which the server wants to remove your mode from
292 void RemoveMode(User* user);
295 * When a MODETYPE_CHANNEL mode handler is being removed, the server will call this method for every channel on the server.
296 * The mode handler has to populate the given modestacker with mode changes that remove the mode from the channel.
297 * The default implementation of this method can remove all kinds of channel modes except listmodes.
298 * In the case of listmodes, the entire list of items must be added to the modestacker (which is handled by ListModeBase,
299 * so if you inherit from it or your mode can be removed by the default implementation then you do not have to implement
301 * @param channel The channel which the server wants to remove your mode from
302 * @param changelist Mode change list to populate with the removal of this mode
304 virtual void RemoveMode(Channel* channel, Modes::ChangeList& changelist);
306 inline unsigned int GetLevelRequired() const { return levelrequired; }
308 friend class ModeParser;
312 * Prefix modes are channel modes that grant a specific rank to members having prefix mode set.
313 * They require a parameter when setting and unsetting; the parameter is always a member of the channel.
314 * A prefix mode may be set on any number of members on a channel, but for a given member a given prefix
315 * mode is either set or not set, in other words members cannot have the same prefix mode set more than once.
317 * A rank of a member is defined as the rank given by the 'strongest' prefix mode that member has.
318 * Other parts of the IRCd use this rank to determine whether a channel action is allowable for a user or not.
319 * The rank of a prefix mode is constant, i.e. the same rank value is given to all users having that prefix mode set.
321 * Note that it is possible that the same action requires a different rank on a different channel;
322 * for example changing the topic on a channel having +t set requires a rank that is >= than the rank of a halfop,
323 * but there is no such restriction when +t isn't set.
325 class CoreExport PrefixMode : public ModeHandler
328 /** The prefix character granted by this mode. '@' for op, '+' for voice, etc.
329 * If 0, this mode does not have a visible prefix character.
333 /** The prefix rank of this mode, used to compare prefix
336 unsigned int prefixrank;
341 * @param Creator The module creating this mode
342 * @param Name The user-friendly one word name of the prefix mode, e.g.: "op", "voice"
343 * @param ModeLetter The mode letter of this mode
344 * @param Rank Rank given by this prefix mode, see explanation above
345 * @param PrefixChar Prefix character, or 0 if the mode has no prefix character
347 PrefixMode(Module* Creator, const std::string& Name, char ModeLetter, unsigned int Rank = 0, char PrefixChar = 0);
350 * Handles setting and unsetting the prefix mode.
351 * Finds the given member of the given channel, if it's not found an error message is sent to 'source'
352 * and MODEACTION_DENY is returned. Otherwise the mode change is attempted.
353 * @param source Source of the mode change, an error message is sent to this user if the target is not found
355 * @param channel The channel the mode change is happening on
356 * @param param The nickname or uuid of the target user
357 * @param adding True when the mode is being set, false when it is being unset
358 * @return MODEACTION_ALLOW if the change happened, MODEACTION_DENY if no change happened
359 * The latter occurs either when the member cannot be found or when the member already has this prefix set
360 * (when setting) or doesn't have this prefix set (when unsetting).
362 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& param, bool adding);
365 * Removes this prefix mode from all users on the given channel
366 * @param chan The channel which the server wants to remove your mode from
367 * @param changelist Mode change list to populate with the removal of this mode
369 void RemoveMode(Channel* channel, Modes::ChangeList& changelist);
372 * Mode prefix or 0. If this is defined, you should
373 * also implement GetPrefixRank() to return an integer
374 * value for this mode prefix.
376 char GetPrefix() const { return prefix; }
379 * Get the 'value' of this modes prefix.
380 * determines which to display when there are multiple.
381 * The mode with the highest value is ranked first. See the
382 * PrefixModeValue enum and Channel::GetPrefixValue() for
385 unsigned int GetPrefixRank() const { return prefixrank; }
388 /** A prebuilt mode handler which handles a simple user 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 user mode is user mode +w.
393 class CoreExport SimpleUserModeHandler : public ModeHandler
396 SimpleUserModeHandler(Module* Creator, const std::string& Name, char modeletter)
397 : ModeHandler(Creator, Name, modeletter, PARAM_NONE, MODETYPE_USER) {}
398 virtual ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding);
401 /** A prebuilt mode handler which handles a simple channel mode, e.g. no parameters, usable by any user, with no extra
402 * behaviour to the mode beyond the basic setting and unsetting of the mode, not allowing the mode to be set if it
403 * is already set and not allowing it to be unset if it is already unset.
404 * An example of a simple channel mode is channel mode +s.
406 class CoreExport SimpleChannelModeHandler : public ModeHandler
409 SimpleChannelModeHandler(Module* Creator, const std::string& Name, char modeletter)
410 : ModeHandler(Creator, Name, modeletter, PARAM_NONE, MODETYPE_CHANNEL) {}
411 virtual ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding);
415 * The ModeWatcher class can be used to alter the behaviour of a mode implemented
416 * by the core or by another module. To use ModeWatcher, derive a class from it,
417 * and attach it to the mode using Server::AddModeWatcher and Server::DelModeWatcher.
418 * A ModeWatcher will be called both before and after the mode change.
420 class CoreExport ModeWatcher : public classbase
424 * The mode name this class is watching
426 const std::string mode;
429 * The mode type being watched (user or channel)
436 * The constructor initializes the mode and the mode type
438 ModeWatcher(Module* creator, const std::string& modename, ModeType type);
440 * The default destructor does nothing.
442 virtual ~ModeWatcher();
445 * Get the mode name being watched
446 * @return The mode name being watched
448 const std::string& GetModeName() const { return mode; }
451 * Get the mode type being watched
452 * @return The mode type being watched (user or channel)
454 ModeType GetModeType();
457 * Before the mode character is processed by its handler, 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 * If you alter the parameter you are given, the mode handler will see your atered version
463 * when it handles the mode.
464 * @param adding True if the mode is being added and false if it is being removed
465 * @return True to allow the mode change to go ahead, false to abort it. If you abort the
466 * change, the mode handler (and ModeWatcher::AfterMode()) will never see the mode change.
468 virtual bool BeforeMode(User* source, User* dest, Channel* channel, std::string& parameter, bool adding);
470 * After the mode character has been processed by the ModeHandler, this method will be called.
471 * @param source The sender of the mode
472 * @param dest The target user for the mode, if you are watching a user mode
473 * @param channel The target channel for the mode, if you are watching a channel mode
474 * @param parameter The parameter of the mode, if the mode is supposed to have a parameter.
475 * You cannot alter the parameter here, as the mode handler has already processed it.
476 * @param adding True if the mode is being added and false if it is being removed
478 virtual void AfterMode(User* source, User* dest, Channel* channel, const std::string& parameter, bool adding);
481 /** The mode parser handles routing of modes and handling of mode strings.
482 * It marshalls, controls and maintains both ModeWatcher and ModeHandler classes,
483 * parses client to server MODE strings for user and channel modes, and performs
484 * processing for the 004 mode list numeric, amongst other things.
486 class CoreExport ModeParser : public fakederef<ModeParser>
489 static const ModeHandler::Id MODEID_MAX = 64;
491 /** Type of the container that maps mode names to ModeHandlers
493 typedef TR1NS::unordered_map<std::string, ModeHandler*, irc::insensitive, irc::StrHashComp> ModeHandlerMap;
496 /** Type of the container that maps mode names to ModeWatchers
498 typedef insp::flat_multimap<std::string, ModeWatcher*> ModeWatcherMap;
500 /** Last item in the ModeType enum
502 static const unsigned int MODETYPE_LAST = 2;
504 /** Mode handlers for each mode, to access a handler subtract
505 * 65 from the ascii value of the mode letter.
506 * The upper bit of the value indicates if its a usermode
507 * or a channel mode, so we have 256 of them not 64.
509 ModeHandler* modehandlers[MODETYPE_LAST][128];
511 /** An array of mode handlers indexed by the mode id
513 ModeHandler* modehandlersbyid[MODETYPE_LAST][MODEID_MAX];
515 /** A map of mode handlers keyed by their name
517 ModeHandlerMap modehandlersbyname[MODETYPE_LAST];
519 /** Lists of mode handlers by type
523 /** List of mode handlers that inherit from ListModeBase
525 std::vector<ListModeBase*> list;
527 /** List of mode handlers that inherit from PrefixMode
529 std::vector<PrefixMode*> prefix;
532 /** Mode watcher classes
534 ModeWatcherMap modewatchermap;
536 /** Last processed mode change
538 Modes::ChangeList LastChangeList;
541 * Attempts to apply a mode change to a user or channel
543 ModeAction TryMode(User* user, User* targu, Channel* targc, Modes::Change& mcitem, bool SkipACL);
545 /** Returns a list of user or channel mode characters.
546 * Used for constructing the parts of the mode list in the 004 numeric.
547 * @param mt Controls whether to list user modes or channel modes
548 * @param needparam Return modes only if they require a parameter to be set
549 * @return The available mode letters that satisfy the given conditions
551 std::string CreateModeList(ModeType mt, bool needparam = false);
553 /** Recreate the cached mode list that is displayed in the 004 numeric
554 * in Cached004ModeList.
555 * Called when a mode handler is added or removed.
557 void RecreateModeListFor004Numeric();
559 /** Allocates an unused id for the given mode type, throws a ModuleException if out of ids.
560 * @param mt The type of the mode to allocate the id for
563 ModeHandler::Id AllocateModeId(ModeType mt);
565 /** The string representing the last set of modes to be parsed.
566 * Use GetLastParse() to get this value, to be used for display purposes.
568 std::string LastParse;
570 /** Cached mode list for use in 004 numeric
572 std::string Cached004ModeList;
575 typedef std::vector<ListModeBase*> ListModeList;
576 typedef std::vector<PrefixMode*> PrefixModeList;
578 typedef unsigned int ModeProcessFlag;
579 enum ModeProcessFlags
581 /** If only this flag is specified, the mode change will be global
582 * and parameter modes will have their parameters explicitly set
583 * (not merged). This is the default.
587 /** If this flag is set then the parameters of non-listmodes will be
588 * merged according to their conflict resolution rules.
589 * Does not affect user modes, channel modes without a parameter and
594 /** If this flag is set then the linking module will ignore the mode change
595 * and not send it to other servers. The mode change will be processed
596 * locally and sent to local user(s) as usual.
600 /** If this flag is set then the mode change will be subject to access checks.
601 * For more information see the documentation of the PrefixMode class,
602 * ModeHandler::levelrequired and ModeHandler::AccessCheck().
603 * Modules may explicitly allow a mode change regardless of this flag by returning
604 * MOD_RES_ALLOW from the OnPreMode hook. Only affects channel mode changes.
612 /** Initialize all built-in modes
614 static void InitBuiltinModes();
616 /** Tidy a banmask. This makes a banmask 'acceptable' if fields are left out.
621 * nick!ident -> nick!ident@*
623 * host.name -> *!*\@host.name
625 * ident@host.name -> *!ident\@host.name
627 * This method can be used on both IPV4 and IPV6 user masks.
629 static void CleanMask(std::string &mask);
630 /** Get the last string to be processed, as it was sent to the user or channel.
631 * Use this to display a string you just sent to be parsed, as the actual output
632 * may be different to what you sent after it has been 'cleaned up' by the parser.
633 * @return Last parsed string, as seen by users.
635 const std::string& GetLastParse() const { return LastParse; }
637 /** Add a mode to the mode parser.
638 * Throws a ModuleException if the mode cannot be added.
640 void AddMode(ModeHandler* mh);
642 /** Delete a mode from the mode parser.
643 * When a mode is deleted, the mode handler will be called
644 * for every user (if it is a user mode) or for every channel
645 * (if it is a channel mode) to unset the mode on all objects.
646 * This prevents modes staying in the system which no longer exist.
647 * @param mh The mode handler to remove
648 * @return True if the mode was successfully removed.
650 bool DelMode(ModeHandler* mh);
652 /** Add a mode watcher.
653 * A mode watcher is triggered before and after a mode handler is
654 * triggered. See the documentation of class ModeWatcher for more
656 * @param mw The ModeWatcher you want to add
658 void AddModeWatcher(ModeWatcher* mw);
660 /** Delete a mode watcher.
661 * A mode watcher is triggered before and after a mode handler is
662 * triggered. See the documentation of class ModeWatcher for more
664 * @param mw The ModeWatcher you want to delete
665 * @return True if the ModeWatcher was deleted correctly
667 bool DelModeWatcher(ModeWatcher* mw);
669 /** Process a list of mode changes entirely. If the mode changes do not fit into one MODE line
670 * then multiple MODE lines are generated.
671 * @param user The source of the mode change, can be a server user.
672 * @param targetchannel Channel to apply the mode change on. NULL if changing modes on a channel.
673 * @param targetuser User to apply the mode change on. NULL if changing modes on a user.
674 * @param changelist Modes to change in form of a Modes::ChangeList.
675 * @param flags Optional flags controlling how the mode change is processed,
676 * defaults to MODE_NONE.
678 void Process(User* user, Channel* targetchannel, User* targetuser, Modes::ChangeList& changelist, ModeProcessFlag flags = MODE_NONE);
680 /** Process a single MODE line's worth of mode changes, taking max modes and line length limits
681 * into consideration. Return value indicates how many modes were processed.
682 * @param user The source of the mode change, can be a server user.
683 * @param targetchannel Channel to apply the mode change on. NULL if changing modes on a channel.
684 * @param targetuser User to apply the mode change on. NULL if changing modes on a user.
685 * @param changelist Modes to change in form of a Modes::ChangeList. May not process
686 * the entire list due to MODE line length and max modes limitations.
687 * @param flags Optional flags controlling how the mode change is processed,
688 * defaults to MODE_NONE.
689 * @param beginindex Index of the first element in changelist to process. Mode changes before
690 * the element with this index are ignored.
691 * @return Number of mode changes processed from changelist.
693 unsigned int ProcessSingle(User* user, Channel* targetchannel, User* targetuser, Modes::ChangeList& changelist, ModeProcessFlag flags = MODE_NONE, unsigned int beginindex = 0);
695 /** Turn a list of parameters compatible with the format of the MODE command into
696 * Modes::ChangeList form. All modes are processed, regardless of max modes. Unknown modes
698 * @param user The source of the mode change, can be a server user. Error numerics are sent to
700 * @param type MODETYPE_USER if this is a user mode change or MODETYPE_CHANNEL if this
701 * is a channel mode change.
702 * @param parameters List of strings describing the mode change to convert to a ChangeList.
703 * Must be using the same format as the parameters of a MODE command.
704 * @param changelist ChangeList object to populate.
705 * @param beginindex Index of the first element that is part of the MODE list in the parameters
706 * container. Defaults to 1.
707 * @param endindex Index of the first element that is not part of the MODE list. By default,
708 * the entire container is considered part of the MODE list.
710 void ModeParamsToChangeList(User* user, ModeType type, const std::vector<std::string>& parameters, Modes::ChangeList& changelist, unsigned int beginindex = 1, unsigned int endindex = UINT_MAX);
712 /** Find the mode handler for a given mode name and type.
713 * @param modename The mode name to search for.
714 * @param mt Type of mode to search for, user or channel.
715 * @return A pointer to a ModeHandler class, or NULL of there isn't a handler for the given mode name.
717 ModeHandler* FindMode(const std::string& modename, ModeType mt);
719 /** Find the mode handler for a given mode and type.
720 * @param modeletter mode letter to search for
721 * @param mt type of mode to search for, user or channel
722 * @returns a pointer to a ModeHandler class, or NULL of there isnt a handler for the given mode
724 ModeHandler* FindMode(unsigned const char modeletter, ModeType mt);
726 /** Find the mode handler for the given prefix mode
727 * @param modeletter The mode letter to search for
728 * @return A pointer to the PrefixMode or NULL if the mode wasn't found or it isn't a prefix mode
730 PrefixMode* FindPrefixMode(unsigned char modeletter);
732 /** Find a mode handler by its prefix.
733 * If there is no mode handler with the given prefix, NULL will be returned.
734 * @param pfxletter The prefix to find, e.g. '@'
735 * @return The mode handler which handles this prefix, or NULL if there is none.
737 PrefixMode* FindPrefix(unsigned const char pfxletter);
739 /** Returns a list of modes, space seperated by type:
742 * 3. Channel modes that require a parameter when set
743 * This is sent to users as the last part of the 004 numeric
745 const std::string& GetModeListFor004Numeric();
747 /** Generates a list of modes, comma seperated by type:
748 * 1; Listmodes EXCEPT those with a prefix
749 * 2; Modes that take a param when adding or removing
750 * 3; Modes that only take a param when adding
751 * 4; Modes that dont take a param
753 std::string GiveModeList(ModeType mt);
755 /** This returns the PREFIX=(ohv)@%+ section of the 005 numeric, or
756 * just the "@%+" part if the parameter false
758 std::string BuildPrefixes(bool lettersAndModes = true);
760 /** Get a list of all mode handlers that inherit from ListModeBase
761 * @return A list containing ListModeBase modes
763 const ListModeList& GetListModes() const { return mhlist.list; }
765 /** Get a list of all prefix modes
766 * @return A list containing all prefix modes
768 const PrefixModeList& GetPrefixModes() const { return mhlist.prefix; }
770 /** Get a mode name -> ModeHandler* map containing all modes of the given type
771 * @param mt Type of modes to return, MODETYPE_USER or MODETYPE_CHANNEL
772 * @return A map of mode handlers of the given type
774 const ModeHandlerMap& GetModes(ModeType mt) const { return modehandlersbyname[mt]; }
776 /** Show the list of a list mode to a user. Modules can deny the listing.
777 * @param user User to show the list to.
778 * @param chan Channel to show the list of.
779 * @param mh List mode to show the list of.
781 void ShowListModeList(User* user, Channel* chan, ModeHandler* mh);
784 inline const std::string& ModeParser::GetModeListFor004Numeric()
786 return Cached004ModeList;
789 inline PrefixMode* ModeHandler::IsPrefixMode()
791 return (this->type_id == MC_PREFIX ? static_cast<PrefixMode*>(this) : NULL);
794 inline ListModeBase* ModeHandler::IsListModeBase()
796 return (this->type_id == MC_LIST ? reinterpret_cast<ListModeBase*>(this) : NULL);
799 inline ParamModeBase* ModeHandler::IsParameterMode()
801 return (this->type_id == MC_PARAM ? reinterpret_cast<ParamModeBase*>(this) : NULL);