1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
17 /* $ModDesc: Provides support for unreal-style oper-override */
19 typedef std::map<std::string,std::string> override_t;
21 class ModuleOverride : public Module
27 int OverOps, OverDeops, OverVoices, OverDevoices, OverHalfops, OverDehalfops;
31 ModuleOverride(InspIRCd* Me)
34 // read our config options (main config file)
36 ServerInstance->SNO->EnableSnomask('O',"OVERRIDE");
37 OverriddenMode = false;
38 OverOps = OverDeops = OverVoices = OverDevoices = OverHalfops = OverDehalfops = 0;
39 Implementation eventlist[] = { I_OnRehash, I_OnAccessCheck, I_On005Numeric, I_OnUserPreJoin, I_OnUserPreKick, I_OnPostCommand };
40 ServerInstance->Modules->Attach(eventlist, this, 6);
43 virtual void OnRehash(User* user, 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] = List[I_OnPostCommand] = 1;
66 virtual void OnPostCommand(const std::string &command, const char** parameters, int pcnt, User *user, CmdResult result, const std::string &original_line)
68 if ((NoisyOverride) && (OverriddenMode) && (irc::string(command.c_str()) == "MODE") && (result == CMD_SUCCESS))
70 int Total = OverOps + OverDeops + OverVoices + OverDevoices + OverHalfops + OverDehalfops;
72 ServerInstance->SNO->WriteToSnoMask('O',std::string(user->nick)+" Overriding modes: "+ServerInstance->Modes->GetLastParse()+" "+(Total ? "[Detail: " : "")+
73 (OverOps ? ConvToStr(OverOps)+" op"+(OverOps != 1 ? "s" : "")+" " : "")+
74 (OverDeops ? ConvToStr(OverDeops)+" deop"+(OverDeops != 1 ? "s" : "")+" " : "")+
75 (OverVoices ? ConvToStr(OverVoices)+" voice"+(OverVoices != 1 ? "s" : "")+" " : "")+
76 (OverDevoices ? ConvToStr(OverDevoices)+" devoice"+(OverDevoices != 1 ? "s" : "")+" " : "")+
77 (OverHalfops ? ConvToStr(OverHalfops)+" halfop"+(OverHalfops != 1 ? "s" : "")+" " : "")+
78 (OverDehalfops ? ConvToStr(OverDehalfops)+" dehalfop"+(OverDehalfops != 1 ? "s" : "") : "")
81 OverriddenMode = false;
82 OverOps = OverDeops = OverVoices = OverDevoices = OverHalfops = OverDehalfops = 0;
86 virtual void On005Numeric(std::string &output)
88 output.append(" OVERRIDE");
91 virtual bool CanOverride(User* source, const char* token)
93 // checks to see if the oper's type has <type:override>
94 override_t::iterator j = overrides.find(source->oper);
96 if (j != overrides.end())
98 // its defined or * is set, return its value as a boolean for if the token is set
99 return ((j->second.find(token, 0) != std::string::npos) || (j->second.find("*", 0) != std::string::npos));
102 // its not defined at all, count as false
106 virtual int OnUserPreKick(User* source, User* user, Channel* chan, const std::string &reason)
108 if (IS_OPER(source) && CanOverride(source,"KICK"))
110 if (((chan->GetStatus(source) == STATUS_HOP) && (chan->GetStatus(user) == STATUS_OP)) || (chan->GetStatus(source) < STATUS_VOICE))
112 ServerInstance->SNO->WriteToSnoMask('O',std::string(source->nick)+" Override-Kicked "+std::string(user->nick)+" on "+std::string(chan->name)+" ("+reason+")");
114 /* Returning -1 explicitly allows the kick */
120 virtual int OnAccessCheck(User* source,User* dest,Channel* channel,int access_type)
124 if (source && channel)
126 // Fix by brain - allow the change if they arent on channel - rely on boolean short-circuit
127 // to not check the other items in the statement if they arent on the channel
128 int mode = channel->GetStatus(source);
132 if (CanOverride(source,"MODEDEOP"))
135 if ((!channel->HasUser(source)) || (mode < STATUS_OP))
145 if (CanOverride(source,"MODEOP"))
148 if ((!channel->HasUser(source)) || (mode < STATUS_OP))
158 if (CanOverride(source,"MODEVOICE"))
161 if ((!channel->HasUser(source)) || (mode < STATUS_HOP))
171 if (CanOverride(source,"MODEDEVOICE"))
174 if ((!channel->HasUser(source)) || (mode < STATUS_HOP))
184 if (CanOverride(source,"MODEHALFOP"))
187 if ((!channel->HasUser(source)) || (mode < STATUS_OP))
197 if (CanOverride(source,"MODEDEHALFOP"))
200 if ((!channel->HasUser(source)) || (mode < STATUS_OP))
211 if (CanOverride(source,"OTHERMODE"))
214 if ((!channel->HasUser(source)) || (mode < STATUS_OP))
216 OverriddenMode = true;
217 OverOps = OverDeops = OverVoices = OverDevoices = OverHalfops = OverDehalfops = 0;
231 virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs)
237 if ((chan->modes[CM_INVITEONLY]) && (CanOverride(user,"INVITE")))
239 irc::string x = chan->name;
240 if (!user->IsInvited(x))
242 /* XXX - Ugly cast for a parameter that isn't used? :< - Om */
244 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper-override to bypass invite-only", cname, user->nick);
245 ServerInstance->SNO->WriteToSnoMask('O',std::string(user->nick)+" used operoverride to bypass +i on "+std::string(cname));
250 if ((*chan->key) && (CanOverride(user,"KEY")))
253 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper-override to bypass the channel key", cname, user->nick);
254 ServerInstance->SNO->WriteToSnoMask('O',std::string(user->nick)+" used operoverride to bypass +k on "+std::string(cname));
258 if ((chan->limit > 0) && (chan->GetUserCounter() >= chan->limit) && (CanOverride(user,"LIMIT")))
261 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper-override to bypass the channel limit", cname, user->nick);
262 ServerInstance->SNO->WriteToSnoMask('O',std::string(user->nick)+" used operoverride to bypass +l on "+std::string(cname));
266 if (CanOverride(user,"BANWALK"))
268 if (chan->IsBanned(user))
271 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper-override to bypass channel ban", cname, user->nick);
272 ServerInstance->SNO->WriteToSnoMask('O',"%s used oper-override to bypass channel ban on %s", user->nick, cname);
281 virtual ~ModuleOverride()
283 ServerInstance->SNO->DisableSnomask('O');
286 virtual Version GetVersion()
288 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
292 MODULE_INIT(ModuleOverride)