void SetNeededPrefix(char needsprefix);
};
+/** A prebuilt mode handler which handles a simple user mode, e.g. no parameters, usable by any user, with no extra
+ * behaviour to the mode beyond the basic setting and unsetting of the mode, not allowing the mode to be set if it
+ * is already set and not allowing it to be unset if it is already unset.
+ * An example of a simple user mode is user mode +w.
+ */
+class CoreExport SimpleUserModeHandler : public ModeHandler
+{
+ public:
+ SimpleUserModeHandler(InspIRCd* Instance, char modeletter);
+ virtual ~SimpleUserModeHandler();
+ virtual ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool servermode = false);
+};
+
+/** A prebuilt mode handler which handles a simple channel mode, e.g. no parameters, usable by any user, with no extra
+ * behaviour to the mode beyond the basic setting and unsetting of the mode, not allowing the mode to be set if it
+ * is already set and not allowing it to be unset if it is already unset.
+ * An example of a simple channel mode is channel mode +s.
+ */
+class CoreExport SimpleChannelModeHandler : public ModeHandler
+{
+ public:
+ SimpleChannelModeHandler(InspIRCd* Instance, char modeletter);
+ virtual ~SimpleChannelModeHandler();
+ virtual ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool servermode = false);
+};
+
/**
* The ModeWatcher class can be used to alter the behaviour of a mode implemented
* by the core or by another module. To use ModeWatcher, derive a class from it,
return (ours < theirs);
}
+SimpleUserModeHandler::SimpleUserModeHandler(InspIRCd* Instance, char modeletter) : ModeHandler(Instance, modeletter, 0, 0, false, MODETYPE_USER, false)
+{
+}
+
+SimpleUserModeHandler::~SimpleUserModeHandler()
+{
+}
+
+SimpleChannelModeHandler::~SimpleChannelModeHandler()
+{
+}
+
+SimpleChannelModeHandler::SimpleChannelModeHandler(InspIRCd* Instance, char modeletter) : ModeHandler(Instance, modeletter, 0, 0, false, MODETYPE_CHANNEL, false)
+{
+}
+
+ModeAction SimpleUserModeHandler::OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool servermode)
+{
+ /* Only opers can change other users modes */
+ if (source != dest)
+ return MODEACTION_DENY;
+
+ if (adding)
+ {
+ if (!dest->IsModeSet(this->GetModeChar()))
+ {
+ dest->SetMode(this->GetModeChar(),true);
+ return MODEACTION_ALLOW;
+ }
+ }
+ else
+ {
+ if (dest->IsModeSet(this->GetModeChar()))
+ {
+ dest->SetMode(this->GetModeChar(),false);
+ return MODEACTION_ALLOW;
+ }
+ }
+
+ return MODEACTION_DENY;
+}
+
+
+ModeAction SimpleChannelModeHandler::OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool servermode)
+{
+ if (adding)
+ {
+ if (!channel->IsModeSet(this->GetModeChar()))
+ {
+ channel->SetMode(this->GetModeChar(),true);
+ return MODEACTION_ALLOW;
+ }
+ }
+ else
+ {
+ if (channel->IsModeSet(this->GetModeChar()))
+ {
+ channel->SetMode(this->GetModeChar(),false);
+ return MODEACTION_ALLOW;
+ }
+ }
+
+ return MODEACTION_DENY;
+}
+
ModeWatcher::ModeWatcher(InspIRCd* Instance, char modeletter, ModeType type) : ServerInstance(Instance), mode(modeletter), m_type(type)
{
}
/** Handles the +P channel mode
*/
-class BlockCaps : public ModeHandler
+class BlockCaps : public SimpleChannelModeHandler
{
public:
- BlockCaps(InspIRCd* Instance) : ModeHandler(Instance, 'B', 0, 0, false, MODETYPE_CHANNEL, false) { }
-
- ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
- {
- if (adding)
- {
- if (!channel->IsModeSet('B'))
- {
- channel->SetMode('B',true);
- return MODEACTION_ALLOW;
- }
- }
- else
- {
- if (channel->IsModeSet('B'))
- {
- channel->SetMode('B',false);
- return MODEACTION_ALLOW;
- }
- }
-
- return MODEACTION_DENY;
- }
+ BlockCaps(InspIRCd* Instance) : SimpleChannelModeHandler(Instance, 'B') { }
};
class ModuleBlockCAPS : public Module
/** Handles the +c channel mode
*/
-class BlockColor : public ModeHandler
+class BlockColor : public SimpleChannelModeHandler
{
public:
- BlockColor(InspIRCd* Instance) : ModeHandler(Instance, 'c', 0, 0, false, MODETYPE_CHANNEL, false) { }
-
- ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
- {
- if (adding)
- {
- if (!channel->IsModeSet('c'))
- {
- channel->SetMode('c',true);
- return MODEACTION_ALLOW;
- }
- }
- else
- {
- if (channel->IsModeSet('c'))
- {
- channel->SetMode('c',false);
- return MODEACTION_ALLOW;
- }
- }
-
- return MODEACTION_DENY;
- }
+ BlockColor(InspIRCd* Instance) : SimpleChannelModeHandler(Instance, 'c') { }
};
class ModuleBlockColour : public Module
/** Handles user mode +B
*/
-class BotMode : public ModeHandler
+class BotMode : public SimpleUserModeHandler
{
public:
- BotMode(InspIRCd* Instance) : ModeHandler(Instance, 'B', 0, 0, false, MODETYPE_USER, false) { }
-
- ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
- {
- if (adding)
- {
- if (!dest->IsModeSet('B'))
- {
- dest->SetMode('B',true);
- return MODEACTION_ALLOW;
- }
- }
- else
- {
- if (dest->IsModeSet('B'))
- {
- dest->SetMode('B',false);
- return MODEACTION_ALLOW;
- }
- }
-
- return MODEACTION_DENY;
- }
+ BotMode(InspIRCd* Instance) : SimpleUserModeHandler(Instance, 'B') { }
};
class ModuleBotMode : public Module
}
}
-class User_g : public ModeHandler
+class User_g : public SimpleUserModeHandler
{
private:
public:
- User_g(InspIRCd* Instance) : ModeHandler(Instance, 'g', 0, 0, false, MODETYPE_USER, false) { }
-
- ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
- {
- if (adding != dest->IsModeSet('g'))
- {
- dest->SetMode('g', adding);
- return MODEACTION_ALLOW;
- }
- return MODEACTION_DENY;
- }
+ User_g(InspIRCd* Instance) : SimpleUserModeHandler(Instance, 'g') { }
};
class CommandAccept : public Command
/** Handles usermode +G
*/
-class CensorUser : public ModeHandler
+class CensorUser : public SimpleUserModeHandler
{
public:
- CensorUser(InspIRCd* Instance) : ModeHandler(Instance, 'G', 0, 0, false, MODETYPE_USER, false) { }
-
- ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
- {
- if (adding)
- {
- if (!dest->IsModeSet('G'))
- {
- dest->SetMode('G',true);
- return MODEACTION_ALLOW;
- }
- }
- else
- {
- if (dest->IsModeSet('G'))
- {
- dest->SetMode('G',false);
- return MODEACTION_ALLOW;
- }
- }
-
- return MODEACTION_DENY;
- }
+ CensorUser(InspIRCd* Instance) : SimpleUserModeHandler(Instance, 'G') { }
};
/** Handles channel mode +G
*/
-class CensorChannel : public ModeHandler
+class CensorChannel : public SimpleChannelModeHandler
{
public:
- CensorChannel(InspIRCd* Instance) : ModeHandler(Instance, 'G', 0, 0, false, MODETYPE_CHANNEL, false) { }
-
- ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
- {
- if (adding)
- {
- if (!channel->IsModeSet('G'))
- {
- channel->SetMode('G',true);
- return MODEACTION_ALLOW;
- }
- }
- else
- {
- if (channel->IsModeSet('G'))
- {
- channel->SetMode('G',false);
- return MODEACTION_ALLOW;
- }
- }
-
- return MODEACTION_DENY;
- }
+ CensorChannel(InspIRCd* Instance) : SimpleChannelModeHandler(Instance, 'G') { }
};
class ModuleCensor : public Module
/** Handles user mode +h
*/
-class Helpop : public ModeHandler
+class Helpop : public SimpleUserModeHandler
{
public:
- Helpop(InspIRCd* Instance) : ModeHandler(Instance, 'h', 0, 0, false, MODETYPE_USER, true) { }
-
- ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
- {
- if (adding)
- {
- if (!dest->IsModeSet('h'))
- {
- dest->SetMode('h',true);
- return MODEACTION_ALLOW;
- }
- }
- else
- {
- if (dest->IsModeSet('h'))
- {
- dest->SetMode('h',false);
- return MODEACTION_ALLOW;
- }
- }
-
- return MODEACTION_DENY;
- }
+ Helpop(InspIRCd* Instance) : SimpleUserModeHandler(Instance, 'h') { }
};
/** Handles /HELPOP
/** Handles channel mode +K
*/
-class Knock : public ModeHandler
+class Knock : public SimpleChannelModeHandler
{
public:
- Knock(InspIRCd* Instance) : ModeHandler(Instance, 'K', 0, 0, false, MODETYPE_CHANNEL, false) { }
-
- ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
- {
- if (adding)
- {
- if (!channel->IsModeSet('K'))
- {
- channel->SetMode('K',true);
- return MODEACTION_ALLOW;
- }
- }
- else
- {
- if (channel->IsModeSet('K'))
- {
- channel->SetMode('K',false);
- return MODEACTION_ALLOW;
- }
- }
-
- return MODEACTION_DENY;
- }
+ Knock(InspIRCd* Instance) : SimpleChannelModeHandler(Instance, 'K') { }
};
class ModuleKnock : public Module
/* $ModDesc: Provides support for unreal-style channel mode +V */
-class NoInvite : public ModeHandler
+class NoInvite : public SimpleChannelModeHandler
{
public:
- NoInvite(InspIRCd* Instance) : ModeHandler(Instance, 'V', 0, 0, false, MODETYPE_CHANNEL, false) { }
-
- ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
- {
- if (adding)
- {
- if (!channel->IsModeSet('V'))
- {
- channel->SetMode('V',true);
- return MODEACTION_ALLOW;
- }
- }
- else
- {
- if (channel->IsModeSet('V'))
- {
- channel->SetMode('V',false);
- return MODEACTION_ALLOW;
- }
- }
-
- return MODEACTION_DENY;
- }
+ NoInvite(InspIRCd* Instance) : SimpleChannelModeHandler(Instance, 'V') { }
};
class ModuleNoInvite : public Module
/* $ModDesc: Provides support for unreal-style channel mode +Q */
-class NoKicks : public ModeHandler
+class NoKicks : public SimpleChannelModeHandler
{
public:
- NoKicks(InspIRCd* Instance) : ModeHandler(Instance, 'Q', 0, 0, false, MODETYPE_CHANNEL, false) { }
-
- ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
- {
- if (adding)
- {
- if (!channel->IsModeSet('Q'))
- {
- channel->SetMode('Q',true);
- return MODEACTION_ALLOW;
- }
- }
- else
- {
- if (channel->IsModeSet('Q'))
- {
- channel->SetMode('Q',false);
- return MODEACTION_ALLOW;
- }
- }
-
- return MODEACTION_DENY;
- }
+ NoKicks(InspIRCd* Instance) : SimpleChannelModeHandler(Instance, 'Q') { }
};
class ModuleNoKicks : public Module
/* $ModDesc: Provides support for unreal-style channel mode +T */
-class NoNotice : public ModeHandler
+class NoNotice : public SimpleChannelModeHandler
{
public:
- NoNotice(InspIRCd* Instance) : ModeHandler(Instance, 'T', 0, 0, false, MODETYPE_CHANNEL, false) { }
-
- ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
- {
- if (adding)
- {
- if (!channel->IsModeSet('T'))
- {
- channel->SetMode('T',true);
- return MODEACTION_ALLOW;
- }
- }
- else
- {
- if (channel->IsModeSet('T'))
- {
- channel->SetMode('T',false);
- return MODEACTION_ALLOW;
- }
- }
-
- return MODEACTION_DENY;
- }
+ NoNotice(InspIRCd* Instance) : SimpleChannelModeHandler(Instance, 'T') { }
};
class ModuleNoNotice : public Module
/** Channel mode +R - registered users only
*/
-class Channel_R : public ModeHandler
+class Channel_R : public SimpleChannelModeHandler
{
public:
- Channel_R(InspIRCd* Instance) : ModeHandler(Instance, 'R', 0, 0, false, MODETYPE_CHANNEL, false) { }
-
- ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
- {
- if (adding)
- {
- if (!channel->IsModeSet('R'))
- {
- channel->SetMode('R',true);
- return MODEACTION_ALLOW;
- }
- }
- else
- {
- if (channel->IsModeSet('R'))
- {
- channel->SetMode('R',false);
- return MODEACTION_ALLOW;
- }
- }
-
- return MODEACTION_DENY;
- }
+ Channel_R(InspIRCd* Instance) : SimpleChannelModeHandler(Instance, 'R') { }
};
/** User mode +R - only allow PRIVMSG and NOTICE from registered users
*/
-class User_R : public ModeHandler
+class User_R : public SimpleUserModeHandler
{
public:
- User_R(InspIRCd* Instance) : ModeHandler(Instance, 'R', 0, 0, false, MODETYPE_USER, false) { }
-
- ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
- {
- if (adding)
- {
- if (!dest->IsModeSet('R'))
- {
- dest->SetMode('R',true);
- return MODEACTION_ALLOW;
- }
- }
- else
- {
- if (dest->IsModeSet('R'))
- {
- dest->SetMode('R',false);
- return MODEACTION_ALLOW;
- }
- }
-
- return MODEACTION_DENY;
- }
+ User_R(InspIRCd* Instance) : SimpleUserModeHandler(Instance, 'R') { }
};
/** Channel mode +M - only allow privmsg and notice to channel from registered users
*/
-class Channel_M : public ModeHandler
+class Channel_M : public SimpleChannelModeHandler
{
public:
- Channel_M(InspIRCd* Instance) : ModeHandler(Instance, 'M', 0, 0, false, MODETYPE_CHANNEL, false) { }
-
- ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
- {
- if (adding)
- {
- if (!channel->IsModeSet('M'))
- {
- channel->SetMode('M',true);
- return MODEACTION_ALLOW;
- }
- }
- else
- {
- if (channel->IsModeSet('M'))
- {
- channel->SetMode('M',false);
- return MODEACTION_ALLOW;
- }
- }
-
- return MODEACTION_DENY;
- }
+ Channel_M(InspIRCd* Instance) : SimpleChannelModeHandler(Instance, 'M') { }
};
/** Dreamnforge-like services support
/** Channel mode +R - unidentified users cannot join
*/
-class AChannel_R : public ModeHandler
+class AChannel_R : public SimpleChannelModeHandler
{
public:
- AChannel_R(InspIRCd* Instance) : ModeHandler(Instance, 'R', 0, 0, false, MODETYPE_CHANNEL, false) { }
-
- ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
- {
- if (adding)
- {
- if (!channel->IsModeSet('R'))
- {
- channel->SetMode('R',true);
- return MODEACTION_ALLOW;
- }
- }
- else
- {
- if (channel->IsModeSet('R'))
- {
- channel->SetMode('R',false);
- return MODEACTION_ALLOW;
- }
- }
-
- return MODEACTION_DENY;
- }
+ AChannel_R(InspIRCd* Instance) : SimpleChannelModeHandler(Instance, 'R') { }
};
/** User mode +R - unidentified users cannot message
*/
-class AUser_R : public ModeHandler
+class AUser_R : public SimpleUserModeHandler
{
public:
- AUser_R(InspIRCd* Instance) : ModeHandler(Instance, 'R', 0, 0, false, MODETYPE_USER, false) { }
-
- ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
- {
- if (adding)
- {
- if (!dest->IsModeSet('R'))
- {
- dest->SetMode('R',true);
- return MODEACTION_ALLOW;
- }
- }
- else
- {
- if (dest->IsModeSet('R'))
- {
- dest->SetMode('R',false);
- return MODEACTION_ALLOW;
- }
- }
-
- return MODEACTION_DENY;
- }
+ AUser_R(InspIRCd* Instance) : SimpleUserModeHandler(Instance, 'R') { }
};
/** Channel mode +M - unidentified users cannot message channel
*/
-class AChannel_M : public ModeHandler
+class AChannel_M : public SimpleChannelModeHandler
{
public:
- AChannel_M(InspIRCd* Instance) : ModeHandler(Instance, 'M', 0, 0, false, MODETYPE_CHANNEL, false) { }
-
- ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
- {
- if (adding)
- {
- if (!channel->IsModeSet('M'))
- {
- channel->SetMode('M',true);
- return MODEACTION_ALLOW;
- }
- }
- else
- {
- if (channel->IsModeSet('M'))
- {
- channel->SetMode('M',false);
- return MODEACTION_ALLOW;
- }
- }
-
- return MODEACTION_DENY;
- }
+ AChannel_M(InspIRCd* Instance) : SimpleChannelModeHandler(Instance, 'M') { }
};
class ModuleServicesAccount : public Module
/** Handles channel mode +S
*/
-class ChannelStripColor : public ModeHandler
+class ChannelStripColor : public SimpleChannelModeHandler
{
public:
- ChannelStripColor(InspIRCd* Instance) : ModeHandler(Instance, 'S', 0, 0, false, MODETYPE_CHANNEL, false) { }
-
- ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool servermode)
- {
- if (adding)
- {
- if (!channel->IsModeSet('S'))
- {
- channel->SetMode('S',true);
- return MODEACTION_ALLOW;
- }
- }
- else
- {
- if (channel->IsModeSet('S'))
- {
- channel->SetMode('S',false);
- return MODEACTION_ALLOW;
- }
- }
-
- return MODEACTION_DENY;
- }
+ ChannelStripColor(InspIRCd* Instance) : SimpleChannelModeHandler(Instance, 'S') { }
};
/** Handles user mode +S
*/
-class UserStripColor : public ModeHandler
+class UserStripColor : public SimpleUserModeHandler
{
public:
- UserStripColor(InspIRCd* Instance) : ModeHandler(Instance, 'S', 0, 0, false, MODETYPE_USER, false) { }
-
- ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool servermode)
- {
- /* Only opers can change other users modes */
- if (source != dest)
- return MODEACTION_DENY;
-
- if (adding)
- {
- if (!dest->IsModeSet('S'))
- {
- dest->SetMode('S',true);
- return MODEACTION_ALLOW;
- }
- }
- else
- {
- if (dest->IsModeSet('S'))
- {
- dest->SetMode('S',false);
- return MODEACTION_ALLOW;
- }
- }
-
- return MODEACTION_DENY;
- }
+ UserStripColor(InspIRCd* Instance) : SimpleUserModeHandler(Instance, 'S') { }
};