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"
23 /* $ModDesc: Provides support for unreal-style oper-override */
25 extern InspIRCd* ServerInstance;
27 typedef std::map<std::string,std::string> override_t;
29 class ModuleOverride : public Module
36 ModuleOverride(Server* Me)
40 // here we initialise our module. Use new to create new instances of the required
45 // read our config options (main config file)
49 virtual void OnRehash(const std::string ¶meter)
51 // on a rehash we delete our classes for good measure and create them again.
52 ConfigReader* Conf = new ConfigReader;
54 // re-read our config options on a rehash
55 NoisyOverride = Conf->ReadFlag("override","noisy",0);
57 for (int j =0; j < Conf->Enumerate("type"); j++)
59 std::string typen = Conf->ReadValue("type","name",j);
60 std::string tokenlist = Conf->ReadValue("type","override",j);
61 overrides[typen] = tokenlist;
67 void Implements(char* List)
69 List[I_OnRehash] = List[I_OnAccessCheck] = List[I_On005Numeric] = List[I_OnUserPreJoin] = List[I_OnUserPreKick] = 1;
72 virtual void On005Numeric(std::string &output)
74 output.append(" OVERRIDE");
77 virtual bool CanOverride(userrec* source, char* token)
79 // checks to see if the oper's type has <type:override>
80 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 (j->second.find(token, 0) != std::string::npos);
88 // its not defined at all, count as false
92 virtual int OnUserPreKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason)
94 if ((*source->oper) && (CanOverride(source,"KICK")))
96 if (((chan->GetStatus(source) == STATUS_HOP) && (chan->GetStatus(user) == STATUS_OP)) || (chan->GetStatus(source) < STATUS_VOICE))
98 ServerInstance->WriteOpers("*** NOTICE: "+std::string(source->nick)+" Override-Kicked "+std::string(user->nick)+" on "+std::string(chan->name)+" ("+reason+")");
100 /* Returning -1 explicitly allows the kick */
106 virtual int OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type)
110 if ((Srv) && (source) && (channel))
112 // Fix by brain - allow the change if they arent on channel - rely on boolean short-circuit
113 // to not check the other items in the statement if they arent on the channel
114 int mode = channel->GetStatus(source);
115 if ((!channel->HasUser(source)) || ((mode != STATUS_HOP) && (mode != STATUS_OP)))
120 if (CanOverride(source,"MODEDEOP"))
122 ServerInstance->WriteOpers("*** NOTICE: "+std::string(source->nick)+" Override-Deopped "+std::string(dest->nick)+" on "+std::string(channel->name));
131 if (CanOverride(source,"MODEOP"))
133 ServerInstance->WriteOpers("*** NOTICE: "+std::string(source->nick)+" Override-Opped "+std::string(dest->nick)+" on "+std::string(channel->name));
142 if (CanOverride(source,"MODEVOICE"))
144 ServerInstance->WriteOpers("*** NOTICE: "+std::string(source->nick)+" Override-Voiced "+std::string(dest->nick)+" on "+std::string(channel->name));
153 if (CanOverride(source,"MODEDEVOICE"))
155 ServerInstance->WriteOpers("*** NOTICE: "+std::string(source->nick)+" Override-Devoiced "+std::string(dest->nick)+" on "+std::string(channel->name));
164 if (CanOverride(source,"MODEHALFOP"))
166 ServerInstance->WriteOpers("*** NOTICE: "+std::string(source->nick)+" Override-Halfopped "+std::string(dest->nick)+" on "+std::string(channel->name));
175 if (CanOverride(source,"MODEDEHALFOP"))
177 ServerInstance->WriteOpers("*** NOTICE: "+std::string(source->nick)+" Override-Dehalfopped "+std::string(dest->nick)+" on "+std::string(channel->name));
188 if (CanOverride(source,"OTHERMODE"))
201 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
207 if ((chan->modes[CM_INVITEONLY]) && (CanOverride(user,"INVITE")))
211 irc::string x = chan->name;
212 if (!user->IsInvited(x))
214 /* XXX - Ugly cast for a parameter that isn't used? :< - Om */
215 chan->WriteChannelWithServ(Srv->GetServerName().c_str(), "NOTICE %s :%s invited himself into the channel", cname, user->nick);
218 ServerInstance->WriteOpers("*** "+std::string(user->nick)+" used operoverride to bypass +i on "+std::string(cname));
222 if ((chan->key[0]) && (CanOverride(user,"KEY")))
225 chan->WriteChannelWithServ(Srv->GetServerName().c_str(), "NOTICE %s :%s bypassed the channel key", cname, user->nick);
226 ServerInstance->WriteOpers("*** "+std::string(user->nick)+" used operoverride to bypass +k on "+std::string(cname));
230 if ((chan->limit > 0) && (chan->GetUserCounter() >= chan->limit) && (CanOverride(user,"LIMIT")))
233 chan->WriteChannelWithServ(Srv->GetServerName().c_str(), "NOTICE %s :%s passed through your channel limit", cname, user->nick);
234 ServerInstance->WriteOpers("*** "+std::string(user->nick)+" used operoverride to bypass +l on "+std::string(cname));
238 if (CanOverride(user,"BANWALK"))
248 virtual ~ModuleOverride()
252 virtual Version GetVersion()
254 return Version(1,0,0,1,VF_VENDOR);
259 class ModuleOverrideFactory : public ModuleFactory
262 ModuleOverrideFactory()
266 ~ModuleOverrideFactory()
270 virtual Module * CreateModule(Server* Me)
272 return new ModuleOverride(Me);
278 extern "C" void * init_module( void )
280 return new ModuleOverrideFactory;