+ bool CanRemoveOthers(userrec* u1, userrec* u2, chanrec* c)
+ {
+ std::string item = extend+std::string(c->name);
+ return (u1->GetExt(item, dummyptr) && u2->GetExt(item, dummyptr));
+ }
+
+ ModeAction HandleChange(userrec* source, userrec* theuser, bool adding, chanrec* channel, std::string ¶meter)
+ {
+ std::string item = extend+std::string(channel->name);
+
+ if (adding)
+ {
+ if (!theuser->GetExt(item, dummyptr))
+ {
+ theuser->Extend(item, fakevalue);
+ parameter = theuser->nick;
+ return MODEACTION_ALLOW;
+ }
+ }
+ else
+ {
+ if (theuser->GetExt(item, dummyptr))
+ {
+ 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
+{
+ char* dummyptr;
+ public:
+ ChanFounder(InspIRCd* Instance, bool using_prefixes, bool &depriv_self, bool &depriv_others)
+ : ModeHandler(Instance, 'q', 1, 1, true, MODETYPE_CHANNEL, false, using_prefixes ? '~' : 0),
+ FounderProtectBase(Instance, "cm_founder_", "founder", 386, 387, depriv_self, depriv_others) { }
+
+ unsigned int GetPrefixRank()
+ {
+ return FOUNDER_VALUE;
+ }
+
+ ModePair ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)
+ {
+ return FounderProtectBase::ModeSet(source, dest, channel, parameter);
+ }
+
+ void RemoveMode(chanrec* channel)
+ {
+ FounderProtectBase::RemoveMode(channel, this->GetModeChar());
+ }
+
+ void RemoveMode(userrec* user)
+ {
+ }
+
+ ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
+ {
+ userrec* 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 ((unload_kludge) || ((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->WriteServ("468 %s %s :Only servers may set channel mode +q",source->nick, channel->name);
+ parameter.clear();
+ return MODEACTION_DENY;
+ }
+ }
+
+ void DisplayList(userrec* user, chanrec* channel)
+ {
+ FounderProtectBase::DisplayList(user,channel);
+ }
+};
+
+/** Abstraction of FounderProtectBase for channel mode +a
+ */
+class ChanProtect : public ModeHandler, public FounderProtectBase
+{
+ char* dummyptr;
+ public:
+ ChanProtect(InspIRCd* Instance, bool using_prefixes, bool &depriv_self, bool &depriv_others)
+ : ModeHandler(Instance, 'a', 1, 1, true, MODETYPE_CHANNEL, false, using_prefixes ? '&' : 0),
+ FounderProtectBase(Instance,"cm_protect_","protected user", 388, 389, depriv_self, depriv_others) { }
+
+ unsigned int GetPrefixRank()
+ {
+ return PROTECT_VALUE;
+ }
+
+ ModePair ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)
+ {
+ return FounderProtectBase::ModeSet(source, dest, channel, parameter);
+ }
+
+ void RemoveMode(chanrec* channel)
+ {
+ FounderProtectBase::RemoveMode(channel, this->GetModeChar());
+ }
+
+ void RemoveMode(userrec* user)
+ {
+ }
+
+ ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
+ {
+ userrec* 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 ((unload_kludge) || ((source == theuser) && (!adding) && (FounderProtectBase::remove_own_privs)) || (ServerInstance->ULine(source->nick)) || (ServerInstance->ULine(source->server)) || (!*source->server) || (source->GetExt(founder,dummyptr)) || (!IS_LOCAL(source)))
+ {
+ return FounderProtectBase::HandleChange(source, theuser, adding, channel, parameter);
+ }
+ else
+ {
+ // bzzzt, wrong answer!
+ source->WriteServ("482 %s %s :You are not a channel founder",source->nick, channel->name);
+ return MODEACTION_DENY;
+ }
+ }
+
+ virtual void DisplayList(userrec* user, chanrec* channel)
+ {
+ FounderProtectBase::DisplayList(user, channel);
+ }
+
+};