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 OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
42 if ((modechar == 'q') && (type == MT_CHANNEL))
45 chanrec* chan = (chanrec*)target;
46 userrec* theuser = Srv->FindNick(params[0]);
48 // cant find the user given as the parameter, eat the mode change.
52 // given user isnt even on the channel, eat the mode change
53 if (!Srv->IsOnChannel(theuser,chan))
56 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"")))
60 if (!theuser->GetExt("cm_founder_"+std::string(chan->name)))
62 theuser->Extend("cm_founder_"+std::string(chan->name),dummyvalue);
68 if (theuser->GetExt("cm_founder_"+std::string(chan->name)))
70 theuser->Shrink("cm_founder_"+std::string(chan->name));
79 WriteServ(user->fd,"482 %s %s :Only servers may set channel mode +q",user->nick, chan->name);
83 if ((modechar == 'a') && (type == MT_CHANNEL))
86 chanrec* chan = (chanrec*)target;
87 userrec* theuser = Srv->FindNick(params[0]);
89 // cant find the user given as the parameter, eat the mode change.
93 // given user isnt even on the channel, eat the mode change
94 if (!Srv->IsOnChannel(theuser,chan))
97 if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"")) || (user->GetExt("cm_founder_"+std::string(chan->name))))
101 if (!theuser->GetExt("cm_founder_"+std::string(chan->name)))
103 theuser->Extend("cm_protect_"+std::string(chan->name),dummyvalue);
109 if (theuser->GetExt("cm_founder_"+std::string(chan->name)))
111 theuser->Shrink("cm_protect_"+std::string(chan->name));
120 WriteServ(user->fd,"482 %s %s :You are not a channel founder",user->nick, chan->name);
127 virtual ~ModuleChanProtect()
132 virtual Version GetVersion()
134 return Version(1,0,0,0);
137 virtual void OnUserConnect(userrec* user)
144 class ModuleChanProtectFactory : public ModuleFactory
147 ModuleChanProtectFactory()
151 ~ModuleChanProtectFactory()
155 virtual Module * CreateModule()
157 return new ModuleChanProtect;
163 extern "C" void * init_module( void )
165 return new ModuleChanProtectFactory;