7 /* $ModDesc: Provides channel modes +a and +q */
9 char dummyvalue[] = "on";
11 class ModuleChanProtect : public Module
14 bool FirstInGetsFounder;
22 Conf = new ConfigReader;
23 // set up our modes. We're using listmodes and not normal extmodes here.
24 // listmodes only need one parameter as everything else is assumed by the
25 // nature of the mode thats being created.
26 Srv->AddExtendedListMode('a');
27 Srv->AddExtendedListMode('q');
29 // read our config options (main config file)
30 std::string val = Conf->ReadValue("options","noservices",0);
31 FirstInGetsFounder = ((val == "yes") || (val == "1") || (val == "true"));
34 virtual void OnRehash()
37 Conf = new ConfigReader;
38 // re-read our config options on a rehash
39 std::string val = Conf->ReadValue("options","noservices",0);
40 FirstInGetsFounder = ((val == "yes") || (val == "1") || (val == "true"));
43 virtual void OnUserJoin(userrec* user, chanrec* channel)
45 // if the user is the first user into the channel, mark them as the founder, but only if
46 // the config option for it is set
47 if (FirstInGetsFounder)
49 if (Srv->CountUsers(channel) == 1)
51 if (user->Extend("cm_founder_"+std::string(channel->name),dummyvalue))
53 Srv->Log(DEBUG,"Marked user "+std::string(user->nick)+" as founder for "+std::string(channel->name));
59 virtual int OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type)
61 // don't allow action if:
62 // (A) Theyre founder (no matter what)
63 // (B) Theyre protected, and you're not
64 // always allow the action if:
65 // (A) The source is ulined
67 if ((Srv->IsUlined(source->nick)) || (Srv->IsUlined(source->server)))
75 if (dest->GetExt("cm_founder_"+std::string(channel->name)))
77 Srv->SendServ(source->fd,"482 "+std::string(source->nick)+" "+std::string(channel->name)+" :Can't deop "+std::string(dest->nick)+" as the're a channel founder");
80 if ((dest->GetExt("cm_protect_"+std::string(channel->name))) && (!source->GetExt("cm_protect_"+std::string(channel->name))))
82 Srv->SendServ(source->fd,"482 "+std::string(source->nick)+" "+std::string(channel->name)+" :Can't deop "+std::string(dest->nick)+" as the're protected (+a)");
88 if (dest->GetExt("cm_founder_"+std::string(channel->name)))
90 Srv->SendServ(source->fd,"482 "+std::string(source->nick)+" "+std::string(channel->name)+" :Can't kick "+std::string(dest->nick)+" as the're a channel founder");
93 if ((dest->GetExt("cm_protect_"+std::string(channel->name))) && (!source->GetExt("cm_protect_"+std::string(channel->name))))
95 Srv->SendServ(source->fd,"482 "+std::string(source->nick)+" "+std::string(channel->name)+" :Can't kick "+std::string(dest->nick)+" as the're protected (+a)");
101 if (dest->GetExt("cm_founder_"+std::string(channel->name)))
103 Srv->SendServ(source->fd,"482 "+std::string(source->nick)+" "+std::string(channel->name)+" :Can't de-halfop "+std::string(dest->nick)+" as the're a channel founder");
106 if ((dest->GetExt("cm_protect_"+std::string(channel->name))) && (!source->GetExt("cm_protect_"+std::string(channel->name))))
108 Srv->SendServ(source->fd,"482 "+std::string(source->nick)+" "+std::string(channel->name)+" :Can't de-halfop "+std::string(dest->nick)+" as the're protected (+a)");
114 if (dest->GetExt("cm_founder_"+std::string(channel->name)))
116 Srv->SendServ(source->fd,"482 "+std::string(source->nick)+" "+std::string(channel->name)+" :Can't devoice "+std::string(dest->nick)+" as the're a channel founder");
119 if ((dest->GetExt("cm_protect_"+std::string(channel->name))) && (!source->GetExt("cm_protect_"+std::string(channel->name))))
121 Srv->SendServ(source->fd,"482 "+std::string(source->nick)+" "+std::string(channel->name)+" :Can't devoice "+std::string(dest->nick)+" as the're protected (+a)");
129 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
131 // not out mode, bail
132 if ((modechar == 'q') && (type == MT_CHANNEL))
135 chanrec* chan = (chanrec*)target;
136 userrec* theuser = Srv->FindNick(params[0]);
138 // cant find the user given as the parameter, eat the mode change.
142 // given user isnt even on the channel, eat the mode change
143 if (!Srv->IsOnChannel(theuser,chan))
146 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"")))
150 if (!theuser->GetExt("cm_founder_"+std::string(chan->name)))
152 theuser->Extend("cm_founder_"+std::string(chan->name),dummyvalue);
158 if (theuser->GetExt("cm_founder_"+std::string(chan->name)))
160 theuser->Shrink("cm_founder_"+std::string(chan->name));
169 WriteServ(user->fd,"482 %s %s :Only servers may set channel mode +q",user->nick, chan->name);
173 if ((modechar == 'a') && (type == MT_CHANNEL))
176 chanrec* chan = (chanrec*)target;
177 userrec* theuser = Srv->FindNick(params[0]);
179 // cant find the user given as the parameter, eat the mode change.
183 // given user isnt even on the channel, eat the mode change
184 if (!Srv->IsOnChannel(theuser,chan))
187 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"")) || (user->GetExt("cm_founder_"+std::string(chan->name))))
191 if (!theuser->GetExt("cm_founder_"+std::string(chan->name)))
193 theuser->Extend("cm_protect_"+std::string(chan->name),dummyvalue);
199 if (theuser->GetExt("cm_founder_"+std::string(chan->name)))
201 theuser->Shrink("cm_protect_"+std::string(chan->name));
210 WriteServ(user->fd,"482 %s %s :You are not a channel founder",user->nick, chan->name);
217 virtual ~ModuleChanProtect()
223 virtual Version GetVersion()
225 return Version(1,0,0,0);
228 virtual void OnUserConnect(userrec* user)
235 class ModuleChanProtectFactory : public ModuleFactory
238 ModuleChanProtectFactory()
242 ~ModuleChanProtectFactory()
246 virtual Module * CreateModule()
248 return new ModuleChanProtect;
254 extern "C" void * init_module( void )
256 return new ModuleChanProtectFactory;