]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_override.cpp
Added <oper:swhois> to m_swhois, which will override <type:swhois> if specified
[user/henk/code/inspircd.git] / src / modules / m_override.cpp
index 3d97be577d21395626dc07f2b0529b574bd86a53..edfffcca45ac611ce05278742944edeec632c776 100644 (file)
@@ -30,6 +30,9 @@ class ModuleOverride : public Module
        
        override_t overrides;
        bool NoisyOverride;
+       bool OverriddenMode;
+       int OverOps, OverDeops, OverVoices, OverDevoices, OverHalfops, OverDehalfops;
+
  public:
  
        ModuleOverride(InspIRCd* Me)
@@ -38,6 +41,8 @@ class ModuleOverride : public Module
                // read our config options (main config file)
                OnRehash("");
                ServerInstance->SNO->EnableSnomask('O',"OVERRIDE");
+               OverriddenMode = false;
+               OverOps = OverDeops = OverVoices = OverDevoices = OverHalfops = OverDehalfops = 0;
        }
        
        virtual void OnRehash(const std::string &parameter)
@@ -60,7 +65,27 @@ class ModuleOverride : public Module
 
        void Implements(char* List)
        {
-               List[I_OnRehash] = List[I_OnAccessCheck] = List[I_On005Numeric] = List[I_OnUserPreJoin] = List[I_OnUserPreKick] = 1;
+               List[I_OnRehash] = List[I_OnAccessCheck] = List[I_On005Numeric] = List[I_OnUserPreJoin] = List[I_OnUserPreKick] = List[I_OnPostCommand] = 1;
+       }
+
+       virtual void OnPostCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, CmdResult result, const std::string &original_line)
+       {
+               if ((NoisyOverride) && (OverriddenMode) && (irc::string(command.c_str()) == "MODE") && (result == CMD_SUCCESS))
+               {
+                       int Total = OverOps + OverDeops + OverVoices + OverDevoices + OverHalfops + OverDehalfops;
+
+                       ServerInstance->SNO->WriteToSnoMask('O',std::string(user->nick)+" Overriding modes: "+ServerInstance->Modes->GetLastParse()+" "+(Total ? "[Detail: " : "")+
+                                       (OverOps ? ConvToStr(OverOps)+" op"+(OverOps != 1 ? "s" : "")+" " : "")+
+                                       (OverDeops ? ConvToStr(OverDeops)+" deop"+(OverDeops != 1 ? "s" : "")+" " : "")+
+                                       (OverVoices ? ConvToStr(OverVoices)+" voice"+(OverVoices != 1 ? "s" : "")+" " : "")+
+                                       (OverDevoices ? ConvToStr(OverDevoices)+" devoice"+(OverDevoices != 1 ? "s" : "")+" " : "")+
+                                       (OverHalfops ? ConvToStr(OverHalfops)+" halfop"+(OverHalfops != 1 ? "s" : "")+" " : "")+
+                                       (OverDehalfops ? ConvToStr(OverDehalfops)+" dehalfop"+(OverDehalfops != 1 ? "s" : "") : "")
+                                       +(Total ? "]" : ""));
+
+                       OverriddenMode = false;
+                       OverOps = OverDeops = OverVoices = OverDevoices = OverHalfops = OverDehalfops = 0;
+               }
        }
 
        virtual void On005Numeric(std::string &output)
@@ -72,13 +97,13 @@ class ModuleOverride : public Module
        {
                // checks to see if the oper's type has <type:override>
                override_t::iterator j = overrides.find(source->oper);
-               
+
                if (j != overrides.end())
                {
-                       // its defined, return its value as a boolean for if the token is set
-                       return (j->second.find(token, 0) != std::string::npos);
+                       // its defined or * is set, return its value as a boolean for if the token is set
+                       return ((j->second.find(token, 0) != std::string::npos) || (j->second.find("*", 0) != std::string::npos));
                }
-               
+
                // its not defined at all, count as false
                return false;
        }
@@ -89,7 +114,7 @@ class ModuleOverride : public Module
                {
                        if (((chan->GetStatus(source) == STATUS_HOP) && (chan->GetStatus(user) == STATUS_OP)) || (chan->GetStatus(source) < STATUS_VOICE))
                        {
-                               ServerInstance->SNO->WriteToSnoMask('O',"NOTICE: "+std::string(source->nick)+" Override-Kicked "+std::string(user->nick)+" on "+std::string(chan->name)+" ("+reason+")");
+                               ServerInstance->SNO->WriteToSnoMask('O',std::string(source->nick)+" Override-Kicked "+std::string(user->nick)+" on "+std::string(chan->name)+" ("+reason+")");
                        }
                        /* Returning -1 explicitly allows the kick */
                        return -1;
@@ -99,7 +124,6 @@ class ModuleOverride : public Module
        
        virtual int OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type)
        {
-               ServerInstance->Log(DEBUG,"Override access check");
                if (*source->oper)
                {
                        if (source && channel)
@@ -115,7 +139,7 @@ class ModuleOverride : public Module
                                                {
                                                        if (NoisyOverride)
                                                        if ((!channel->HasUser(source)) || (mode < STATUS_OP))
-                                                               ServerInstance->SNO->WriteToSnoMask('O',"NOTICE: "+std::string(source->nick)+" Override-Deopped "+std::string(dest->nick)+" on "+std::string(channel->name));
+                                                               OverDeops++;
                                                        return ACR_ALLOW;
                                                }
                                                else
@@ -129,7 +153,7 @@ class ModuleOverride : public Module
                                                {
                                                        if (NoisyOverride)
                                                        if ((!channel->HasUser(source)) || (mode < STATUS_OP))
-                                                               ServerInstance->SNO->WriteToSnoMask('O',"NOTICE: "+std::string(source->nick)+" Override-Opped "+std::string(dest->nick)+" on "+std::string(channel->name));
+                                                               OverOps++;
                                                        return ACR_ALLOW;
                                                }
                                                else
@@ -143,7 +167,7 @@ class ModuleOverride : public Module
                                                {
                                                        if (NoisyOverride)
                                                        if ((!channel->HasUser(source)) || (mode < STATUS_HOP))
-                                                               ServerInstance->SNO->WriteToSnoMask('O',"NOTICE: "+std::string(source->nick)+" Override-Voiced "+std::string(dest->nick)+" on "+std::string(channel->name));
+                                                               OverVoices++;
                                                        return ACR_ALLOW;
                                                }
                                                else
@@ -157,7 +181,7 @@ class ModuleOverride : public Module
                                                {
                                                        if (NoisyOverride)
                                                        if ((!channel->HasUser(source)) || (mode < STATUS_HOP))
-                                                               ServerInstance->SNO->WriteToSnoMask('O',"NOTICE: "+std::string(source->nick)+" Override-Devoiced "+std::string(dest->nick)+" on "+std::string(channel->name));
+                                                               OverDevoices++;
                                                        return ACR_ALLOW;
                                                }
                                                else
@@ -171,7 +195,7 @@ class ModuleOverride : public Module
                                                {
                                                        if (NoisyOverride)
                                                        if ((!channel->HasUser(source)) || (mode < STATUS_OP))
-                                                               ServerInstance->SNO->WriteToSnoMask('O',"NOTICE: "+std::string(source->nick)+" Override-Halfopped "+std::string(dest->nick)+" on "+std::string(channel->name));
+                                                               OverHalfops++;
                                                        return ACR_ALLOW;
                                                }
                                                else
@@ -185,7 +209,7 @@ class ModuleOverride : public Module
                                                {
                                                        if (NoisyOverride)
                                                        if ((!channel->HasUser(source)) || (mode < STATUS_OP))
-                                                               ServerInstance->SNO->WriteToSnoMask('O',"NOTICE: "+std::string(source->nick)+" Override-Dehalfopped "+std::string(dest->nick)+" on "+std::string(channel->name));
+                                                               OverDehalfops++;
                                                        return ACR_ALLOW;
                                                }
                                                else
@@ -197,10 +221,13 @@ class ModuleOverride : public Module
                        
                                if (CanOverride(source,"OTHERMODE"))
                                {
-                                       ServerInstance->Log(DEBUG,"Override access check other mode");
                                        if (NoisyOverride)
                                        if ((!channel->HasUser(source)) || (mode < STATUS_OP))
-                                               ServerInstance->SNO->WriteToSnoMask('O',"NOTICE: "+std::string(source->nick)+" changed modes on "+std::string(channel->name));
+                                       {
+                                               ServerInstance->Log(DEBUG,"Overridden mode");
+                                               OverriddenMode = true;
+                                               OverOps = OverDeops = OverVoices = OverDevoices = OverHalfops = OverDehalfops = 0;
+                                       }
                                        return ACR_ALLOW;
                                }
                                else
@@ -213,7 +240,7 @@ class ModuleOverride : public Module
                return ACR_DEFAULT;
        }
        
-       virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
+       virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname, std::string &privs)
        {
                if (*user->oper)
                {
@@ -221,20 +248,18 @@ class ModuleOverride : public Module
                        {
                                if ((chan->modes[CM_INVITEONLY]) && (CanOverride(user,"INVITE")))
                                {
-                                       if (NoisyOverride)
+                                       irc::string x = chan->name;
+                                       if (!user->IsInvited(x))
                                        {
-                                               irc::string x = chan->name;
-                                               if (!user->IsInvited(x))
-                                               {
-                                                       /* XXX - Ugly cast for a parameter that isn't used? :< - Om */
+                                               /* XXX - Ugly cast for a parameter that isn't used? :< - Om */
+                                               if (NoisyOverride)
                                                        chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper-override to bypass invite-only", cname, user->nick);
-                                               }
+                                               ServerInstance->SNO->WriteToSnoMask('O',std::string(user->nick)+" used operoverride to bypass +i on "+std::string(cname));
                                        }
-                                       ServerInstance->SNO->WriteToSnoMask('O',std::string(user->nick)+" used operoverride to bypass +i on "+std::string(cname));
                                        return -1;
                                }
                                
-                               if ((chan->key[0]) && (CanOverride(user,"KEY")))
+                               if ((*chan->key) && (CanOverride(user,"KEY")))
                                {
                                        if (NoisyOverride)
                                                chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper-override to bypass the channel key", cname, user->nick);
@@ -255,10 +280,8 @@ class ModuleOverride : public Module
                                        if (chan->IsBanned(user))
                                        {
                                                if (NoisyOverride)
-                                               {
                                                        chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper-override to bypass channel ban", cname, user->nick);
-                                                       ServerInstance->SNO->WriteToSnoMask('O',"%s used oper-override to bypass channel ban", cname, user->nick);
-                                               }
+                                               ServerInstance->SNO->WriteToSnoMask('O',"%s used oper-override to bypass channel ban on %s", user->nick, cname);
                                        }
                                        return -1;
                                }
@@ -274,7 +297,7 @@ class ModuleOverride : public Module
        
        virtual Version GetVersion()
        {
-               return Version(1,0,0,1,VF_VENDOR);
+               return Version(1,1,0,1,VF_VENDOR,API_VERSION);
        }
 };