The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

ModeHandler Class Reference

Each mode is implemented by ONE ModeHandler class. More...

#include <mode.h>

Inheritance diagram for ModeHandler:

Inheritance graph
[legend]
Collaboration diagram for ModeHandler:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ModeHandler (InspIRCd *Instance, char modeletter, int parameters_on, int parameters_off, bool listmode, ModeType type, bool operonly, char mprefix=0, char prefixrequired= '%')
 The constructor for ModeHandler initalizes the mode handler.
virtual ~ModeHandler ()
 The default destructor does nothing.
bool IsListMode ()
 Returns true if the mode is a list mode.
char GetPrefix ()
 Mode prefix or 0.
virtual unsigned int GetCount ()
 Get number of items with this mode set on them.
virtual void ChangeCount (int modifier)
 Adjust usage count returned by GetCount.
virtual unsigned int GetPrefixRank ()
 Get the 'value' of this modes prefix.
ModeType GetModeType ()
 Returns the modes type.
bool NeedsOper ()
 Returns true if the mode can only be set/unset by an oper.
int GetNumParams (bool adding)
 Returns the number of parameters for the mode.
char GetModeChar ()
 Returns the mode character this handler handles.
virtual std::string GetUserParameter (User *useor)
 For user modes, return the current parameter, if any.
virtual ModeAction OnModeChange (User *source, User *dest, Channel *channel, std::string &parameter, bool adding, bool servermode=false)
 Called when a mode change for your mode occurs.
virtual void DisplayList (User *user, Channel *channel)
 If your mode is a listmode, then this method will be called for displaying an item list, e.g.
virtual void OnParameterMissing (User *user, User *dest, Channel *channel)
 In the event that the mode should be given a parameter, and no parameter was provided, this method is called.
virtual void DisplayEmptyList (User *user, Channel *channel)
 If your mode is a listmode, this method will be called to display an empty list (just the end of list numeric).
virtual bool CheckTimeStamp (time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, Channel *channel)
 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.
virtual ModePair ModeSet (User *source, User *dest, Channel *channel, const std::string &parameter)
 When a remote server needs to bounce a set of modes, it will call this method for every mode in the mode string to determine if the mode is set or not.
virtual void RemoveMode (User *user, irc::modestacker *stack=NULL)
 When a MODETYPE_USER mode handler is being removed, the server will call this method for every user on the server.
virtual void RemoveMode (Channel *channel, irc::modestacker *stack=NULL)
 When a MODETYPE_CHANNEL mode handler is being removed, the server will call this method for every channel on the server.
char GetNeededPrefix ()
void SetNeededPrefix (char needsprefix)

Protected Attributes

InspIRCdServerInstance
 Creator/owner pointer.
char mode
 The mode letter you're implementing.
int n_params_on
 Number of parameters when being set.
int n_params_off
 Number of parameters when being unset.
bool list
 Mode is a 'list' mode.
ModeType m_type
 The mode type, either MODETYPE_USER or MODETYPE_CHANNEL.
bool oper
 True if the mode requires oper status to set.
char prefix
 Mode prefix, or 0.
unsigned int count
 Number of items with this mode set on them.
char prefixneeded
 The prefix char needed on channel to use this mode, only checked for channel modes.

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.

Definition at line 93 of file mode.h.


Constructor & Destructor Documentation

ModeHandler::ModeHandler InspIRCd Instance,
char  modeletter,
int  parameters_on,
int  parameters_off,
bool  listmode,
ModeType  type,
bool  operonly,
char  mprefix = 0,
char  prefixrequired = '%'
 

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:
modeletter The mode letter you wish to handle
parameters_on The number of parameters your mode takes when being set. Note that any nonzero value is treated as 1.
parameters_off The number of parameters your mode takes when being unset. Note that any nonzero value is treated as 1.
listmode Set to true if your mode is a listmode, e.g. it will respond to MODE channel +modechar with a list of items
ModeType Set this to MODETYPE_USER for a usermode, or MODETYPE_CHANNEL for a channelmode.
operonly Set this to true if only opers should be allowed to set or unset the mode.
mprefix For listmodes where parameters are NICKNAMES which are on the channel (for example, +ohv), you may define a prefix. When you define a prefix, it can be returned in NAMES, WHO etc if it has the highest value (as returned by GetPrefixRank()) In the core, the only modes to implement prefixes are +ovh (ops, voice, halfop) which define the prefix characters @, % and + and the rank values OP_VALUE, HALFOP_VALUE and VOICE_VALUE respectively. Any prefixes you define should have unique values proportional to these three defaults or proportional to another mode in a module you depend on. See src/cmode_o.cpp as an example.

Definition at line 55 of file mode.cpp.

ModeHandler::~ModeHandler  )  [virtual]
 

The default destructor does nothing.

Definition at line 60 of file mode.cpp.


Member Function Documentation

void ModeHandler::ChangeCount int  modifier  )  [virtual]
 

Adjust usage count returned by GetCount.

Definition at line 89 of file mode.cpp.

References count, DEBUG, LogManager::Log(), InspIRCd::Logs, mode, and ServerInstance.

Referenced by User::DecrementModes(), TreeSocket::ParseUID(), and ModeParser::Process().

bool ModeHandler::CheckTimeStamp time_t  theirs,
time_t  ours,
const 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:
theirs The timestamp of the remote side
ours The timestamp of the local side
their_param Their parameter if the mode has a parameter
our_param Our parameter if the mode has a parameter
channel The 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 JoinFlood, KickRejoin, MsgFlood, NickFlood, Redirect, ModeChannelKey, and ModeChannelLimit.

Definition at line 154 of file mode.cpp.

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:
user The user issuing the command
channel The channel tehy're requesting an item list of (e.g. a banlist, or an exception list etc)

Reimplemented in ModeChannelBan, and ListModeBase.

Definition at line 146 of file mode.cpp.

Referenced by ModeParser::Process().

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:
user The user issuing the command
channel The channel they're requesting an item list of (e.g. a banlist, or an exception list etc)

Reimplemented in ChanFounder, ChanProtect, ModeChannelBan, and ListModeBase.

Definition at line 142 of file mode.cpp.

Referenced by ModeParser::Process().

unsigned int ModeHandler::GetCount  )  [virtual]
 

Get number of items with this mode set on them.

Reimplemented in ModeUserInvisible, ModeUserOperator, and ModeUserWallops.

Definition at line 84 of file mode.cpp.

Referenced by UserManager::ModeCount().

char ModeHandler::GetModeChar  ) 
 

Returns the mode character this handler handles.

Returns:
The mode character

Definition at line 115 of file mode.cpp.

References mode.

Referenced by ModeParser::AddMode(), ModeParser::ChanModes(), ModeParser::DelMode(), ModeParser::ModeString(), and ModeParser::Process().

ModeType ModeHandler::GetModeType  ) 
 

Returns the modes type.

Definition at line 95 of file mode.cpp.

References m_type.

Referenced by ModeParser::AddMode(), and ModeParser::DelMode().

char ModeHandler::GetNeededPrefix  ) 
 

Definition at line 69 of file mode.cpp.

References prefixneeded.

Referenced by ModeParser::Process().

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:
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.
Returns:
The number of parameters the mode expects

Definition at line 110 of file mode.cpp.

References n_params_off, and n_params_on.

Referenced by User::FormatModes(), ModeParser::ModeString(), ModulePermanentChannels::OnRehash(), TreeSocket::ParseUID(), and Channel::SetDefaultModes().

char ModeHandler::GetPrefix  ) 
 

Mode prefix or 0.

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

Definition at line 105 of file mode.cpp.

References prefix.

Referenced by ModeParser::AddMode(), ModeParser::BuildPrefixes(), and Channel::ForceChan().

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.

Reimplemented in ChanFounder, ChanProtect, ModeChannelHalfOp, ModeChannelOp, and ModeChannelVoice.

Definition at line 79 of file mode.cpp.

Referenced by Channel::ForceChan(), and ModeParser::Process().

std::string ModeHandler::GetUserParameter User useor  )  [virtual]
 

For user modes, return the current parameter, if any.

Reimplemented in ModeUserServerNoticeMask.

Definition at line 120 of file mode.cpp.

Referenced by User::FormatModes().

bool ModeHandler::IsListMode  ) 
 

Returns true if the mode is a list mode.

Definition at line 64 of file mode.cpp.

References list.

Referenced by ModeParser::Process().

ModePair ModeHandler::ModeSet User source,
User dest,
Channel channel,
const std::string parameter
[virtual]
 

When a remote server needs to bounce a set of modes, it will call this method for every mode in the mode string to determine if the mode is set or not.

Parameters:
source of the mode change, this will be NULL for a server mode
dest Target user of the mode change, if this is a user mode
channel Target channel of the mode change, if this is a channel mode
parameter The parameter given for the mode change, or an empty string
Returns:
The first value of the pair should be true if the mode is set with the given parameter. In the case of permissions modes such as channelmode +o, this should return true if the user given as the parameter has the given privilage on the given channel. The string value of the pair will hold the current setting for this mode set locally, when the bool is true, or, the parameter given. This allows the local server to enforce our locally set parameters back to a remote server.

Reimplemented in ChanFounder, ChanProtect, JoinFlood, KickRejoin, MsgFlood, NickFlood, Redirect, ModeChannelBan, ModeChannelHalfOp, ModeChannelKey, ModeChannelLimit, ModeChannelOp, ModeChannelVoice, and ListModeBase.

Definition at line 130 of file mode.cpp.

References Channel::IsModeSet(), and User::IsModeSet().

Referenced by ModeParser::ModeString().

bool ModeHandler::NeedsOper  ) 
 

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

Reimplemented in ServProtectMode.

Definition at line 100 of file mode.cpp.

References oper.

Referenced by User::UnOper().

ModeAction ModeHandler::OnModeChange User source,
User dest,
Channel channel,
std::string parameter,
bool  adding,
bool  servermode = false
[virtual]
 

Called when a mode change for your mode occurs.

Parameters:
source Contains the user setting the mode.
dest For usermodes, contains the destination user the mode is being set on. For channelmodes, this is an undefined value.
channel For channel modes, contains the destination channel the modes are being set on. For usermodes, this is an undefined value.
parameter The 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.
adding This 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 AuditoriumMode, ChanFounder, ChanProtect, CloakUser, PrivacyMode, User_d, DelayJoinMode, HideChans, HideOper, InvisibleMode, JoinFlood, KickRejoin, MsgFlood, NickFlood, NoCTCP, NoNicks, OperChans, PermChannel, Redirect, Channel_r, User_r, ServProtectMode, SeeWhois, SSLMode, ModeChannelBan, ModeChannelHalfOp, ModeChannelKey, ModeChannelLimit, ModeChannelOp, ModeChannelTopicOps, ModeChannelVoice, ModeUserOperator, ModeUserServerNoticeMask, SimpleUserModeHandler, SimpleChannelModeHandler, and ListModeBase.

Definition at line 125 of file mode.cpp.

References MODEACTION_DENY.

Referenced by Channel::ForceChan(), ModulePermanentChannels::OnRehash(), TreeSocket::ParseUID(), ModeParser::Process(), and Channel::SetDefaultModes().

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:
user The user issuing the mode change
dest For user mode changes, the target of the mode. For channel mode changes, NULL.
channel For channel mode changes, the target of the mode. For user mode changes, NULL.

Reimplemented in ModeUserServerNoticeMask.

Definition at line 150 of file mode.cpp.

Referenced by ModeParser::Process().

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:
channel The channel which the server wants to remove your mode from

Reimplemented in ChanFounder, ChanProtect, ModeChannelBan, ModeChannelHalfOp, ModeChannelKey, ModeChannelOp, ModeChannelVoice, and ListModeBase.

Definition at line 1176 of file mode.cpp.

References InspIRCd::FakeClient, Channel::IsModeSet(), MAXBUF, Channel::name, irc::modestacker::Push(), InspIRCd::SendMode(), and ServerInstance.

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:
user The user which the server wants to remove your mode from

Reimplemented in ChanFounder, ChanProtect, ModeChannelBan, ModeChannelHalfOp, ModeChannelKey, ModeChannelOp, ModeChannelVoice, and ListModeBase.

Definition at line 1152 of file mode.cpp.

References CommandParser::CallHandler(), User::IsModeSet(), MAXBUF, User::nick, InspIRCd::Parser, irc::modestacker::Push(), and ServerInstance.

Referenced by ModeParser::DelMode(), and TreeSocket::RemoveStatus().

void ModeHandler::SetNeededPrefix char  needsprefix  ) 
 

Definition at line 74 of file mode.cpp.

References prefixneeded.


Member Data Documentation

unsigned int ModeHandler::count [protected]
 

Number of items with this mode set on them.

Definition at line 140 of file mode.h.

Referenced by ChangeCount(), ModeUserWallops::GetCount(), ModeUserOperator::GetCount(), and ModeUserInvisible::GetCount().

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)

Definition at line 122 of file mode.h.

Referenced by IsListMode().

ModeType ModeHandler::m_type [protected]
 

The mode type, either MODETYPE_USER or MODETYPE_CHANNEL.

Definition at line 127 of file mode.h.

Referenced by GetModeType().

char ModeHandler::mode [protected]
 

The mode letter you're implementing.

Definition at line 103 of file mode.h.

Referenced by ChangeCount(), ListModeBase::DoSyncChannel(), GetModeChar(), and ListModeBase::ListModeBase().

int ModeHandler::n_params_off [protected]
 

Number of parameters when being unset.

Definition at line 111 of file mode.h.

Referenced by GetNumParams().

int ModeHandler::n_params_on [protected]
 

Number of parameters when being set.

Definition at line 107 of file mode.h.

Referenced by GetNumParams().

bool ModeHandler::oper [protected]
 

True if the mode requires oper status to set.

Definition at line 132 of file mode.h.

Referenced by NeedsOper().

char ModeHandler::prefix [protected]
 

Mode prefix, or 0.

Reimplemented in CloakUser.

Definition at line 136 of file mode.h.

Referenced by GetPrefix().

char ModeHandler::prefixneeded [protected]
 

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

Definition at line 145 of file mode.h.

Referenced by GetNeededPrefix(), and SetNeededPrefix().

InspIRCd* ModeHandler::ServerInstance [protected]
 

Creator/owner pointer.

Definition at line 99 of file mode.h.

Referenced by ModeChannelBan::AddBan(), ModeChannelHalfOp::AddHalfOp(), ModeChannelOp::AddOp(), ModeChannelVoice::AddVoice(), ChangeCount(), ModeChannelBan::DelBan(), ModeChannelHalfOp::DelHalfOp(), ModeChannelOp::DelOp(), ModeChannelVoice::DelVoice(), ListModeBase::DisplayList(), ListModeBase::DoImplements(), ListModeBase::DoRehash(), CloakUser::DoRehash(), ListModeBase::DoSyncChannel(), ModeChannelVoice::ModeSet(), ModeChannelOp::ModeSet(), ModeChannelHalfOp::ModeSet(), ModeUserOperator::OnModeChange(), ListModeBase::OnModeChange(), SSLMode::OnModeChange(), User_r::OnModeChange(), Channel_r::OnModeChange(), Redirect::OnModeChange(), InvisibleMode::OnModeChange(), ChanProtect::OnModeChange(), ChanFounder::OnModeChange(), ModeChannelHalfOp::OnModeChange(), ListModeBase::RemoveMode(), RemoveMode(), ModeChannelVoice::RemoveMode(), ModeChannelOp::RemoveMode(), ModeChannelKey::RemoveMode(), ModeChannelHalfOp::RemoveMode(), ModeChannelBan::RemoveMode(), and InvisibleMode::~InvisibleMode().


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