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 * ---------------------------------------------------
20 #include "helperfuncs.h"
21 #include "configreader.h"
24 /* $ModDesc: Provides support for unreal-style oper-override */
26 extern InspIRCd* ServerInstance;
28 typedef std::map<std::string,std::string> override_t;
30 class ModuleOverride : public Module
37 ModuleOverride(Server* Me)
41 // here we initialise our module. Use new to create new instances of the required
46 // read our config options (main config file)
50 virtual void OnRehash(const std::string ¶meter)
52 // on a rehash we delete our classes for good measure and create them again.
53 ConfigReader* Conf = new ConfigReader;
55 // re-read our config options on a rehash
56 NoisyOverride = Conf->ReadFlag("override","noisy",0);
58 for (int j =0; j < Conf->Enumerate("type"); j++)
60 std::string typen = Conf->ReadValue("type","name",j);
61 std::string tokenlist = Conf->ReadValue("type","override",j);
62 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.append(" 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);
83 if (j != overrides.end())
85 // its defined, return its value as a boolean for if the token is set
86 return (j->second.find(token, 0) != std::string::npos);
89 // its not defined at all, count as false
93 virtual int OnUserPreKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason)
95 if ((*source->oper) && (CanOverride(source,"KICK")))
97 if (((chan->GetStatus(source) == STATUS_HOP) && (chan->GetStatus(user) == STATUS_OP)) || (chan->GetStatus(source) < STATUS_VOICE))
99 ServerInstance->WriteOpers("*** NOTICE: "+std::string(source->nick)+" Override-Kicked "+std::string(user->nick)+" on "+std::string(chan->name)+" ("+reason+")");
101 /* Returning -1 explicitly allows the kick */
107 virtual int OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type)
111 if ((Srv) && (source) && (channel))
113 // Fix by brain - allow the change if they arent on channel - rely on boolean short-circuit
114 // to not check the other items in the statement if they arent on the channel
115 int mode = channel->GetStatus(source);
116 if ((!channel->HasUser(source)) || ((mode != STATUS_HOP) && (mode != STATUS_OP)))
121 if (CanOverride(source,"MODEDEOP"))
123 ServerInstance->WriteOpers("*** NOTICE: "+std::string(source->nick)+" Override-Deopped "+std::string(dest->nick)+" on "+std::string(channel->name));
132 if (CanOverride(source,"MODEOP"))
134 ServerInstance->WriteOpers("*** NOTICE: "+std::string(source->nick)+" Override-Opped "+std::string(dest->nick)+" on "+std::string(channel->name));
143 if (CanOverride(source,"MODEVOICE"))
145 ServerInstance->WriteOpers("*** NOTICE: "+std::string(source->nick)+" Override-Voiced "+std::string(dest->nick)+" on "+std::string(channel->name));
154 if (CanOverride(source,"MODEDEVOICE"))
156 ServerInstance->WriteOpers("*** NOTICE: "+std::string(source->nick)+" Override-Devoiced "+std::string(dest->nick)+" on "+std::string(channel->name));
165 if (CanOverride(source,"MODEHALFOP"))
167 ServerInstance->WriteOpers("*** NOTICE: "+std::string(source->nick)+" Override-Halfopped "+std::string(dest->nick)+" on "+std::string(channel->name));
176 if (CanOverride(source,"MODEDEHALFOP"))
178 ServerInstance->WriteOpers("*** NOTICE: "+std::string(source->nick)+" Override-Dehalfopped "+std::string(dest->nick)+" on "+std::string(channel->name));
189 if (CanOverride(source,"OTHERMODE"))
202 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
208 if ((chan->modes[CM_INVITEONLY]) && (CanOverride(user,"INVITE")))
212 irc::string x = chan->name;
213 if (!user->IsInvited(x))
215 /* XXX - Ugly cast for a parameter that isn't used? :< - Om */
216 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s invited himself into the channel", cname, user->nick);
219 ServerInstance->WriteOpers("*** "+std::string(user->nick)+" used operoverride to bypass +i on "+std::string(cname));
223 if ((chan->key[0]) && (CanOverride(user,"KEY")))
226 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s bypassed the channel key", cname, user->nick);
227 ServerInstance->WriteOpers("*** "+std::string(user->nick)+" used operoverride to bypass +k on "+std::string(cname));
231 if ((chan->limit > 0) && (chan->GetUserCounter() >= chan->limit) && (CanOverride(user,"LIMIT")))
234 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s passed through your channel limit", cname, user->nick);
235 ServerInstance->WriteOpers("*** "+std::string(user->nick)+" used operoverride to bypass +l on "+std::string(cname));
239 if (CanOverride(user,"BANWALK"))
249 virtual ~ModuleOverride()
253 virtual Version GetVersion()
255 return Version(1,0,0,1,VF_VENDOR);
260 class ModuleOverrideFactory : public ModuleFactory
263 ModuleOverrideFactory()
267 ~ModuleOverrideFactory()
271 virtual Module * CreateModule(Server* Me)
273 return new ModuleOverride(Me);
279 extern "C" void * init_module( void )
281 return new ModuleOverrideFactory;