+const char* fakevalue = "on";
+
+class ChanFounder : public ModeHandler
+{
+ Server* Srv;
+ char* dummyptr;
+
+ public:
+ ChanFounder(Server* s) : ModeHandler('q', 1, 1, true, MODETYPE_CHANNEL, false), Srv(s) { }
+
+ ModePair ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)
+ {
+ userrec* x = Find(parameter);
+ if (x)
+ {
+ if (!channel->HasUser(x))
+ {
+ return std::make_pair(false, parameter);
+ }
+ else
+ {
+ std::string founder = "cm_founder_"+std::string(channel->name);
+ if (x->GetExt(founder,dummyptr))
+ {
+ return std::make_pair(true, x->nick);
+ }
+ else
+ {
+ return std::make_pair(false, parameter);
+ }
+ }
+ }
+ return std::make_pair(false, parameter);
+ }
+
+
+ ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
+ {
+ userrec* theuser = Srv->FindNick(parameter);
+
+ log(DEBUG,"ChanFounder::OnModeChange");
+
+ // cant find the user given as the parameter, eat the mode change.
+ if (!theuser)
+ {
+ log(DEBUG,"No such user in ChanFounder");
+ parameter = "";
+ return MODEACTION_DENY;
+ }
+
+ // given user isnt even on the channel, eat the mode change
+ if (!channel->HasUser(theuser))
+ {
+ log(DEBUG,"Channel doesn't have user in ChanFounder");
+ parameter = "";
+ return MODEACTION_DENY;
+ }
+
+ std::string protect = "cm_protect_"+std::string(channel->name);
+ std::string founder = "cm_founder_"+std::string(channel->name);
+
+ // source is a server, or ulined, we'll let them +-q the user.
+ if ((Srv->IsUlined(source->nick)) || (Srv->IsUlined(source->server)) || (!*source->server) || (!IS_LOCAL(source)))
+ {
+ log(DEBUG,"Allowing remote mode change in ChanFounder");
+ if (adding)
+ {
+ if (!theuser->GetExt(founder,dummyptr))
+ {
+ log(DEBUG,"Does not have the ext item in ChanFounder");
+ if (!theuser->Extend(founder,fakevalue))
+ log(DEBUG,"COULD NOT EXTEND!!!");
+ // Tidy the nickname (make case match etc)
+ parameter = theuser->nick;
+ if (theuser->GetExt(founder, dummyptr))
+ log(DEBUG,"Extended!");
+ else
+ log(DEBUG,"Not extended :(");
+ return MODEACTION_ALLOW;
+ }
+ }
+ else
+ {
+ if (theuser->GetExt(founder, dummyptr))
+ {
+ theuser->Shrink(founder);
+ // Tidy the nickname (make case match etc)
+ parameter = theuser->nick;
+ return MODEACTION_ALLOW;
+ }
+ }
+ return MODEACTION_DENY;
+ }
+ else
+ {
+ // whoops, someones being naughty!
+ source->WriteServ("468 %s %s :Only servers may set channel mode +q",source->nick, channel->name);
+ parameter = "";
+ return MODEACTION_DENY;
+ }
+ }
+
+ void DisplayList(userrec* user, chanrec* channel)
+ {
+ chanuserlist cl = Srv->GetUsers(channel);
+ std::string founder = "cm_founder_"+std::string(channel->name);
+ for (unsigned int i = 0; i < cl.size(); i++)
+ {
+ if (cl[i]->GetExt(founder, dummyptr))
+ {
+ user->WriteServ("386 %s %s %s",user->nick, channel->name,cl[i]->nick);
+ }
+ }
+ user->WriteServ("387 %s %s :End of channel founder list",user->nick, channel->name);
+ }
+
+};
+
+class ChanProtect : public ModeHandler
+{
+ Server* Srv;
+ char* dummyptr;
+ public:
+ ChanProtect(Server* s) : ModeHandler('a', 1, 1, true, MODETYPE_CHANNEL, false), Srv(s) { }
+
+ ModePair ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter)
+ {
+ userrec* x = Find(parameter);
+ if (x)
+ {
+ if (!channel->HasUser(x))
+ {
+ return std::make_pair(false, parameter);
+ }
+ else
+ {
+ std::string founder = "cm_protect_"+std::string(channel->name);
+ if (x->GetExt(founder,dummyptr))
+ {
+ return std::make_pair(true, x->nick);
+ }
+ else
+ {
+ return std::make_pair(false, parameter);
+ }
+ }
+ }
+ return std::make_pair(false, parameter);
+ }
+
+ ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
+ {
+ userrec* theuser = Srv->FindNick(parameter);
+
+ // cant find the user given as the parameter, eat the mode change.
+ if (!theuser)
+ {
+ parameter = "";
+ return MODEACTION_DENY;
+ }
+
+ // given user isnt even on the channel, eat the mode change
+ if (!channel->HasUser(theuser))
+ {
+ parameter = "";
+ return MODEACTION_DENY;
+ }
+
+ std::string protect = "cm_protect_"+std::string(channel->name);
+ std::string founder = "cm_founder_"+std::string(channel->name);
+
+ // source has +q, is a server, or ulined, we'll let them +-a the user.
+ if ((Srv->IsUlined(source->nick)) || (Srv->IsUlined(source->server)) || (!*source->server) || (source->GetExt(founder,dummyptr)) || (!IS_LOCAL(source)))
+ {
+ if (adding)
+ {
+ if (!theuser->GetExt(protect,dummyptr))
+ {
+ theuser->Extend(protect,fakevalue);
+ // Tidy the nickname (make case match etc)
+ parameter = theuser->nick;
+ return MODEACTION_ALLOW;
+ }
+ }
+ else
+ {
+ if (theuser->GetExt(protect,dummyptr))
+ {
+ theuser->Shrink(protect);
+ // Tidy the nickname (make case match etc)
+ parameter = theuser->nick;
+ return MODEACTION_ALLOW;
+ }
+ }
+ return MODEACTION_DENY;
+ }
+ 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)
+ {
+ chanuserlist cl = Srv->GetUsers(channel);
+ std::string protect = "cm_protect_"+std::string(channel->name);
+ for (unsigned int i = 0; i < cl.size(); i++)
+ {
+ if (cl[i]->GetExt(protect,dummyptr))
+ {
+ user->WriteServ("388 %s %s %s",user->nick, channel->name,cl[i]->nick);
+ }
+ }
+ user->WriteServ("389 %s %s :End of channel protected user list",user->nick, channel->name);
+ }
+
+};