InspIRCd  3.0
Public Types | Public Member Functions | Protected Attributes | Friends | List of all members
ModeHandler Class Reference

#include <mode.h>

Inheritance diagram for ModeHandler:
ServiceProvider classbase ListModeBase ModeUserOperator ModeUserServerNoticeMask ParamModeBase PrefixMode SimpleChannelModeHandler SimpleUserModeHandler ModeChannelBan ParamMode< T, ExtItemT > ParamMode< ModeChannelKey, LocalStringExt > ParamMode< ModeChannelLimit, LocalIntExt > ModeChannelOp ModeChannelVoice ModeChannelKey ModeChannelLimit

Public Types

enum  Class { MC_PREFIX, MC_LIST, MC_PARAM, MC_OTHER }
 
typedef size_t Id
 

Public Member Functions

 ModeHandler (Module *me, const std::string &name, char modeletter, ParamSpec params, ModeType type, Class mclass=MC_OTHER)
 
virtual CullResult cull () CXX11_OVERRIDE
 
void RegisterService () CXX11_OVERRIDE
 
bool IsListMode () const
 
PrefixModeIsPrefixMode ()
 
const PrefixModeIsPrefixMode () const
 
ListModeBaseIsListModeBase ()
 
const ListModeBaseIsListModeBase () const
 
ParamModeBaseIsParameterMode ()
 
const ParamModeBaseIsParameterMode () const
 
ModeType GetModeType () const
 
bool NeedsOper () const
 
bool NeedsParam (bool adding) const
 
char GetModeChar () const
 
Id GetId () const
 
virtual std::string GetUserParameter (const User *user) const
 
virtual ModResult AccessCheck (User *source, Channel *channel, std::string &parameter, bool adding)
 
virtual ModeAction OnModeChange (User *source, User *dest, Channel *channel, std::string &parameter, bool adding)
 
virtual void DisplayList (User *user, Channel *channel)
 
virtual void OnParameterMissing (User *user, User *dest, Channel *channel)
 
virtual void DisplayEmptyList (User *user, Channel *channel)
 
virtual bool ResolveModeConflict (std::string &their_param, const std::string &our_param, Channel *channel)
 
void RemoveMode (User *user)
 
virtual void RemoveMode (Channel *channel, Modes::ChangeList &changelist)
 
unsigned int GetLevelRequired () const
 
- Public Member Functions inherited from ServiceProvider
 ServiceProvider (Module *Creator, const std::string &Name, ServiceType Type)
 
void DisableAutoRegister ()
 

Protected Attributes

ParamSpec parameters_taken
 
char mode
 
bool oper
 
bool list
 
ModeType m_type
 
const Class type_id
 
int levelrequired
 

Friends

class ModeParser
 

Additional Inherited Members

- Public Attributes inherited from ServiceProvider
ModuleRef creator
 
const std::string name
 
const ServiceType service
 

Detailed Description

Each mode is implemented by ONE ModeHandler class. You must derive ModeHandler and add the child class to the list of modes handled by the ircd, using ModeParser::AddMode. When the mode you implement is set by a user, the virtual function OnModeChange is called. If you specify a value greater than 0 for parameters_on or parameters_off, then when the mode is set or unset respectively, std::string &parameter will contain the parameter given by the user, else it will contain an empty string. You may alter this parameter string, and if you alter it to an empty string, and your mode is expected to have a parameter, then this is equivalent to returning MODEACTION_DENY.

Constructor & Destructor Documentation

◆ ModeHandler()

ModeHandler::ModeHandler ( Module me,
const std::string &  name,
char  modeletter,
ParamSpec  params,
ModeType  type,
Class  mclass = MC_OTHER 
)

The constructor for ModeHandler initalizes the mode handler. The constructor of any class you derive from ModeHandler should probably call this constructor with the parameters set correctly.

Parameters
meThe module which created this mode
nameA one-word name for the mode
modeletterThe mode letter you wish to handle
paramsParameters taken by the mode
typeType of the mode (MODETYPE_USER or MODETYPE_CHANNEL)
mclassThe object type of this mode handler, one of ModeHandler::Class

Member Function Documentation

◆ AccessCheck()

ModResult ModeHandler::AccessCheck ( User source,
Channel channel,
std::string &  parameter,
bool  adding 
)
virtual

Called when a channel mode change access check for your mode occurs.

Parameters
sourceContains the user setting the mode.
channelcontains the destination channel the modes are being set on.
parameterThe parameter for your mode. This is modifiable.
addingThis value is true when the mode is being set, or false when it is being unset.
Returns
allow, deny, or passthru to check against the required level

◆ cull()

CullResult ModeHandler::cull ( )
virtual

Called just prior to destruction via cull list.

Reimplemented from classbase.

◆ DisplayEmptyList()

void ModeHandler::DisplayEmptyList ( User user,
Channel channel 
)
virtual

If your mode is a listmode, this method will be called to display an empty list (just the end of list numeric)

Parameters
userThe user issuing the command
channelThe channel tehy're requesting an item list of (e.g. a banlist, or an exception list etc)

Reimplemented in ListModeBase.

◆ DisplayList()

void ModeHandler::DisplayList ( User user,
Channel channel 
)
virtual

If your mode is a listmode, then this method will be called for displaying an item list, e.g. on MODE #channel +modechar without any parameter or other modes in the command.

Parameters
userThe user issuing the command
channelThe channel they're requesting an item list of (e.g. a banlist, or an exception list etc)

Reimplemented in ListModeBase.

◆ GetId()

Id ModeHandler::GetId ( ) const
inline

Return the id of this mode which is used in User::modes and Channel::modes as the index to determine whether a mode is set.

◆ GetModeChar()

char ModeHandler::GetModeChar ( ) const
inline

Returns the mode character this handler handles.

Returns
The mode character

◆ GetModeType()

ModeType ModeHandler::GetModeType ( ) const
inline

Returns the mode's type

◆ GetUserParameter()

std::string ModeHandler::GetUserParameter ( const User user) const
virtual

For user modes, return the current parameter, if any

Reimplemented in ModeUserServerNoticeMask.

◆ IsListMode()

bool ModeHandler::IsListMode ( ) const
inline

Returns true if the mode is a list mode

◆ IsListModeBase() [1/2]

ListModeBase * ModeHandler::IsListModeBase ( )
inline

Check whether this mode handler inherits from ListModeBase

Returns
non-NULL if this mode handler inherits from ListModeBase, NULL otherwise

◆ IsListModeBase() [2/2]

const ListModeBase * ModeHandler::IsListModeBase ( ) const
inline

Check whether this mode handler inherits from ListModeBase

Returns
non-NULL if this mode handler inherits from ListModeBase, NULL otherwise

◆ IsParameterMode() [1/2]

ParamModeBase * ModeHandler::IsParameterMode ( )
inline

Check whether this mode handler inherits from ParamModeBase

Returns
non-NULL if this mode handler inherits from ParamModeBase, NULL otherwise

◆ IsParameterMode() [2/2]

const ParamModeBase * ModeHandler::IsParameterMode ( ) const
inline

Check whether this mode handler inherits from ParamModeBase

Returns
non-NULL if this mode handler inherits from ParamModeBase, NULL otherwise

◆ IsPrefixMode() [1/2]

PrefixMode * ModeHandler::IsPrefixMode ( )
inline

Check whether this mode is a prefix mode

Returns
non-NULL if this mode is a prefix mode, NULL otherwise

◆ IsPrefixMode() [2/2]

const PrefixMode * ModeHandler::IsPrefixMode ( ) const
inline

Check whether this mode is a prefix mode

Returns
non-NULL if this mode is a prefix mode, NULL otherwise

◆ NeedsOper()

bool ModeHandler::NeedsOper ( ) const
inline

Returns true if the mode can only be set/unset by an oper

◆ NeedsParam()

bool ModeHandler::NeedsParam ( bool  adding) const

Check if the mode needs a parameter for adding or removing

Parameters
addingTrue to check if the mode needs a parameter when setting, false to check if the mode needs a parameter when unsetting
Returns
True if the mode needs a parameter for the specified action, false if it doesn't

◆ OnModeChange()

ModeAction ModeHandler::OnModeChange ( User source,
User dest,
Channel channel,
std::string &  parameter,
bool  adding 
)
virtual

Called when a mode change for your mode occurs.

Parameters
sourceContains the user setting the mode.
destFor usermodes, contains the destination user the mode is being set on. For channelmodes, this is an undefined value.
channelFor channel modes, contains the destination channel the modes are being set on. For usermodes, this is an undefined value.
parameterThe parameter for your mode, if you indicated that your mode requires a parameter when being set or unset. Note that 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 but you specified your mode REQUIRES a parameter, this is equivalent to returning MODEACTION_DENY and will prevent the mode from being displayed.
addingThis value is true when the mode is being set, or false when it is being unset.
Returns
MODEACTION_ALLOW to allow the mode, or MODEACTION_DENY to prevent the mode, also see the description of 'parameter'.

Reimplemented in SimpleChannelModeHandler, SimpleUserModeHandler, PrefixMode, ListModeBase, ModeUserOperator, ModeUserServerNoticeMask, ModeChannelKey, and ParamModeBase.

◆ OnParameterMissing()

void ModeHandler::OnParameterMissing ( User user,
User dest,
Channel channel 
)
virtual

In the event that the mode should be given a parameter, and no parameter was provided, this method is called. This allows you to give special information to the user, or handle this any way you like.

Parameters
userThe user issuing the mode change
destFor user mode changes, the target of the mode. For channel mode changes, NULL.
channelFor channel mode changes, the target of the mode. For user mode changes, NULL.

Reimplemented in ModeUserServerNoticeMask.

◆ RegisterService()

void ModeHandler::RegisterService ( )
virtual

Register this object in the ModeParser

Reimplemented from ServiceProvider.

◆ RemoveMode() [1/2]

void ModeHandler::RemoveMode ( User user)

When a MODETYPE_USER mode handler is being removed, the core will call this method for every user on the server. The usermode will be removed using the appropiate server mode using InspIRCd::SendMode().

Parameters
userThe user which the server wants to remove your mode from

◆ RemoveMode() [2/2]

void ModeHandler::RemoveMode ( Channel channel,
Modes::ChangeList changelist 
)
virtual

When a MODETYPE_CHANNEL mode handler is being removed, the server will call this method for every channel on the server. The mode handler has to populate the given modestacker with mode changes that remove the mode from the channel. The default implementation of this method can remove all kinds of channel modes except listmodes. In the case of listmodes, the entire list of items must be added to the modestacker (which is handled by ListModeBase, so if you inherit from it or your mode can be removed by the default implementation then you do not have to implement this function).

Parameters
channelThe channel which the server wants to remove your mode from
changelistMode change list to populate with the removal of this mode

Reimplemented in PrefixMode, and ListModeBase.

◆ ResolveModeConflict()

bool ModeHandler::ResolveModeConflict ( std::string &  their_param,
const std::string &  our_param,
Channel channel 
)
virtual

If your mode needs special action during a server sync to determine which side wins when comparing timestamps, override this function and use it to return true or false. The default implementation just returns true if theirs < ours. This will only be called for non-listmodes with parameters, when adding the mode and where theirs == ours (therefore the default implementation will always return false).

Parameters
their_paramTheir parameter if the mode has a parameter
our_paramOur parameter if the mode has a parameter
channelThe channel we are checking against
Returns
True if the other side wins the merge, false if we win the merge for this mode.

Reimplemented in ModeChannelLimit.

Member Data Documentation

◆ levelrequired

int ModeHandler::levelrequired
protected

The prefix char needed on channel to use this mode, only checked for channel modes

◆ list

bool ModeHandler::list
protected

Mode is a 'list' mode. The behaviour of your mode is now set entirely within the class as of the 1.1 api, rather than inside the mode parser as in the 1.0 api, so the only use of this value (along with IsListMode()) is for the core to determine wether your module can produce 'lists' or not (e.g. banlists, etc)

◆ m_type

ModeType ModeHandler::m_type
protected

The mode type, either MODETYPE_USER or MODETYPE_CHANNEL.

◆ mode

char ModeHandler::mode
protected

The mode letter you're implementing.

◆ oper

bool ModeHandler::oper
protected

True if the mode requires oper status to set.

◆ parameters_taken

ParamSpec ModeHandler::parameters_taken
protected

What kind of parameters does the mode take?

◆ type_id

const Class ModeHandler::type_id
protected

The object type of this mode handler


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