+
+ ModeAction HandleChange(User* source, User* theuser, bool adding, Channel* channel, std::string ¶meter)
+ {
+ std::string item = extend+std::string(channel->name);
+
+ if (adding)
+ {
+ if (!theuser->GetExt(item))
+ {
+ theuser->Extend(item);
+ parameter = theuser->nick;
+ return MODEACTION_ALLOW;
+ }
+ }
+ else
+ {
+ if (theuser->GetExt(item))
+ {
+ theuser->Shrink(item);
+ parameter = theuser->nick;
+ return MODEACTION_ALLOW;
+ }
+ }
+ return MODEACTION_DENY;
+ }
+};
+
+/** Abstraction of FounderProtectBase for channel mode +q
+ */
+class ChanFounder : public ModeHandler, public FounderProtectBase
+{
+ public:
+ ChanFounder(InspIRCd* Instance, char my_prefix, bool &depriv_self, bool &depriv_others)
+ : ModeHandler(Instance, 'q', 1, 1, true, MODETYPE_CHANNEL, false, my_prefix, 0),
+ FounderProtectBase(Instance, "cm_founder_", "founder", 386, 387, depriv_self, depriv_others) { }
+
+ unsigned int GetPrefixRank()
+ {
+ return FOUNDER_VALUE;
+ }
+
+ ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter)
+ {
+ return FounderProtectBase::ModeSet(source, dest, channel, parameter);
+ }
+
+ void RemoveMode(Channel* channel, irc::modestacker* stack)
+ {
+ FounderProtectBase::RemoveMode(channel, this->GetModeChar(), stack);
+ }
+
+ void RemoveMode(User* user, irc::modestacker* stack)
+ {
+ }
+
+ ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
+ {
+ User* theuser = FounderProtectBase::FindAndVerify(parameter, channel);
+
+ if (!theuser)
+ {
+ return MODEACTION_DENY;
+ }
+
+ if ((!adding) && FounderProtectBase::CanRemoveOthers(source, theuser, channel))
+ {
+ return FounderProtectBase::HandleChange(source, theuser, adding, channel, parameter);
+ }
+ // source is a server, or ulined, we'll let them +-q the user.
+ if (source == ServerInstance->FakeClient ||
+ ((source == theuser) && (!adding) && (FounderProtectBase::remove_own_privs)) ||
+ (ServerInstance->ULine(source->nick)) ||
+ (ServerInstance->ULine(source->server)) ||
+ (!*source->server) ||
+ (!IS_LOCAL(source)))
+ {
+ return FounderProtectBase::HandleChange(source, theuser, adding, channel, parameter);
+ }
+ else
+ {
+ // whoops, someones being naughty!
+ source->WriteNumeric(468, "%s %s :Only servers may set channel mode +q",source->nick, channel->name);
+ parameter.clear();
+ return MODEACTION_DENY;
+ }
+ }
+
+ void DisplayList(User* user, Channel* channel)
+ {
+ FounderProtectBase::DisplayList(user,channel);
+ }
+};
+
+/** Abstraction of FounderProtectBase for channel mode +a
+ */
+class ChanProtect : public ModeHandler, public FounderProtectBase
+{
+ public:
+ ChanProtect(InspIRCd* Instance, char my_prefix, bool &depriv_self, bool &depriv_others)
+ : ModeHandler(Instance, 'a', 1, 1, true, MODETYPE_CHANNEL, false, my_prefix, 0),
+ FounderProtectBase(Instance,"cm_protect_","protected user", 388, 389, depriv_self, depriv_others) { }
+
+ unsigned int GetPrefixRank()
+ {
+ return PROTECT_VALUE;
+ }
+
+ ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter)
+ {
+ return FounderProtectBase::ModeSet(source, dest, channel, parameter);
+ }
+
+ void RemoveMode(Channel* channel, irc::modestacker* stack)
+ {
+ FounderProtectBase::RemoveMode(channel, this->GetModeChar(), stack);
+ }
+
+ void RemoveMode(User* user, irc::modestacker* stack)
+ {
+ }
+
+ ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
+ {
+ User* theuser = FounderProtectBase::FindAndVerify(parameter, channel);
+
+ if (!theuser)
+ return MODEACTION_DENY;
+
+ std::string founder = "cm_founder_"+std::string(channel->name);
+
+ if ((!adding) && FounderProtectBase::CanRemoveOthers(source, theuser, channel))
+ {
+ return FounderProtectBase::HandleChange(source, theuser, adding, channel, parameter);
+ }
+ // source has +q, is a server, or ulined, we'll let them +-a the user.
+ if (source == ServerInstance->FakeClient ||
+ ((source == theuser) && (!adding) && (FounderProtectBase::remove_own_privs)) ||
+ (ServerInstance->ULine(source->nick)) ||
+ (ServerInstance->ULine(source->server)) ||
+ (!*source->server) ||
+ (source->GetExt(founder)) ||
+ (!IS_LOCAL(source)))
+ {
+ return FounderProtectBase::HandleChange(source, theuser, adding, channel, parameter);
+ }
+ else
+ {
+ // bzzzt, wrong answer!
+ source->WriteNumeric(482, "%s %s :You are not a channel founder",source->nick, channel->name);
+ return MODEACTION_DENY;
+ }
+ }
+
+ virtual void DisplayList(User* user, Channel* channel)
+ {
+ FounderProtectBase::DisplayList(user, channel);
+ }
+
+};
+
+class ModuleChanProtect : public Module
+{
+
+ bool FirstInGetsFounder;
+ char QPrefix;
+ char APrefix;
+ bool DeprivSelf;
+ bool DeprivOthers;
+ bool booting;
+ ChanProtect* cp;
+ ChanFounder* cf;