1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
23 #include "helperfuncs.h"
25 /* $ModDesc: Provides support for unreal-style oper-override */
27 class ModuleOverride : public Module
35 ModuleOverride(Server* Me)
39 // here we initialise our module. Use new to create new instances of the required
43 Conf = new ConfigReader;
45 // read our config options (main config file)
46 NoisyOverride = Conf->ReadFlag("override","noisy",0);
49 virtual void OnRehash(std::string parameter)
51 // on a rehash we delete our classes for good measure and create them again.
53 Conf = new ConfigReader;
54 // re-read our config options on a rehash
55 NoisyOverride = Conf->ReadFlag("override","noisy",0);
58 void Implements(char* List)
60 List[I_OnRehash] = List[I_OnAccessCheck] = List[I_On005Numeric] = List[I_OnUserPreJoin] = List[I_OnUserPreKick] = 1;
63 virtual void On005Numeric(std::string &output)
65 output = output + std::string(" OVERRIDE");
68 virtual bool CanOverride(userrec* source, char* token)
70 // checks to see if the oper's type has <type:override>
71 for (int j =0; j < Conf->Enumerate("type"); j++)
73 std::string typen = Conf->ReadValue("type","name",j);
74 if (!strcmp(typen.c_str(),source->oper))
76 // its defined, return its value as a boolean for if the token is set
77 std::string tokenlist = Conf->ReadValue("type","override",j);
78 return strstr(tokenlist.c_str(),token);
81 // its not defined at all, count as false
85 virtual int OnUserPreKick(userrec* source, userrec* user, chanrec* chan, std::string reason)
87 if ((*source->oper) && (CanOverride(source,"KICK")))
89 if (((Srv->ChanMode(source,chan) == "%") && (Srv->ChanMode(user,chan) == "@")) || (Srv->ChanMode(source,chan) == ""))
91 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Kicked "+std::string(user->nick)+" on "+std::string(chan->name)+" ("+reason+")");
93 /* Returning -1 explicitly allows the kick */
99 virtual int OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type)
103 if ((Srv) && (source) && (channel))
105 // Fix by brain - allow the change if they arent on channel - rely on boolean short-circuit
106 // to not check the other items in the statement if they arent on the channel
107 if ((!Srv->IsOnChannel(source,channel)) || ((Srv->ChanMode(source,channel) != "%") && (Srv->ChanMode(source,channel) != "@")))
112 if (CanOverride(source,"MODEDEOP"))
114 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Deopped "+std::string(dest->nick)+" on "+std::string(channel->name));
117 else return ACR_DEFAULT;
120 if (CanOverride(source,"MODEOP"))
122 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Opped "+std::string(dest->nick)+" on "+std::string(channel->name));
125 else return ACR_DEFAULT;
128 if (CanOverride(source,"MODEVOICE"))
130 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Voiced "+std::string(dest->nick)+" on "+std::string(channel->name));
133 else return ACR_DEFAULT;
136 if (CanOverride(source,"MODEDEVOICE"))
138 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Devoiced "+std::string(dest->nick)+" on "+std::string(channel->name));
141 else return ACR_DEFAULT;
144 if (CanOverride(source,"MODEHALFOP"))
146 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Halfopped "+std::string(dest->nick)+" on "+std::string(channel->name));
149 else return ACR_DEFAULT;
152 if (CanOverride(source,"MODEDEHALFOP"))
154 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Dehalfopped "+std::string(dest->nick)+" on "+std::string(channel->name));
157 else return ACR_DEFAULT;
162 if (CanOverride(source,"OTHERMODE"))
175 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
177 if (strchr(user->modes,'o'))
181 if ((chan->binarymodes & CM_INVITEONLY) && (CanOverride(user,"INVITE")))
185 irc::string x = chan->name;
186 if (!user->IsInvited(x))
188 WriteChannelWithServ((char*)Srv->GetServerName().c_str(),chan,"NOTICE %s :%s invited himself into the channel",cname,user->nick);
191 Srv->SendOpers("*** "+std::string(user->nick)+" used operoverride to bypass +i on "+std::string(cname));
194 if ((chan->key[0]) && (CanOverride(user,"KEY")))
197 WriteChannelWithServ((char*)Srv->GetServerName().c_str(),chan,"NOTICE %s :%s bypassed the channel key",cname,user->nick);
198 Srv->SendOpers("*** "+std::string(user->nick)+" used operoverride to bypass +k on "+std::string(cname));
201 if ((chan->limit >= Srv->CountUsers(chan)) && (CanOverride(user,"LIMIT")))
204 WriteChannelWithServ((char*)Srv->GetServerName().c_str(),chan,"NOTICE %s :%s passed through your channel limit",cname,user->nick);
205 Srv->SendOpers("*** "+std::string(user->nick)+" used operoverride to bypass +l on "+std::string(cname));
209 if (CanOverride(user,"BANWALK"))
219 virtual ~ModuleOverride()
224 virtual Version GetVersion()
226 return Version(1,0,0,1,VF_VENDOR);
231 class ModuleOverrideFactory : public ModuleFactory
234 ModuleOverrideFactory()
238 ~ModuleOverrideFactory()
242 virtual Module * CreateModule(Server* Me)
244 return new ModuleOverride(Me);
250 extern "C" void * init_module( void )
252 return new ModuleOverrideFactory;