summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-09-13 20:31:23 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-09-13 20:31:23 +0000
commit7892c8a0313c50d8138942ff3b112691caf05a2f (patch)
tree9c0c4a20584c0dca6adbeddec538ff871546dabe /src/modules
parentb4be0c94ab5fb7e5a7a799a195c78de072a5e315 (diff)
Replace OnAccessCheck with OnPreMode to remove a number of redundant checks
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11700 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/m_chanprotect.cpp105
-rw-r--r--src/modules/m_nokicks.cpp33
-rw-r--r--src/modules/m_ojoin.cpp50
-rw-r--r--src/modules/m_override.cpp132
-rw-r--r--src/modules/m_samode.cpp10
5 files changed, 51 insertions, 279 deletions
diff --git a/src/modules/m_chanprotect.cpp b/src/modules/m_chanprotect.cpp
index 15481fb7f..1e03da617 100644
--- a/src/modules/m_chanprotect.cpp
+++ b/src/modules/m_chanprotect.cpp
@@ -256,7 +256,7 @@ class ChanProtect : public ModeHandler, public FounderProtectBase
}
}
- virtual void DisplayList(User* user, Channel* channel)
+ void DisplayList(User* user, Channel* channel)
{
FounderProtectBase::DisplayList(user, channel);
}
@@ -296,8 +296,8 @@ class ModuleChanProtect : public Module
throw ModuleException("Could not add new modes!");
}
- Implementation eventlist[] = { I_OnUserKick, I_OnUserPart, I_OnUserPreJoin, I_OnAccessCheck };
- ServerInstance->Modules->Attach(eventlist, this, 4);
+ Implementation eventlist[] = { I_OnUserKick, I_OnUserPart, I_OnUserPreJoin };
+ ServerInstance->Modules->Attach(eventlist, this, 3);
}
void LoadSettings()
@@ -325,109 +325,18 @@ class ModuleChanProtect : public Module
DeprivOthers = Conf.ReadFlag("chanprotect","deprotectothers", "yes", 0);
}
- virtual ModResult OnUserPreJoin(User *user, Channel *chan, const char *cname, std::string &privs, const std::string &keygiven)
+ ModResult OnUserPreJoin(User *user, Channel *chan, const char *cname, std::string &privs, const std::string &keygiven)
{
// if the user is the first user into the channel, mark them as the founder, but only if
// the config option for it is set
if (FirstInGetsFounder && !chan)
- privs = std::string(1, QPrefix) + "@";
-
- return MOD_RES_PASSTHRU;
- }
-
- virtual ModResult OnAccessCheck(User* source,User* dest,Channel* channel,int access_type)
- {
- // here we perform access checks, this is the important bit that actually stops kicking/deopping
- // etc of protected users. There are many types of access check, we're going to handle
- // a relatively small number of them relevent to our module using a switch statement.
- // don't allow action if:
- // (A) Theyre founder (no matter what)
- // (B) Theyre protected, unless you're founder or are protected and DeprivOthers is enabled
- // always allow the action if:
- // (A) The source is ulined
-
- if ((ServerInstance->ULine(source->nick.c_str())) || (ServerInstance->ULine(source->server)) || (!*source->server))
- return MOD_RES_PASSTHRU;
-
- if (!channel)
- return MOD_RES_PASSTHRU;
-
- // Can do anything to yourself if deprotectself is enabled.
- if (DeprivSelf && source == dest)
- return MOD_RES_PASSTHRU;
-
- Membership* smemb = channel->GetUser(source);
- Membership* dmemb = channel->GetUser(source);
- bool candepriv_founder = (DeprivOthers && smemb && smemb->hasMode('q'));
- bool candepriv_protect = smemb && (smemb->hasMode('q') || (DeprivOthers && smemb->hasMode('a')));
- bool desthas_founder = dmemb->hasMode('q');
- bool desthas_protect = dmemb->hasMode('a');
-
- switch (access_type)
- {
- // a user has been deopped. Do we let them? hmmm...
- case AC_DEOP:
- if (desthas_founder && !candepriv_founder)
- {
- source->WriteNumeric(484, source->nick+" "+channel->name+" :Can't deop "+dest->nick+" as they're a channel founder");
- return MOD_RES_DENY;
- }
- if (desthas_protect && !candepriv_protect)
- {
- source->WriteNumeric(484, source->nick+" "+channel->name+" :Can't deop "+dest->nick+" as they're protected (+a)");
- return MOD_RES_DENY;
- }
- break;
-
- // a user is being kicked. do we chop off the end of the army boot?
- case AC_KICK:
- if (desthas_founder && !candepriv_founder)
- {
- source->WriteNumeric(484, source->nick+" "+channel->name+" :Can't kick "+dest->nick+" as they're a channel founder");
- return MOD_RES_DENY;
- }
- if (desthas_protect && !candepriv_protect)
- {
- source->WriteNumeric(484, source->nick+" "+channel->name+" :Can't kick "+dest->nick+" as they're protected (+a)");
- return MOD_RES_DENY;
- }
- break;
-
- // a user is being dehalfopped. Yes, we do disallow -h of a +ha user
- case AC_DEHALFOP:
- if (desthas_founder && !candepriv_founder)
- {
- source->WriteNumeric(484, source->nick+" "+channel->name+" :Can't de-halfop "+dest->nick+" as they're a channel founder");
- return MOD_RES_DENY;
- }
- if (desthas_protect && !candepriv_protect)
- {
- source->WriteNumeric(484, source->nick+" "+channel->name+" :Can't de-halfop "+dest->nick+" as they're protected (+a)");
- return MOD_RES_DENY;
- }
- break;
-
- // same with devoice.
- case AC_DEVOICE:
- if (desthas_founder && !candepriv_founder)
- {
- source->WriteNumeric(484, source->nick+" "+channel->name+" :Can't devoice "+dest->nick+" as they're a channel founder");
- return MOD_RES_DENY;
- }
- if (desthas_protect && !candepriv_protect)
- {
- source->WriteNumeric(484, source->nick+" "+channel->name+" :Can't devoice "+dest->nick+" as they're protected (+a)");
- return MOD_RES_DENY;
- }
- break;
- }
+ privs += std::string(1, QPrefix);
- // we dont know what this access check is, or dont care. just carry on, nothing to see here.
return MOD_RES_PASSTHRU;
}
- virtual ~ModuleChanProtect()
+ ~ModuleChanProtect()
{
ServerInstance->Modes->DelMode(cp);
ServerInstance->Modes->DelMode(cf);
@@ -435,7 +344,7 @@ class ModuleChanProtect : public Module
delete cf;
}
- virtual Version GetVersion()
+ Version GetVersion()
{
return Version("Founder and Protect modes (+qa)", VF_COMMON | VF_VENDOR);
}
diff --git a/src/modules/m_nokicks.cpp b/src/modules/m_nokicks.cpp
index 4af76e0d8..1324a7c03 100644
--- a/src/modules/m_nokicks.cpp
+++ b/src/modules/m_nokicks.cpp
@@ -31,43 +31,40 @@ class ModuleNoKicks : public Module
{
if (!ServerInstance->Modes->AddMode(&nk))
throw ModuleException("Could not add new modes!");
- Implementation eventlist[] = { I_OnAccessCheck, I_On005Numeric };
+ Implementation eventlist[] = { I_OnUserPreKick, I_On005Numeric };
ServerInstance->Modules->Attach(eventlist, this, 2);
}
- virtual void On005Numeric(std::string &output)
+ void On005Numeric(std::string &output)
{
ServerInstance->AddExtBanChar('Q');
}
- virtual ModResult OnAccessCheck(User* source,User* dest,Channel* channel,int access_type)
+ ModResult OnUserPreKick(User* source, Membership* memb, const std::string &reason)
{
- if (access_type == AC_KICK)
+ if (!memb->chan->GetExtBanStatus(source, 'Q').check(!memb->chan->IsModeSet('Q')))
{
- if (!channel->GetExtBanStatus(source, 'Q').check(!channel->IsModeSet('Q')))
+ if ((ServerInstance->ULine(source->nick.c_str())) || (ServerInstance->ULine(source->server)) || (!*source->server))
{
- if ((ServerInstance->ULine(source->nick.c_str())) || (ServerInstance->ULine(source->server)) || (!*source->server))
- {
- // ulines can still kick with +Q in place
- return MOD_RES_PASSTHRU;
- }
- else
- {
- // nobody else can (not even opers with override, and founders)
- source->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :Can't kick user %s from channel (+Q set)",source->nick.c_str(), channel->name.c_str(), dest->nick.c_str());
- return MOD_RES_DENY;
- }
+ // ulines can still kick with +Q in place
+ return MOD_RES_PASSTHRU;
+ }
+ else
+ {
+ // nobody else can (not even opers with override, and founders)
+ source->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :Can't kick user %s from channel (+Q set)",source->nick.c_str(), memb->chan->name.c_str(), memb->user->nick.c_str());
+ return MOD_RES_DENY;
}
}
return MOD_RES_PASSTHRU;
}
- virtual ~ModuleNoKicks()
+ ~ModuleNoKicks()
{
ServerInstance->Modes->DelMode(&nk);
}
- virtual Version GetVersion()
+ Version GetVersion()
{
return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
}
diff --git a/src/modules/m_ojoin.cpp b/src/modules/m_ojoin.cpp
index c03f2ad1f..8c45c0d50 100644
--- a/src/modules/m_ojoin.cpp
+++ b/src/modules/m_ojoin.cpp
@@ -259,7 +259,7 @@ class ModuleOjoin : public Module
ServerInstance->AddCommand(&mycommand);
- Implementation eventlist[] = { I_OnUserPreJoin, I_OnUserKick, I_OnUserPart, I_OnAccessCheck, I_OnRehash };
+ Implementation eventlist[] = { I_OnUserPreJoin, I_OnUserKick, I_OnUserPart, I_OnUserPreKick, I_OnRehash };
ServerInstance->Modules->Attach(eventlist, this, 5);
}
@@ -294,59 +294,21 @@ class ModuleOjoin : public Module
op = Conf.ReadFlag("ojoin", "op", "yes", 0);
}
- ModResult OnAccessCheck(User* source,User* dest,Channel* channel,int access_type)
+ ModResult OnUserPreKick(User* source, Membership* memb, const std::string &reason)
{
- // Here's where we preform access checks, and disallow any kicking/deopping
- // of +Y users.
-
- // If there's no dest, it's not for us.
- if (!dest || !channel)
- return MOD_RES_PASSTHRU;
-
- // If a ulined nickname, or a server is setting the mode, let it
- // do whatever it wants.
if ((ServerInstance->ULine(source->nick.c_str())) || (ServerInstance->ULine(source->server)) || (!*source->server))
return MOD_RES_PASSTHRU;
- Membership* m = channel->GetUser(dest);
-
// Don't do anything if they're not +Y
- if (!m || !m->hasMode('Y'))
+ if (!memb->hasMode('Y'))
return MOD_RES_PASSTHRU;
// Let them do whatever they want to themselves.
- if (source == dest)
+ if (source == memb->user)
return MOD_RES_PASSTHRU;
- switch (access_type)
- {
- // Disallow deopping of +Y users.
- case AC_DEOP:
- source->WriteNumeric(484, source->nick+" "+channel->name+" :Can't deop "+dest->nick+" as they're on official network business.");
- return MOD_RES_DENY;
- break;
-
- // Kicking people who are here on network business is a no no.
- case AC_KICK:
- source->WriteNumeric(484, source->nick+" "+channel->name+" :Can't kick "+dest->nick+" as they're on official network business.");
- return MOD_RES_DENY;
- break;
-
- // Yes, they're immune to dehalfopping too.
- case AC_DEHALFOP:
- source->WriteNumeric(484, source->nick+" "+channel->name+" :Can't de-halfop "+dest->nick+" as they're on official network business.");
- return MOD_RES_DENY;
- break;
-
- // same with devoice.
- case AC_DEVOICE:
- source->WriteNumeric(484, source->nick+" "+channel->name+" :Can't devoice "+dest->nick+" as they're on official network business.");
- return MOD_RES_DENY;
- break;
- }
-
- // Some other access check that doesn't fall into the above. Let it through.
- return MOD_RES_PASSTHRU;
+ source->WriteNumeric(484, source->nick+" "+memb->chan->name+" :Can't kick "+memb->user->nick+" as they're on official network business.");
+ return MOD_RES_DENY;
}
~ModuleOjoin()
diff --git a/src/modules/m_override.cpp b/src/modules/m_override.cpp
index 38864f400..1f2eb876a 100644
--- a/src/modules/m_override.cpp
+++ b/src/modules/m_override.cpp
@@ -23,9 +23,6 @@ class ModuleOverride : public Module
override_t overrides;
bool RequireKey;
bool NoisyOverride;
- bool OverriddenMode;
- bool OverOther;
- int OverOps, OverDeops, OverVoices, OverDevoices, OverHalfops, OverDehalfops;
public:
@@ -39,13 +36,11 @@ class ModuleOverride : public Module
{
throw ModuleException("m_override: Unable to publish feature 'Override'");
}
- OverriddenMode = OverOther = false;
- OverOps = OverDeops = OverVoices = OverDevoices = OverHalfops = OverDehalfops = 0;
- Implementation eventlist[] = { I_OnRehash, I_OnAccessCheck, I_On005Numeric, I_OnUserPreJoin, I_OnUserPreKick, I_OnPostCommand, I_OnPreTopicChange, I_OnRequest };
- ServerInstance->Modules->Attach(eventlist, this, 8);
+ Implementation eventlist[] = { I_OnRehash, I_OnPreMode, I_On005Numeric, I_OnUserPreJoin, I_OnUserPreKick, I_OnPreTopicChange, I_OnRequest };
+ ServerInstance->Modules->Attach(eventlist, this, 7);
}
- virtual void OnRehash(User* user)
+ void OnRehash(User* user)
{
// on a rehash we delete our classes for good measure and create them again.
ConfigReader Conf(ServerInstance);
@@ -64,43 +59,12 @@ class ModuleOverride : public Module
}
}
-
- virtual void OnPostCommand(const std::string &command, const std::vector<std::string> &parameters, User *user, CmdResult result, const std::string &original_line)
- {
- if (OverriddenMode)
- {
- if ((irc::string(command.c_str()) == "MODE") && (result == CMD_SUCCESS) && !ServerInstance->Modes->GetLastParse().empty())
- {
- std::string msg = std::string(user->nick)+" overriding modes: "+ServerInstance->Modes->GetLastParse()+" [Detail: ";
- if (OverOps)
- msg += ConvToStr(OverOps)+" op"+(OverOps != 1 ? "s" : "")+", ";
- if (OverDeops)
- msg += ConvToStr(OverDeops)+" deop"+(OverDeops != 1 ? "s" : "")+", ";
- if (OverVoices)
- msg += ConvToStr(OverVoices)+" voice"+(OverVoices != 1 ? "s" : "")+", ";
- if (OverDevoices)
- msg += ConvToStr(OverDevoices)+" devoice"+(OverDevoices != 1 ? "s" : "")+", ";
- if (OverHalfops)
- msg += ConvToStr(OverHalfops)+" halfop"+(OverHalfops != 1 ? "s" : "")+", ";
- if (OverDehalfops)
- msg += ConvToStr(OverDehalfops)+" dehalfop"+(OverDehalfops != 1 ? "s" : "")+", ";
- if (OverOther)
- msg += "others, ";
- msg.replace(msg.length()-2, 2, 1, ']');
- ServerInstance->SNO->WriteGlobalSno('G',msg);
- }
-
- OverriddenMode = OverOther = false;
- OverOps = OverDeops = OverVoices = OverDevoices = OverHalfops = OverDehalfops = 0;
- }
- }
-
- virtual void On005Numeric(std::string &output)
+ void On005Numeric(std::string &output)
{
output.append(" OVERRIDE");
}
- virtual bool CanOverride(User* source, const char* token)
+ bool CanOverride(User* source, const char* token)
{
// checks to see if the oper's type has <type:override>
override_t::iterator j = overrides.find(source->oper);
@@ -116,7 +80,7 @@ class ModuleOverride : public Module
}
- virtual ModResult OnPreTopicChange(User *source, Channel *channel, const std::string &topic)
+ ModResult OnPreTopicChange(User *source, Channel *channel, const std::string &topic)
{
if (IS_LOCAL(source) && IS_OPER(source) && CanOverride(source, "TOPIC"))
{
@@ -146,89 +110,29 @@ class ModuleOverride : public Module
return MOD_RES_PASSTHRU;
}
- virtual ModResult OnAccessCheck(User* source,User* dest,Channel* channel,int access_type)
+ ModResult OnPreMode(User* source,User* dest,Channel* channel, const std::vector<std::string>& parameters)
{
if (!IS_OPER(source))
return MOD_RES_PASSTHRU;
if (!source || !channel)
return MOD_RES_PASSTHRU;
- int mode = 0;
+ unsigned int mode = 0;
if (channel->HasUser(source))
mode = channel->GetPrefixValue(source);
- bool over_this = false;
- switch (access_type)
+ if (mode < HALFOP_VALUE && CanOverride(source, "MODE"))
{
- case AC_DEOP:
- if (mode < OP_VALUE && CanOverride(source,"MODEDEOP"))
- {
- over_this = true;
- OverDeops++;
- }
- break;
- case AC_OP:
- if (mode < OP_VALUE && CanOverride(source,"MODEOP"))
- {
- over_this = true;
- OverOps++;
- }
- break;
- case AC_VOICE:
- if (mode < HALFOP_VALUE && CanOverride(source,"MODEVOICE"))
- {
- over_this = true;
- OverVoices++;
- }
- break;
- case AC_DEVOICE:
- if (mode < HALFOP_VALUE && CanOverride(source,"MODEDEVOICE"))
- {
- over_this = true;
- OverDevoices++;
- }
- break;
- case AC_HALFOP:
- if (mode < OP_VALUE && CanOverride(source,"MODEHALFOP"))
- {
- over_this = true;
- OverHalfops++;
- }
- break;
- case AC_DEHALFOP:
- if (mode < OP_VALUE && CanOverride(source,"MODEDEHALFOP"))
- {
- over_this = true;
- OverDehalfops++;
- }
- break;
- case AC_GENERAL_MODE:
- {
- std::string modes = ServerInstance->Modes->GetLastParse();
- bool ohv_only = (modes.find_first_not_of("+-ohv") == std::string::npos);
-
- if (mode < HALFOP_VALUE && (ohv_only || CanOverride(source,"OTHERMODE")))
- {
- over_this = true;
- if (!ohv_only)
- OverOther = true;
- }
- }
- break;
- }
-
- if (over_this)
- {
- OverriddenMode = true;
+ std::string msg = std::string(source->nick)+" overriding modes:";
+ for(unsigned int i=0; i < parameters.size(); i++)
+ msg += " " + parameters[i];
+ ServerInstance->SNO->WriteGlobalSno('G',msg);
return MOD_RES_ALLOW;
}
- else
- {
- return MOD_RES_PASSTHRU;
- }
+ return MOD_RES_PASSTHRU;
}
- virtual ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
+ ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
{
if (IS_LOCAL(user) && IS_OPER(user))
{
@@ -302,7 +206,7 @@ class ModuleOverride : public Module
return MOD_RES_PASSTHRU;
}
- virtual const char* OnRequest(Request* request)
+ const char* OnRequest(Request* request)
{
if(strcmp(OVRREQID, request->GetId()) == 0)
{
@@ -312,13 +216,13 @@ class ModuleOverride : public Module
return NULL;
}
- virtual ~ModuleOverride()
+ ~ModuleOverride()
{
ServerInstance->Modules->UnpublishFeature("Override");
ServerInstance->SNO->DisableSnomask('G');
}
- virtual Version GetVersion()
+ Version GetVersion()
{
return Version("$Id$",VF_VENDOR,API_VERSION);
}
diff --git a/src/modules/m_samode.cpp b/src/modules/m_samode.cpp
index e0e751e7b..2a185680d 100644
--- a/src/modules/m_samode.cpp
+++ b/src/modules/m_samode.cpp
@@ -46,19 +46,19 @@ class ModuleSaMode : public Module
: Module(Me), cmd(Me, this)
{
ServerInstance->AddCommand(&cmd);
- ServerInstance->Modules->Attach(I_OnAccessCheck, this);
+ ServerInstance->Modules->Attach(I_OnPreMode, this);
}
- virtual ~ModuleSaMode()
+ ~ModuleSaMode()
{
}
- virtual Version GetVersion()
+ Version GetVersion()
{
return Version("$Id$", VF_VENDOR, API_VERSION);
}
- virtual ModResult OnAccessCheck(User* source,User* dest,Channel* channel,int access_type)
+ ModResult OnPreMode(User* source,User* dest,Channel* channel, const std::vector<std::string>& parameters)
{
if (cmd.active)
return MOD_RES_ALLOW;
@@ -68,7 +68,7 @@ class ModuleSaMode : public Module
void Prioritize()
{
Module *override = ServerInstance->Modules->Find("m_override.so");
- ServerInstance->Modules->SetPriority(this, I_OnAccessCheck, PRIORITY_BEFORE, &override);
+ ServerInstance->Modules->SetPriority(this, I_OnPreMode, PRIORITY_BEFORE, &override);
}
};