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 "configreader.h"
24 /* $ModDesc: Provides support for unreal-style oper-override */
26 typedef std::map<std::string,std::string> override_t;
28 class ModuleOverride : public Module
35 ModuleOverride(InspIRCd* Me)
38 // read our config options (main config file)
40 ServerInstance->SNO->EnableSnomask('O',"OVERRIDE");
43 virtual void OnRehash(const std::string ¶meter)
45 // on a rehash we delete our classes for good measure and create them again.
46 ConfigReader* Conf = new ConfigReader(ServerInstance);
48 // re-read our config options on a rehash
49 NoisyOverride = Conf->ReadFlag("override","noisy",0);
51 for (int j =0; j < Conf->Enumerate("type"); j++)
53 std::string typen = Conf->ReadValue("type","name",j);
54 std::string tokenlist = Conf->ReadValue("type","override",j);
55 overrides[typen] = tokenlist;
61 void Implements(char* List)
63 List[I_OnRehash] = List[I_OnAccessCheck] = List[I_On005Numeric] = List[I_OnUserPreJoin] = List[I_OnUserPreKick] = 1;
66 virtual void On005Numeric(std::string &output)
68 output.append(" OVERRIDE");
71 virtual bool CanOverride(userrec* source, char* token)
73 // checks to see if the oper's type has <type:override>
74 override_t::iterator j = overrides.find(source->oper);
76 if (j != overrides.end())
78 // its defined, return its value as a boolean for if the token is set
79 return (j->second.find(token, 0) != std::string::npos);
82 // its not defined at all, count as false
86 virtual int OnUserPreKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason)
88 if ((*source->oper) && (CanOverride(source,"KICK")))
90 if (((chan->GetStatus(source) == STATUS_HOP) && (chan->GetStatus(user) == STATUS_OP)) || (chan->GetStatus(source) < STATUS_VOICE))
92 ServerInstance->SNO->WriteToSnoMask('O',"NOTICE: "+std::string(source->nick)+" Override-Kicked "+std::string(user->nick)+" on "+std::string(chan->name)+" ("+reason+")");
94 /* Returning -1 explicitly allows the kick */
100 virtual int OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type)
104 if (source && channel)
106 // Fix by brain - allow the change if they arent on channel - rely on boolean short-circuit
107 // to not check the other items in the statement if they arent on the channel
108 int mode = channel->GetStatus(source);
109 if ((!channel->HasUser(source)) || ((mode != STATUS_HOP) && (mode != STATUS_OP)))
114 if (CanOverride(source,"MODEDEOP"))
116 ServerInstance->SNO->WriteToSnoMask('O',"NOTICE: "+std::string(source->nick)+" Override-Deopped "+std::string(dest->nick)+" on "+std::string(channel->name));
125 if (CanOverride(source,"MODEOP"))
127 ServerInstance->SNO->WriteToSnoMask('O',"NOTICE: "+std::string(source->nick)+" Override-Opped "+std::string(dest->nick)+" on "+std::string(channel->name));
136 if (CanOverride(source,"MODEVOICE"))
138 ServerInstance->SNO->WriteToSnoMask('O',"NOTICE: "+std::string(source->nick)+" Override-Voiced "+std::string(dest->nick)+" on "+std::string(channel->name));
147 if (CanOverride(source,"MODEDEVOICE"))
149 ServerInstance->SNO->WriteToSnoMask('O',"NOTICE: "+std::string(source->nick)+" Override-Devoiced "+std::string(dest->nick)+" on "+std::string(channel->name));
158 if (CanOverride(source,"MODEHALFOP"))
160 ServerInstance->SNO->WriteToSnoMask('O',"NOTICE: "+std::string(source->nick)+" Override-Halfopped "+std::string(dest->nick)+" on "+std::string(channel->name));
169 if (CanOverride(source,"MODEDEHALFOP"))
171 ServerInstance->SNO->WriteToSnoMask('O',"NOTICE: "+std::string(source->nick)+" Override-Dehalfopped "+std::string(dest->nick)+" on "+std::string(channel->name));
182 if (CanOverride(source,"OTHERMODE"))
195 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
201 if ((chan->modes[CM_INVITEONLY]) && (CanOverride(user,"INVITE")))
205 irc::string x = chan->name;
206 if (!user->IsInvited(x))
208 /* XXX - Ugly cast for a parameter that isn't used? :< - Om */
209 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper-override to bypass invite-only", cname, user->nick);
212 ServerInstance->SNO->WriteToSnoMask('O',std::string(user->nick)+" used operoverride to bypass +i on "+std::string(cname));
216 if ((chan->key[0]) && (CanOverride(user,"KEY")))
219 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper-override to bypass the channel key", cname, user->nick);
220 ServerInstance->SNO->WriteToSnoMask('O',std::string(user->nick)+" used operoverride to bypass +k on "+std::string(cname));
224 if ((chan->limit > 0) && (chan->GetUserCounter() >= chan->limit) && (CanOverride(user,"LIMIT")))
227 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper-override to bypass the channel limit", cname, user->nick);
228 ServerInstance->SNO->WriteToSnoMask('O',std::string(user->nick)+" used operoverride to bypass +l on "+std::string(cname));
232 if (CanOverride(user,"BANWALK"))
234 if (chan->IsBanned(user))
238 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper-override to bypass channel ban", cname, user->nick);
239 ServerInstance->SNO->WriteToSnoMask('O',"%s used oper-override to bypass channel ban", cname, user->nick);
249 virtual ~ModuleOverride()
251 ServerInstance->SNO->DisableSnomask('O');
254 virtual Version GetVersion()
256 return Version(1,0,0,1,VF_VENDOR);
261 class ModuleOverrideFactory : public ModuleFactory
264 ModuleOverrideFactory()
268 ~ModuleOverrideFactory()
272 virtual Module * CreateModule(InspIRCd* Me)
274 return new ModuleOverride(Me);
280 extern "C" void * init_module( void )
282 return new ModuleOverrideFactory;