summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/channels.cpp33
-rw-r--r--src/mode.cpp7
-rw-r--r--src/modes/cmode_h.cpp78
-rw-r--r--src/modes/cmode_o.cpp77
-rw-r--r--src/modes/cmode_v.cpp77
-rw-r--r--src/modules.cpp2
-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
11 files changed, 73 insertions, 531 deletions
diff --git a/src/channels.cpp b/src/channels.cpp
index 37edcebfb..adb0e6ebe 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -527,10 +527,8 @@ long Channel::KickUser(User *src, User *user, const char* reason)
ModResult res;
if (ServerInstance->ULine(src->server))
res = MOD_RES_ALLOW;
- if (res == MOD_RES_PASSTHRU)
+ else
FIRST_MOD_RESULT(ServerInstance, OnUserPreKick, res, (src,memb,reason));
- if (res == MOD_RES_PASSTHRU)
- FIRST_MOD_RESULT(ServerInstance, OnAccessCheck, res, (src,user,this,AC_KICK));
if (res == MOD_RES_DENY)
return this->GetUserCounter();
@@ -980,24 +978,27 @@ unsigned int Channel::GetPrefixValue(User* user)
void Channel::SetPrefix(User* user, char prefix, unsigned int prefix_value, bool adding)
{
+ ModeHandler* delta_mh = ServerInstance->Modes->FindMode(prefix, MODETYPE_CHANNEL);
+ if (!delta_mh)
+ return;
UserMembIter m = userlist.find(user);
- if (m != userlist.end())
+ if (m == userlist.end())
+ return;
+ for(unsigned int i=0; i < m->second->modes.length(); i++)
{
- for(unsigned int i=0; i < m->second->modes.length(); i++)
+ char mchar = m->second->modes[i];
+ ModeHandler* mh = ServerInstance->Modes->FindMode(mchar, MODETYPE_CHANNEL);
+ if (mh && mh->GetPrefixRank() <= delta_mh->GetPrefixRank())
{
- char mchar = m->second->modes[i];
- ModeHandler* mh = ServerInstance->Modes->FindMode(mchar, MODETYPE_CHANNEL);
- if (mh && mh->GetPrefixRank() <= prefix_value)
- {
- m->second->modes =
- m->second->modes.substr(0,i-1) +
- (adding ? std::string(1, prefix) : "") +
- m->second->modes.substr(mchar == prefix ? i+1 : i);
- return;
- }
+ m->second->modes =
+ m->second->modes.substr(0,i) +
+ (adding ? std::string(1, prefix) : "") +
+ m->second->modes.substr(mchar == prefix ? i+1 : i);
+ return;
}
- m->second->modes += std::string(1, prefix);
}
+ if (adding)
+ m->second->modes += std::string(1, prefix);
}
void Channel::RemoveAllPrefixes(User* user)
diff --git a/src/mode.cpp b/src/mode.cpp
index c760df3f5..18384aaef 100644
--- a/src/mode.cpp
+++ b/src/mode.cpp
@@ -419,13 +419,8 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
}
else
{
- /* Overall access control hook for mode change */
- int hook = targetchannel ? AC_GENERAL_MODE : AC_GENERAL_UMODE;
-
- LastParse = mode_sequence;
ModResult MOD_RESULT;
- FIRST_MOD_RESULT(ServerInstance, OnAccessCheck, MOD_RESULT, (user, targetuser, targetchannel, hook));
- LastParse.clear();
+ FIRST_MOD_RESULT(ServerInstance, OnPreMode, MOD_RESULT, (user, targetuser, targetchannel, parameters));
if (MOD_RESULT == MOD_RES_DENY)
return;
SkipAccessChecks = (MOD_RESULT == MOD_RES_ALLOW);
diff --git a/src/modes/cmode_h.cpp b/src/modes/cmode_h.cpp
index 480d69f0a..a61df4ba0 100644
--- a/src/modes/cmode_h.cpp
+++ b/src/modes/cmode_h.cpp
@@ -74,81 +74,5 @@ void ModeChannelHalfOp::RemoveMode(User*, irc::modestacker* stack)
ModeAction ModeChannelHalfOp::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding)
{
- int status = channel->GetPrefixValue(source);
-
- /* Call the correct method depending on wether we're adding or removing the mode */
- if (adding)
- {
- parameter = this->AddHalfOp(source, parameter.c_str(), channel, status);
- }
- else
- {
- parameter = this->DelHalfOp(source, parameter.c_str(), channel, status);
- }
- /* If the method above 'ate' the parameter by reducing it to an empty string, then
- * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
- * the return value and is always MODEACTION_DENY if the mode is supposed to have
- * a parameter.
- */
- if (parameter.length())
- return MODEACTION_ALLOW;
- else
- return MODEACTION_DENY;
-}
-
-std::string ModeChannelHalfOp::AddHalfOp(User *user,const char* dest,Channel *chan,int status)
-{
- User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
-
- if (d)
- {
- if (IS_LOCAL(user))
- {
- ModResult MOD_RESULT;
- FIRST_MOD_RESULT(ServerInstance, OnAccessCheck, MOD_RESULT, (user,d,chan,AC_HALFOP));
-
- if (MOD_RESULT == MOD_RES_DENY)
- return "";
- if (MOD_RESULT == MOD_RES_PASSTHRU)
- {
- if ((status < OP_VALUE) && (!ServerInstance->ULine(user->server)))
- {
- user->WriteServ("482 %s %s :You're not a channel operator",user->nick.c_str(), chan->name.c_str());
- return "";
- }
- }
- }
-
- return d->nick;
- }
- return "";
+ return MODEACTION_ALLOW;
}
-
-std::string ModeChannelHalfOp::DelHalfOp(User *user,const char *dest,Channel *chan,int status)
-{
- User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
-
- if (d)
- {
- if (IS_LOCAL(user))
- {
- ModResult MOD_RESULT;
- FIRST_MOD_RESULT(ServerInstance, OnAccessCheck, MOD_RESULT, (user,d,chan,AC_DEHALFOP));
-
- if (MOD_RESULT == MOD_RES_DENY)
- return "";
- if (MOD_RESULT == MOD_RES_PASSTHRU)
- {
- if ((user != d) && ((status < OP_VALUE) && (!ServerInstance->ULine(user->server))))
- {
- user->WriteServ("482 %s %s :You are not a channel operator",user->nick.c_str(), chan->name.c_str());
- return "";
- }
- }
- }
-
- return d->nick;
- }
- return "";
-}
-
diff --git a/src/modes/cmode_o.cpp b/src/modes/cmode_o.cpp
index 9da9fa478..19c365ad9 100644
--- a/src/modes/cmode_o.cpp
+++ b/src/modes/cmode_o.cpp
@@ -72,80 +72,5 @@ void ModeChannelOp::RemoveMode(User*, irc::modestacker* stack)
ModeAction ModeChannelOp::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding)
{
- int status = channel->GetPrefixValue(source);
-
- /* Call the correct method depending on wether we're adding or removing the mode */
- if (adding)
- {
- parameter = this->AddOp(source, parameter.c_str(), channel, status);
- }
- else
- {
- parameter = this->DelOp(source, parameter.c_str(), channel, status);
- }
- /* If the method above 'ate' the parameter by reducing it to an empty string, then
- * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
- * the return value and is always MODEACTION_DENY if the mode is supposed to have
- * a parameter.
- */
- if (parameter.length())
- return MODEACTION_ALLOW;
- else
- return MODEACTION_DENY;
-}
-
-std::string ModeChannelOp::AddOp(User *user,const char* dest,Channel *chan,int status)
-{
- User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
-
- if (d)
- {
- if (IS_LOCAL(user))
- {
- ModResult MOD_RESULT;
- FIRST_MOD_RESULT(ServerInstance, OnAccessCheck, MOD_RESULT, (user,d,chan,AC_OP));
-
- if (MOD_RESULT == MOD_RES_DENY)
- return "";
- if (MOD_RESULT == MOD_RES_PASSTHRU)
- {
- if ((status < OP_VALUE) && (!ServerInstance->ULine(user->server)))
- {
- user->WriteServ("482 %s %s :You're not a channel operator",user->nick.c_str(), chan->name.c_str());
- return "";
- }
- }
- }
-
- return d->nick;
- }
- return "";
-}
-
-std::string ModeChannelOp::DelOp(User *user,const char *dest,Channel *chan,int status)
-{
- User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
-
- if (d)
- {
- if (IS_LOCAL(user))
- {
- ModResult MOD_RESULT;
- FIRST_MOD_RESULT(ServerInstance, OnAccessCheck, MOD_RESULT, (user,d,chan,AC_DEOP));
-
- if (MOD_RESULT == MOD_RES_DENY)
- return "";
- if (MOD_RESULT == MOD_RES_PASSTHRU)
- {
- if ((status < OP_VALUE) && (!ServerInstance->ULine(user->server)) && (IS_LOCAL(user)))
- {
- user->WriteServ("482 %s %s :You are not a channel operator",user->nick.c_str(), chan->name.c_str());
- return "";
- }
- }
- }
-
- return d->nick;
- }
- return "";
+ return MODEACTION_ALLOW;
}
diff --git a/src/modes/cmode_v.cpp b/src/modes/cmode_v.cpp
index 031cefb7f..752dd509b 100644
--- a/src/modes/cmode_v.cpp
+++ b/src/modes/cmode_v.cpp
@@ -72,80 +72,5 @@ void ModeChannelVoice::RemoveMode(User*, irc::modestacker* stack)
ModeAction ModeChannelVoice::OnModeChange(User* source, User*, Channel* channel, std::string &parameter, bool adding)
{
- int status = channel->GetPrefixValue(source);
-
- /* Call the correct method depending on wether we're adding or removing the mode */
- if (adding)
- {
- parameter = this->AddVoice(source, parameter.c_str(), channel, status);
- }
- else
- {
- parameter = this->DelVoice(source, parameter.c_str(), channel, status);
- }
- /* If the method above 'ate' the parameter by reducing it to an empty string, then
- * it won't matter wether we return ALLOW or DENY here, as an empty string overrides
- * the return value and is always MODEACTION_DENY if the mode is supposed to have
- * a parameter.
- */
- if (parameter.length())
- return MODEACTION_ALLOW;
- else
- return MODEACTION_DENY;
-}
-
-std::string ModeChannelVoice::AddVoice(User *user,const char* dest,Channel *chan,int status)
-{
- User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
-
- if (d)
- {
- if (IS_LOCAL(user))
- {
- ModResult MOD_RESULT;
- FIRST_MOD_RESULT(ServerInstance, OnAccessCheck, MOD_RESULT, (user,d,chan,AC_VOICE));
-
- if (MOD_RESULT == MOD_RES_DENY)
- return "";
- if (MOD_RESULT == MOD_RES_PASSTHRU)
- {
- if ((status < HALFOP_VALUE) && (!ServerInstance->ULine(user->server)))
- {
- user->WriteServ("482 %s %s :You're not a channel (half)operator",user->nick.c_str(), chan->name.c_str());
- return "";
- }
- }
- }
-
- return d->nick;
- }
- return "";
-}
-
-std::string ModeChannelVoice::DelVoice(User *user,const char *dest,Channel *chan,int status)
-{
- User *d = ServerInstance->Modes->SanityChecks(user,dest,chan,status);
-
- if (d)
- {
- if (IS_LOCAL(user))
- {
- ModResult MOD_RESULT;
- FIRST_MOD_RESULT(ServerInstance, OnAccessCheck, MOD_RESULT, (user,d,chan,AC_DEVOICE));
-
- if (MOD_RESULT == MOD_RES_DENY)
- return "";
- if (MOD_RESULT == MOD_RES_PASSTHRU)
- {
- if ((status < HALFOP_VALUE) && (!ServerInstance->ULine(user->server)))
- {
- user->WriteServ("482 %s %s :You are not a channel (half)operator",user->nick.c_str(), chan->name.c_str());
- return "";
- }
- }
- }
-
- return d->nick;
- }
- return "";
+ return MODEACTION_ALLOW;
}
diff --git a/src/modules.cpp b/src/modules.cpp
index 4a8a13a48..979c42119 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -129,7 +129,7 @@ ModResult Module::OnUserPreMessage(User*, void*, int, std::string&, char, CUList
ModResult Module::OnUserPreNotice(User*, void*, int, std::string&, char, CUList&) { return MOD_RES_PASSTHRU; }
ModResult Module::OnUserPreNick(User*, const std::string&) { return MOD_RES_PASSTHRU; }
void Module::OnUserPostNick(User*, const std::string&) { }
-ModResult Module::OnAccessCheck(User*, User*, Channel*, int) { return MOD_RES_PASSTHRU; }
+ModResult Module::OnPreMode(User*, User*, Channel*, const std::vector<std::string>&) { return MOD_RES_PASSTHRU; }
void Module::On005Numeric(std::string&) { }
ModResult Module::OnKill(User*, User*, const std::string&) { return MOD_RES_PASSTHRU; }
void Module::OnLoadModule(Module*, const std::string&) { }
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);
}
};