1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 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;
62 virtual void OnPostCommand(const std::string &command, const char** parameters, int pcnt, User *user, CmdResult result, const std::string &original_line)
64 if ((NoisyOverride) && (OverriddenMode) && (irc::string(command.c_str()) == "MODE") && (result == CMD_SUCCESS))
66 int Total = OverOps + OverDeops + OverVoices + OverDevoices + OverHalfops + OverDehalfops;
68 ServerInstance->SNO->WriteToSnoMask('O',std::string(user->nick)+" Overriding modes: "+ServerInstance->Modes->GetLastParse()+" "+(Total ? "[Detail: " : "")+
69 (OverOps ? ConvToStr(OverOps)+" op"+(OverOps != 1 ? "s" : "")+" " : "")+
70 (OverDeops ? ConvToStr(OverDeops)+" deop"+(OverDeops != 1 ? "s" : "")+" " : "")+
71 (OverVoices ? ConvToStr(OverVoices)+" voice"+(OverVoices != 1 ? "s" : "")+" " : "")+
72 (OverDevoices ? ConvToStr(OverDevoices)+" devoice"+(OverDevoices != 1 ? "s" : "")+" " : "")+
73 (OverHalfops ? ConvToStr(OverHalfops)+" halfop"+(OverHalfops != 1 ? "s" : "")+" " : "")+
74 (OverDehalfops ? ConvToStr(OverDehalfops)+" dehalfop"+(OverDehalfops != 1 ? "s" : "") : "")
77 OverriddenMode = false;
78 OverOps = OverDeops = OverVoices = OverDevoices = OverHalfops = OverDehalfops = 0;
82 virtual void On005Numeric(std::string &output)
84 output.append(" OVERRIDE");
87 virtual bool CanOverride(User* source, const char* token)
89 // checks to see if the oper's type has <type:override>
90 override_t::iterator j = overrides.find(source->oper);
92 if (j != overrides.end())
94 // its defined or * is set, return its value as a boolean for if the token is set
95 return ((j->second.find(token, 0) != std::string::npos) || (j->second.find("*", 0) != std::string::npos));
98 // its not defined at all, count as false
102 virtual int OnUserPreKick(User* source, User* user, Channel* chan, const std::string &reason)
104 if (IS_OPER(source) && CanOverride(source,"KICK"))
106 if (((chan->GetStatus(source) == STATUS_HOP) && (chan->GetStatus(user) == STATUS_OP)) || (chan->GetStatus(source) < STATUS_VOICE))
108 ServerInstance->SNO->WriteToSnoMask('O',std::string(source->nick)+" Override-Kicked "+std::string(user->nick)+" on "+std::string(chan->name)+" ("+reason+")");
110 /* Returning -1 explicitly allows the kick */
116 virtual int OnAccessCheck(User* source,User* dest,Channel* channel,int access_type)
120 if (source && channel)
122 // Fix by brain - allow the change if they arent on channel - rely on boolean short-circuit
123 // to not check the other items in the statement if they arent on the channel
124 int mode = channel->GetStatus(source);
128 if (CanOverride(source,"MODEDEOP"))
131 if ((!channel->HasUser(source)) || (mode < STATUS_OP))
141 if (CanOverride(source,"MODEOP"))
144 if ((!channel->HasUser(source)) || (mode < STATUS_OP))
154 if (CanOverride(source,"MODEVOICE"))
157 if ((!channel->HasUser(source)) || (mode < STATUS_HOP))
167 if (CanOverride(source,"MODEDEVOICE"))
170 if ((!channel->HasUser(source)) || (mode < STATUS_HOP))
180 if (CanOverride(source,"MODEHALFOP"))
183 if ((!channel->HasUser(source)) || (mode < STATUS_OP))
193 if (CanOverride(source,"MODEDEHALFOP"))
196 if ((!channel->HasUser(source)) || (mode < STATUS_OP))
207 if (CanOverride(source,"OTHERMODE"))
210 if ((!channel->HasUser(source)) || (mode < STATUS_OP))
212 OverriddenMode = true;
213 OverOps = OverDeops = OverVoices = OverDevoices = OverHalfops = OverDehalfops = 0;
227 virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs)
233 if ((chan->modes[CM_INVITEONLY]) && (CanOverride(user,"INVITE")))
235 irc::string x = chan->name;
236 if (!user->IsInvited(x))
238 /* XXX - Ugly cast for a parameter that isn't used? :< - Om */
240 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper-override to bypass invite-only", cname, user->nick);
241 ServerInstance->SNO->WriteToSnoMask('O',std::string(user->nick)+" used operoverride to bypass +i on "+std::string(cname));
246 if ((*chan->key) && (CanOverride(user,"KEY")))
249 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper-override to bypass the channel key", cname, user->nick);
250 ServerInstance->SNO->WriteToSnoMask('O',std::string(user->nick)+" used operoverride to bypass +k on "+std::string(cname));
254 if ((chan->limit > 0) && (chan->GetUserCounter() >= chan->limit) && (CanOverride(user,"LIMIT")))
257 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper-override to bypass the channel limit", cname, user->nick);
258 ServerInstance->SNO->WriteToSnoMask('O',std::string(user->nick)+" used operoverride to bypass +l on "+std::string(cname));
262 if (CanOverride(user,"BANWALK"))
264 if (chan->IsBanned(user))
267 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper-override to bypass channel ban", cname, user->nick);
268 ServerInstance->SNO->WriteToSnoMask('O',"%s used oper-override to bypass channel ban on %s", user->nick, cname);
277 virtual ~ModuleOverride()
279 ServerInstance->SNO->DisableSnomask('O');
282 virtual Version GetVersion()
284 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
288 MODULE_INIT(ModuleOverride)