InspIRCd  3.0
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
ModeParser Class Reference

#include <mode.h>

Inheritance diagram for ModeParser:
fakederef< ModeParser >

Public Types

enum  ModeProcessFlags { MODE_NONE = 0, MODE_MERGE = 1, MODE_LOCALONLY = 2, MODE_CHECKACCESS = 4 }
 
typedef TR1NS::unordered_map< std::string, ModeHandler *, irc::insensitive, irc::StrHashCompModeHandlerMap
 
typedef std::vector< ListModeBase * > ListModeList
 
typedef std::vector< PrefixMode * > PrefixModeList
 
typedef unsigned int ModeProcessFlag
 

Public Member Functions

const std::string & GetLastParse () const
 
void AddMode (ModeHandler *mh)
 
bool DelMode (ModeHandler *mh)
 
void AddModeWatcher (ModeWatcher *mw)
 
bool DelModeWatcher (ModeWatcher *mw)
 
void Process (User *user, Channel *targetchannel, User *targetuser, Modes::ChangeList &changelist, ModeProcessFlag flags=MODE_NONE)
 
unsigned int ProcessSingle (User *user, Channel *targetchannel, User *targetuser, Modes::ChangeList &changelist, ModeProcessFlag flags=MODE_NONE, unsigned int beginindex=0)
 
void ModeParamsToChangeList (User *user, ModeType type, const std::vector< std::string > &parameters, Modes::ChangeList &changelist, unsigned int beginindex=1, unsigned int endindex=UINT_MAX)
 
ModeHandlerFindMode (const std::string &modename, ModeType mt)
 
ModeHandlerFindMode (unsigned const char modeletter, ModeType mt)
 
PrefixModeFindPrefixMode (unsigned char modeletter)
 
PrefixModeFindPrefix (unsigned const char pfxletter)
 
const TR1NS::array< std::string, 3 > & GetModeListFor004Numeric ()
 
std::string GiveModeList (ModeType mt)
 
std::string BuildPrefixes (bool lettersAndModes=true)
 
const ListModeList & GetListModes () const
 
const PrefixModeList & GetPrefixModes () const
 
const ModeHandlerMapGetModes (ModeType mt) const
 
void ShowListModeList (User *user, Channel *chan, ModeHandler *mh)
 
- Public Member Functions inherited from fakederef< ModeParser >
ModeParseroperator-> ()
 

Static Public Member Functions

static void InitBuiltinModes ()
 
static bool IsModeChar (char chr)
 
static void CleanMask (std::string &mask)
 

Static Public Attributes

static const ModeHandler::Id MODEID_MAX = 64
 

Detailed Description

The mode parser handles routing of modes and handling of mode strings. It marshalls, controls and maintains both ModeWatcher and ModeHandler classes, parses client to server MODE strings for user and channel modes, and performs processing for the 004 mode list numeric, amongst other things.

Member Typedef Documentation

◆ ModeHandlerMap

typedef TR1NS::unordered_map<std::string, ModeHandler*, irc::insensitive, irc::StrHashComp> ModeParser::ModeHandlerMap

Type of the container that maps mode names to ModeHandlers

Member Enumeration Documentation

◆ ModeProcessFlags

Enumerator
MODE_NONE 

If only this flag is specified, the mode change will be global and parameter modes will have their parameters explicitly set (not merged). This is the default.

MODE_MERGE 

If this flag is set then the parameters of non-listmodes will be merged according to their conflict resolution rules. Does not affect user modes, channel modes without a parameter and listmodes.

MODE_LOCALONLY 

If this flag is set then the linking module will ignore the mode change and not send it to other servers. The mode change will be processed locally and sent to local user(s) as usual.

MODE_CHECKACCESS 

If this flag is set then the mode change will be subject to access checks. For more information see the documentation of the PrefixMode class, ModeHandler::levelrequired and ModeHandler::AccessCheck(). Modules may explicitly allow a mode change regardless of this flag by returning MOD_RES_ALLOW from the OnPreMode hook. Only affects channel mode changes.

Member Function Documentation

◆ AddMode()

void ModeParser::AddMode ( ModeHandler mh)

Add a mode to the mode parser. Throws a ModuleException if the mode cannot be added.

◆ AddModeWatcher()

void ModeParser::AddModeWatcher ( ModeWatcher mw)

Add a mode watcher. A mode watcher is triggered before and after a mode handler is triggered. See the documentation of class ModeWatcher for more information.

Parameters
mwThe ModeWatcher you want to add

◆ BuildPrefixes()

std::string ModeParser::BuildPrefixes ( bool  lettersAndModes = true)

This returns the PREFIX=(ohv)%+ section of the 005 numeric, or just the "@%+" part if the parameter false

◆ CleanMask()

void ModeParser::CleanMask ( std::string &  mask)
static

Tidy a banmask. This makes a banmask 'acceptable' if fields are left out. E.g.

nick -> nick!*@*

nick!ident -> [email protected]*

host.name -> !@host.name

ident[email protected]@hos[email protected]t.nam[email protected]e -> *[email protected]

This method can be used on both IPV4 and IPV6 user masks.

◆ DelMode()

bool ModeParser::DelMode ( ModeHandler mh)

Delete a mode from the mode parser. When a mode is deleted, the mode handler will be called for every user (if it is a user mode) or for every channel (if it is a channel mode) to unset the mode on all objects. This prevents modes staying in the system which no longer exist.

Parameters
mhThe mode handler to remove
Returns
True if the mode was successfully removed.

◆ DelModeWatcher()

bool ModeParser::DelModeWatcher ( ModeWatcher mw)

Delete a mode watcher. A mode watcher is triggered before and after a mode handler is triggered. See the documentation of class ModeWatcher for more information.

Parameters
mwThe ModeWatcher you want to delete
Returns
True if the ModeWatcher was deleted correctly

◆ FindMode() [1/2]

ModeHandler * ModeParser::FindMode ( const std::string &  modename,
ModeType  mt 
)

Find the mode handler for a given mode name and type.

Parameters
modenameThe mode name to search for.
mtType of mode to search for, user or channel.
Returns
A pointer to a ModeHandler class, or NULL of there isn't a handler for the given mode name.

◆ FindMode() [2/2]

ModeHandler * ModeParser::FindMode ( unsigned const char  modeletter,
ModeType  mt 
)

Find the mode handler for a given mode and type.

Parameters
modelettermode letter to search for
mttype of mode to search for, user or channel
Returns
a pointer to a ModeHandler class, or NULL of there isnt a handler for the given mode

◆ FindPrefix()

PrefixMode * ModeParser::FindPrefix ( unsigned const char  pfxletter)

Find a mode handler by its prefix. If there is no mode handler with the given prefix, NULL will be returned.

Parameters
pfxletterThe prefix to find, e.g. '@'
Returns
The mode handler which handles this prefix, or NULL if there is none.

◆ FindPrefixMode()

PrefixMode * ModeParser::FindPrefixMode ( unsigned char  modeletter)

Find the mode handler for the given prefix mode

Parameters
modeletterThe mode letter to search for
Returns
A pointer to the PrefixMode or NULL if the mode wasn't found or it isn't a prefix mode

◆ GetLastParse()

const std::string& ModeParser::GetLastParse ( ) const
inline

Get the last string to be processed, as it was sent to the user or channel. Use this to display a string you just sent to be parsed, as the actual output may be different to what you sent after it has been 'cleaned up' by the parser.

Returns
Last parsed string, as seen by users.

◆ GetListModes()

const ListModeList& ModeParser::GetListModes ( ) const
inline

Get a list of all mode handlers that inherit from ListModeBase

Returns
A list containing ListModeBase modes

◆ GetModeListFor004Numeric()

const TR1NS::array< std::string, 3 > & ModeParser::GetModeListFor004Numeric ( )
inline

Returns an array of modes:

  1. User modes
  2. Channel modes
  3. Channel modes that require a parameter when set This is sent to users as the last part of the 004 numeric

◆ GetModes()

const ModeHandlerMap& ModeParser::GetModes ( ModeType  mt) const
inline

Get a mode name -> ModeHandler* map containing all modes of the given type

Parameters
mtType of modes to return, MODETYPE_USER or MODETYPE_CHANNEL
Returns
A map of mode handlers of the given type

◆ GetPrefixModes()

const PrefixModeList& ModeParser::GetPrefixModes ( ) const
inline

Get a list of all prefix modes

Returns
A list containing all prefix modes

◆ GiveModeList()

std::string ModeParser::GiveModeList ( ModeType  mt)

Generates a list of modes, comma seperated by type: 1; Listmodes EXCEPT those with a prefix 2; Modes that take a param when adding or removing 3; Modes that only take a param when adding 4; Modes that dont take a param

◆ InitBuiltinModes()

void ModeParser::InitBuiltinModes ( )
static

Initialize all built-in modes

◆ ModeParamsToChangeList()

void ModeParser::ModeParamsToChangeList ( User user,
ModeType  type,
const std::vector< std::string > &  parameters,
Modes::ChangeList changelist,
unsigned int  beginindex = 1,
unsigned int  endindex = UINT_MAX 
)

Turn a list of parameters compatible with the format of the MODE command into Modes::ChangeList form. All modes are processed, regardless of max modes. Unknown modes are skipped.

Parameters
userThe source of the mode change, can be a server user. Error numerics are sent to this user.
typeMODETYPE_USER if this is a user mode change or MODETYPE_CHANNEL if this is a channel mode change.
parametersList of strings describing the mode change to convert to a ChangeList. Must be using the same format as the parameters of a MODE command.
changelistChangeList object to populate.
beginindexIndex of the first element that is part of the MODE list in the parameters container. Defaults to 1.
endindexIndex of the first element that is not part of the MODE list. By default, the entire container is considered part of the MODE list.

◆ Process()

void ModeParser::Process ( User user,
Channel targetchannel,
User targetuser,
Modes::ChangeList changelist,
ModeProcessFlag  flags = MODE_NONE 
)

Process a list of mode changes entirely. If the mode changes do not fit into one MODE line then multiple MODE lines are generated.

Parameters
userThe source of the mode change, can be a server user.
targetchannelChannel to apply the mode change on. NULL if changing modes on a channel.
targetuserUser to apply the mode change on. NULL if changing modes on a user.
changelistModes to change in form of a Modes::ChangeList.
flagsOptional flags controlling how the mode change is processed, defaults to MODE_NONE.

◆ ProcessSingle()

unsigned int ModeParser::ProcessSingle ( User user,
Channel targetchannel,
User targetuser,
Modes::ChangeList changelist,
ModeProcessFlag  flags = MODE_NONE,
unsigned int  beginindex = 0 
)

Process a single MODE line's worth of mode changes, taking max modes and line length limits into consideration. Return value indicates how many modes were processed.

Parameters
userThe source of the mode change, can be a server user.
targetchannelChannel to apply the mode change on. NULL if changing modes on a channel.
targetuserUser to apply the mode change on. NULL if changing modes on a user.
changelistModes to change in form of a Modes::ChangeList. May not process the entire list due to MODE line length and max modes limitations.
flagsOptional flags controlling how the mode change is processed, defaults to MODE_NONE.
beginindexIndex of the first element in changelist to process. Mode changes before the element with this index are ignored.
Returns
Number of mode changes processed from changelist.

◆ ShowListModeList()

void ModeParser::ShowListModeList ( User user,
Channel chan,
ModeHandler mh 
)

Show the list of a list mode to a user. Modules can deny the listing.

Parameters
userUser to show the list to.
chanChannel to show the list of.
mhList mode to show the list of.

Member Data Documentation

◆ list

std::vector<ListModeBase*> ModeParser::list

List of mode handlers that inherit from ListModeBase

◆ prefix

std::vector<PrefixMode*> ModeParser::prefix

List of mode handlers that inherit from PrefixMode


The documentation for this class was generated from the following files: