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 typedef std::map<std::string,std::string> override_t;
29 class ModuleOverride : public Module
38 ModuleOverride(Server* Me)
42 // here we initialise our module. Use new to create new instances of the required
46 Conf = new ConfigReader;
48 // read our config options (main config file)
52 virtual void OnRehash(const std::string ¶meter)
54 // on a rehash we delete our classes for good measure and create them again.
56 Conf = new ConfigReader;
57 // re-read our config options on a rehash
58 NoisyOverride = Conf->ReadFlag("override","noisy",0);
60 for (int j =0; j < Conf->Enumerate("type"); j++)
62 std::string typen = Conf->ReadValue("type","name",j);
63 std::string tokenlist = Conf->ReadValue("type","override",j);
64 overrides[typen] = tokenlist;
68 void Implements(char* List)
70 List[I_OnRehash] = List[I_OnAccessCheck] = List[I_On005Numeric] = List[I_OnUserPreJoin] = List[I_OnUserPreKick] = 1;
73 virtual void On005Numeric(std::string &output)
75 output = output + std::string(" OVERRIDE");
78 virtual bool CanOverride(userrec* source, char* token)
80 // checks to see if the oper's type has <type:override>
81 override_t::iterator j = overrides.find(source->oper);
82 if (j != overrides.end())
84 // its defined, return its value as a boolean for if the token is set
85 return strstr(j->second.c_str(),token);
87 // its not defined at all, count as false
91 virtual int OnUserPreKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason)
93 if ((*source->oper) && (CanOverride(source,"KICK")))
95 if (((Srv->ChanMode(source,chan) == "%") && (Srv->ChanMode(user,chan) == "@")) || (Srv->ChanMode(source,chan) == ""))
97 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Kicked "+std::string(user->nick)+" on "+std::string(chan->name)+" ("+reason+")");
99 /* Returning -1 explicitly allows the kick */
105 virtual int OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type)
109 if ((Srv) && (source) && (channel))
111 // Fix by brain - allow the change if they arent on channel - rely on boolean short-circuit
112 // to not check the other items in the statement if they arent on the channel
113 std::string mode = Srv->ChanMode(source,channel);
114 if ((!channel->HasUser(source)) || ((mode != "%") && (mode != "@")))
119 if (CanOverride(source,"MODEDEOP"))
121 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Deopped "+std::string(dest->nick)+" on "+std::string(channel->name));
124 else return ACR_DEFAULT;
127 if (CanOverride(source,"MODEOP"))
129 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Opped "+std::string(dest->nick)+" on "+std::string(channel->name));
132 else return ACR_DEFAULT;
135 if (CanOverride(source,"MODEVOICE"))
137 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Voiced "+std::string(dest->nick)+" on "+std::string(channel->name));
140 else return ACR_DEFAULT;
143 if (CanOverride(source,"MODEDEVOICE"))
145 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Devoiced "+std::string(dest->nick)+" on "+std::string(channel->name));
148 else return ACR_DEFAULT;
151 if (CanOverride(source,"MODEHALFOP"))
153 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Halfopped "+std::string(dest->nick)+" on "+std::string(channel->name));
156 else return ACR_DEFAULT;
159 if (CanOverride(source,"MODEDEHALFOP"))
161 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Dehalfopped "+std::string(dest->nick)+" on "+std::string(channel->name));
164 else return ACR_DEFAULT;
169 if (CanOverride(source,"OTHERMODE"))
182 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
188 if ((chan->custom_modes[CM_INVITEONLY]) && (CanOverride(user,"INVITE")))
192 irc::string x = chan->name;
193 if (!user->IsInvited(x))
195 WriteChannelWithServ((char*)Srv->GetServerName().c_str(),chan,"NOTICE %s :%s invited himself into the channel",cname,user->nick);
198 Srv->SendOpers("*** "+std::string(user->nick)+" used operoverride to bypass +i on "+std::string(cname));
201 if ((chan->key[0]) && (CanOverride(user,"KEY")))
204 WriteChannelWithServ((char*)Srv->GetServerName().c_str(),chan,"NOTICE %s :%s bypassed the channel key",cname,user->nick);
205 Srv->SendOpers("*** "+std::string(user->nick)+" used operoverride to bypass +k on "+std::string(cname));
208 if ((chan->limit >= Srv->CountUsers(chan)) && (CanOverride(user,"LIMIT")))
211 WriteChannelWithServ((char*)Srv->GetServerName().c_str(),chan,"NOTICE %s :%s passed through your channel limit",cname,user->nick);
212 Srv->SendOpers("*** "+std::string(user->nick)+" used operoverride to bypass +l on "+std::string(cname));
216 if (CanOverride(user,"BANWALK"))
226 virtual ~ModuleOverride()
231 virtual Version GetVersion()
233 return Version(1,0,0,1,VF_VENDOR);
238 class ModuleOverrideFactory : public ModuleFactory
241 ModuleOverrideFactory()
245 ~ModuleOverrideFactory()
249 virtual Module * CreateModule(Server* Me)
251 return new ModuleOverride(Me);
257 extern "C" void * init_module( void )
259 return new ModuleOverrideFactory;