7 /* $ModDesc: Provides channel modes +a and +q */
9 char dummyvalue[] = "on";
11 class ModuleChanProtect : public Module
14 bool FirstInGetsFounder;
22 // here we initialise our module. Use new to create new instances of the required
26 Conf = new ConfigReader;
28 // set up our modes. We're using listmodes and not normal extmodes here.
29 // listmodes only need one parameter as everything else is assumed by the
30 // nature of the mode thats being created.
31 Srv->AddExtendedListMode('a');
32 Srv->AddExtendedListMode('q');
34 // read our config options (main config file)
35 std::string val = Conf->ReadValue("options","noservices",0);
36 FirstInGetsFounder = ((val == "yes") || (val == "1") || (val == "true"));
39 virtual void OnRehash()
41 // on a rehash we delete our classes for good measure and create them again.
43 Conf = new ConfigReader;
44 // re-read our config options on a rehash
45 std::string val = Conf->ReadValue("options","noservices",0);
46 FirstInGetsFounder = ((val == "yes") || (val == "1") || (val == "true"));
49 virtual void OnUserJoin(userrec* user, chanrec* channel)
51 // if the user is the first user into the channel, mark them as the founder, but only if
52 // the config option for it is set
53 if (FirstInGetsFounder)
55 if (Srv->CountUsers(channel) == 1)
57 if (user->Extend("cm_founder_"+std::string(channel->name),dummyvalue))
59 Srv->Log(DEBUG,"Marked user "+std::string(user->nick)+" as founder for "+std::string(channel->name));
65 virtual int OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type)
67 // don't allow action if:
68 // (A) Theyre founder (no matter what)
69 // (B) Theyre protected, and you're not
70 // always allow the action if:
71 // (A) The source is ulined
73 if ((Srv->IsUlined(source->nick)) || (Srv->IsUlined(source->server)))
81 if (dest->GetExt("cm_founder_"+std::string(channel->name)))
83 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");
86 if ((dest->GetExt("cm_protect_"+std::string(channel->name))) && (!source->GetExt("cm_protect_"+std::string(channel->name))))
88 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)");
94 if (dest->GetExt("cm_founder_"+std::string(channel->name)))
96 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");
99 if ((dest->GetExt("cm_protect_"+std::string(channel->name))) && (!source->GetExt("cm_protect_"+std::string(channel->name))))
101 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)");
107 if (dest->GetExt("cm_founder_"+std::string(channel->name)))
109 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");
112 if ((dest->GetExt("cm_protect_"+std::string(channel->name))) && (!source->GetExt("cm_protect_"+std::string(channel->name))))
114 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)");
120 if (dest->GetExt("cm_founder_"+std::string(channel->name)))
122 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");
125 if ((dest->GetExt("cm_protect_"+std::string(channel->name))) && (!source->GetExt("cm_protect_"+std::string(channel->name))))
127 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)");
135 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
137 // not out mode, bail
138 if ((modechar == 'q') && (type == MT_CHANNEL))
141 chanrec* chan = (chanrec*)target;
142 userrec* theuser = Srv->FindNick(params[0]);
144 // cant find the user given as the parameter, eat the mode change.
148 // given user isnt even on the channel, eat the mode change
149 if (!Srv->IsOnChannel(theuser,chan))
152 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"")))
156 if (!theuser->GetExt("cm_founder_"+std::string(chan->name)))
158 theuser->Extend("cm_founder_"+std::string(chan->name),dummyvalue);
164 if (theuser->GetExt("cm_founder_"+std::string(chan->name)))
166 theuser->Shrink("cm_founder_"+std::string(chan->name));
175 WriteServ(user->fd,"482 %s %s :Only servers may set channel mode +q",user->nick, chan->name);
179 if ((modechar == 'a') && (type == MT_CHANNEL))
182 chanrec* chan = (chanrec*)target;
183 userrec* theuser = Srv->FindNick(params[0]);
185 // cant find the user given as the parameter, eat the mode change.
189 // given user isnt even on the channel, eat the mode change
190 if (!Srv->IsOnChannel(theuser,chan))
193 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"")) || (user->GetExt("cm_founder_"+std::string(chan->name))))
197 if (!theuser->GetExt("cm_protect_"+std::string(chan->name)))
199 theuser->Extend("cm_protect_"+std::string(chan->name),dummyvalue);
205 if (theuser->GetExt("cm_protect_"+std::string(chan->name)))
207 theuser->Shrink("cm_protect_"+std::string(chan->name));
216 WriteServ(user->fd,"482 %s %s :You are not a channel founder",user->nick, chan->name);
223 virtual ~ModuleChanProtect()
229 virtual Version GetVersion()
231 return Version(1,0,0,0);
234 virtual string_list OnChannelSync(chanrec* chan)
236 chanuserlist cl = Srv->GetUsers(chan);
237 string_list commands;
238 for (int i = 0; i < cl.size(); i++)
240 if (cl[i]->GetExt("cm_founder_"+std::string(chan->name)))
242 commands.push_back("M "+std::string(chan->name)+" +q "+std::string(cl[i]->nick));
244 if (cl[i]->GetExt("cm_protect_"+std::string(chan->name)))
246 commands.push_back("M "+std::string(chan->name)+" +a "+std::string(cl[i]->nick));
255 class ModuleChanProtectFactory : public ModuleFactory
258 ModuleChanProtectFactory()
262 ~ModuleChanProtectFactory()
266 virtual Module * CreateModule()
268 return new ModuleChanProtect;
274 extern "C" void * init_module( void )
276 return new ModuleChanProtectFactory;