1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 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 char dummyvalue[] = "on";
29 class ModuleOverride : public Module
40 // here we initialise our module. Use new to create new instances of the required
44 Conf = new ConfigReader;
46 // read our config options (main config file)
47 NoisyOverride = Conf->ReadFlag("override","noisy",0);
50 virtual void OnRehash()
52 // on a rehash we delete our classes for good measure and create them again.
54 Conf = new ConfigReader;
55 // re-read our config options on a rehash
56 NoisyOverride = Conf->ReadFlag("override","noisy",0);
59 virtual void On005Numeric(std::string &output)
61 output = output + std::string(" OVERRIDE");
64 virtual bool CanOverride(userrec* source, char* token)
66 // checks to see if the oper's type has <type:override>
67 for (int j =0; j < Conf->Enumerate("type"); j++)
69 std::string typen = Conf->ReadValue("type","name",j);
70 if (!strcmp(typen.c_str(),source->oper))
72 // its defined, return its value as a boolean for if the token is set
73 std::string tokenlist = Conf->ReadValue("type","override",j);
74 return strstr(tokenlist.c_str(),token);
77 // its not defined at all, count as false
81 virtual int OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type)
83 if (strchr(source->modes,'o'))
85 if ((Srv) && (source) && (channel))
87 // Fix by brain - allow the change if they arent on channel - rely on boolean short-circuit
88 // to not check the other items in the statement if they arent on the channel
89 if ((!Srv->IsOnChannel(source,channel)) || ((Srv->ChanMode(source,channel) != "%") && (Srv->ChanMode(source,channel) != "@")))
94 if (CanOverride(source,"KICK"))
96 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Kicked "+std::string(dest->nick)+" on "+std::string(channel->name));
99 else return ACR_DEFAULT;
102 if (CanOverride(source,"MODEOP"))
104 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Deopped "+std::string(dest->nick)+" on "+std::string(channel->name));
107 else return ACR_DEFAULT;
110 if (CanOverride(source,"MODEDEOP"))
112 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Opped "+std::string(dest->nick)+" on "+std::string(channel->name));
115 else return ACR_DEFAULT;
118 if (CanOverride(source,"MODEVOICE"))
120 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Voiced "+std::string(dest->nick)+" on "+std::string(channel->name));
123 else return ACR_DEFAULT;
126 if (CanOverride(source,"MODEDEVOICE"))
128 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Devoiced "+std::string(dest->nick)+" on "+std::string(channel->name));
131 else return ACR_DEFAULT;
134 if (CanOverride(source,"MODEHALFOP"))
136 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Halfopped "+std::string(dest->nick)+" on "+std::string(channel->name));
139 else return ACR_DEFAULT;
142 if (CanOverride(source,"MODEDEHALFOP"))
144 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Dehalfopped "+std::string(dest->nick)+" on "+std::string(channel->name));
147 else return ACR_DEFAULT;
152 if (CanOverride(source,"OTHERMODE"))
165 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
167 if (strchr(user->modes,'o'))
171 if ((chan->binarymodes & CM_INVITEONLY) && (CanOverride(user,"INVITE")))
175 if (!user->IsInvited(chan->name))
177 WriteChannelWithServ((char*)Srv->GetServerName().c_str(),chan,"NOTICE %s :%s invited himself into the channel",cname,user->nick);
180 Srv->SendOpers("*** "+std::string(user->nick)+" used operoverride to bypass +i on "+std::string(cname));
183 if ((chan->key[0]) && (CanOverride(user,"KEY")))
186 WriteChannelWithServ((char*)Srv->GetServerName().c_str(),chan,"NOTICE %s :%s bypassed the channel key",cname,user->nick);
187 Srv->SendOpers("*** "+std::string(user->nick)+" used operoverride to bypass +k on "+std::string(cname));
190 if ((chan->limit >= Srv->CountUsers(chan)) && (CanOverride(user,"LIMIT")))
193 WriteChannelWithServ((char*)Srv->GetServerName().c_str(),chan,"NOTICE %s :%s passed through your channel limit",cname,user->nick);
194 Srv->SendOpers("*** "+std::string(user->nick)+" used operoverride to bypass +l on "+std::string(cname));
198 if (CanOverride(user,"BANWALK"))
208 virtual ~ModuleOverride()
214 virtual Version GetVersion()
216 return Version(1,0,0,1,VF_VENDOR);
221 class ModuleOverrideFactory : public ModuleFactory
224 ModuleOverrideFactory()
228 ~ModuleOverrideFactory()
232 virtual Module * CreateModule()
234 return new ModuleOverride;
240 extern "C" void * init_module( void )
242 return new ModuleOverrideFactory;