7 /* $ModDesc: Provides channel modes +a and +q */
9 char dummyvalue[] = "on";
11 class ModuleChanProtect : public Module
20 // set up our modes. We're using listmodes and not normal extmodes here.
21 // listmodes only need one parameter as everything else is assumed by the
22 // nature of the mode thats being created.
23 Srv->AddExtendedListMode('a');
24 Srv->AddExtendedListMode('q');
27 virtual void OnUserJoin(userrec* user, chanrec* channel)
29 // if the user is the first user into the channel, mark them as the founder
30 if (Srv->CountUsers(channel) == 1)
32 if (user->Extend("cm_founder_"+std::string(channel->name),dummyvalue))
34 Srv->Log(DEBUG,"Marked user "+std::string(user->nick)+" as founder for "+std::string(channel->name));
39 virtual int OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type)
41 // don't allow action if:
42 // (A) Theyre founder (no matter what)
43 // (B) Theyre protected, and you're not
47 if (dest->GetExt("cm_founder_"+std::string(channel->name)))
49 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");
52 if ((dest->GetExt("cm_protect_"+std::string(channel->name))) && (!source->GetExt("cm_protect_"+std::string(channel->name))))
54 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)");
60 if (dest->GetExt("cm_founder_"+std::string(channel->name)))
62 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");
65 if ((dest->GetExt("cm_protect_"+std::string(channel->name))) && (!source->GetExt("cm_protect_"+std::string(channel->name))))
67 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)");
73 if (dest->GetExt("cm_founder_"+std::string(channel->name)))
75 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");
78 if ((dest->GetExt("cm_protect_"+std::string(channel->name))) && (!source->GetExt("cm_protect_"+std::string(channel->name))))
80 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)");
86 if (dest->GetExt("cm_founder_"+std::string(channel->name)))
88 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");
91 if ((dest->GetExt("cm_protect_"+std::string(channel->name))) && (!source->GetExt("cm_protect_"+std::string(channel->name))))
93 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)");
101 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
103 // not out mode, bail
104 if ((modechar == 'q') && (type == MT_CHANNEL))
107 chanrec* chan = (chanrec*)target;
108 userrec* theuser = Srv->FindNick(params[0]);
110 // cant find the user given as the parameter, eat the mode change.
114 // given user isnt even on the channel, eat the mode change
115 if (!Srv->IsOnChannel(theuser,chan))
118 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"")))
122 if (!theuser->GetExt("cm_founder_"+std::string(chan->name)))
124 theuser->Extend("cm_founder_"+std::string(chan->name),dummyvalue);
130 if (theuser->GetExt("cm_founder_"+std::string(chan->name)))
132 theuser->Shrink("cm_founder_"+std::string(chan->name));
141 WriteServ(user->fd,"482 %s %s :Only servers may set channel mode +q",user->nick, chan->name);
145 if ((modechar == 'a') && (type == MT_CHANNEL))
148 chanrec* chan = (chanrec*)target;
149 userrec* theuser = Srv->FindNick(params[0]);
151 // cant find the user given as the parameter, eat the mode change.
155 // given user isnt even on the channel, eat the mode change
156 if (!Srv->IsOnChannel(theuser,chan))
159 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"")) || (user->GetExt("cm_founder_"+std::string(chan->name))))
163 if (!theuser->GetExt("cm_founder_"+std::string(chan->name)))
165 theuser->Extend("cm_protect_"+std::string(chan->name),dummyvalue);
171 if (theuser->GetExt("cm_founder_"+std::string(chan->name)))
173 theuser->Shrink("cm_protect_"+std::string(chan->name));
182 WriteServ(user->fd,"482 %s %s :You are not a channel founder",user->nick, chan->name);
189 virtual ~ModuleChanProtect()
194 virtual Version GetVersion()
196 return Version(1,0,0,0);
199 virtual void OnUserConnect(userrec* user)
206 class ModuleChanProtectFactory : public ModuleFactory
209 ModuleChanProtectFactory()
213 ~ModuleChanProtectFactory()
217 virtual Module * CreateModule()
219 return new ModuleChanProtect;
225 extern "C" void * init_module( void )
227 return new ModuleChanProtectFactory;