InspIRCd  2.0
 All Classes Namespaces Functions Variables Typedefs Enumerations
Public Member Functions | Protected Attributes | List of all members
ModeHandler Class Reference

#include <mode.h>

Inheritance diagram for ModeHandler:
ServiceProvider classbase ParamChannelModeHandler SimpleChannelModeHandler SimpleUserModeHandler

Public Member Functions

 ModeHandler (Module *me, const std::string &name, char modeletter, ParamSpec params, ModeType type)
 
virtual CullResult cull ()
 
bool IsListMode ()
 
char GetPrefix () const
 
virtual unsigned int GetPrefixRank ()
 
ModeType GetModeType () const
 
TranslateType GetTranslateType () const
 
bool NeedsOper () const
 
int GetNumParams (bool adding)
 
char GetModeChar ()
 
virtual std::string GetUserParameter (User *useor)
 
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)
 
virtual void RemoveMode (User *user, irc::modestacker *stack=NULL)
 
virtual void RemoveMode (Channel *channel, irc::modestacker *stack=NULL)
 
unsigned int GetLevelRequired () const
 
- Public Member Functions inherited from ServiceProvider
 ServiceProvider (Module *Creator, const std::string &Name, ServiceType Type)
 

Protected Attributes

TranslateType m_paramtype
 
ParamSpec parameters_taken
 
char mode
 
char prefix
 
bool oper
 
bool list
 
ModeType m_type
 
int levelrequired
 

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 ( Module me,
const std::string &  name,
char  modeletter,
ParamSpec  params,
ModeType  type 
)

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)

Member Function Documentation

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
CullResult ModeHandler::cull ( )
virtual

Called just prior to destruction via cull list.

Reimplemented from classbase.

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)
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)
char ModeHandler::GetModeChar ( )
inline

Returns the mode character this handler handles.

Returns
The mode character
ModeType ModeHandler::GetModeType ( ) const
inline

Returns the mode's type

int ModeHandler::GetNumParams ( bool  adding)

Returns the number of parameters for the mode. Any non-zero value should be considered to be equivalent to one.

Parameters
addingIf 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.
Returns
The number of parameters the mode expects
char ModeHandler::GetPrefix ( ) const
inline

Mode prefix or 0. If this is defined, you should also implement GetPrefixRank() to return an integer value for this mode prefix.

unsigned int ModeHandler::GetPrefixRank ( )
virtual

Get the 'value' of this modes prefix. determines which to display when there are multiple. The mode with the highest value is ranked first. See the PrefixModeValue enum and Channel::GetPrefixValue() for more information.

TranslateType ModeHandler::GetTranslateType ( ) const
inline

Returns the mode's parameter translation type

std::string ModeHandler::GetUserParameter ( User useor)
virtual

For user modes, return the current parameter, if any

bool ModeHandler::IsListMode ( )

Returns true if the mode is a list mode

bool ModeHandler::NeedsOper ( ) const
inline

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

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 ParamChannelModeHandler, SimpleChannelModeHandler, and SimpleUserModeHandler.

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.
void ModeHandler::RemoveMode ( User user,
irc::modestacker stack = NULL 
)
virtual

When a MODETYPE_USER mode handler is being removed, the server will call this method for every user on the server. Your mode handler should remove its user mode from the user by sending the appropriate server modes using InspIRCd::SendMode(). The default implementation of this method can remove simple modes which have no parameters, and can be used when your mode is of this type, otherwise you must implement a more advanced version of it to remove your mode properly from each user.

Parameters
userThe user which the server wants to remove your mode from
stackThe mode stack to add the mode change to

This default implementation can remove simple user modes

void ModeHandler::RemoveMode ( Channel channel,
irc::modestacker stack = NULL 
)
virtual

When a MODETYPE_CHANNEL mode handler is being removed, the server will call this method for every channel on the server. Your mode handler should remove its user mode from the channel by sending the appropriate server modes using InspIRCd::SendMode(). The default implementation of this method can remove simple modes which have no parameters, and can be used when your mode is of this type, otherwise you must implement a more advanced version of it to remove your mode properly from each channel. Note that in the case of listmodes, you should remove the entire list of items.

Parameters
channelThe channel which the server wants to remove your mode from
stackThe mode stack to add the mode change to

This default implementation can remove simple channel modes (no parameters)

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.

Member Data Documentation

int ModeHandler::levelrequired
protected

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

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)

TranslateType ModeHandler::m_paramtype
protected

The mode parameter translation type

ModeType ModeHandler::m_type
protected

The mode type, either MODETYPE_USER or MODETYPE_CHANNEL.

char ModeHandler::mode
protected

The mode letter you're implementing.

bool ModeHandler::oper
protected

True if the mode requires oper status to set.

ParamSpec ModeHandler::parameters_taken
protected

What kind of parameters does the mode take?

char ModeHandler::prefix
protected

Mode prefix, or 0


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