Skip to content

Commit

Permalink
Add CHANMSG oper override
Browse files Browse the repository at this point in the history
CHANMSG oper override overrides channel privmsg restrictions from modules, such as m_chanfilter and m_muteban.
  • Loading branch information
B00mX0r committed Dec 12, 2017
1 parent c4955b7 commit 077dfa6
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion src/modules/m_override.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Override : public SimpleUserModeHandler

class ModuleOverride : public Module
{
bool active;
bool RequireKey;
bool NoisyOverride;
bool UmodeEnabled;
Expand Down Expand Up @@ -78,7 +79,8 @@ class ModuleOverride : public Module

public:
ModuleOverride()
: UmodeEnabled(false)
: active(false)
, UmodeEnabled(false)
, ou(this)
, topiclock(this, "topiclock")
, inviteonly(this, "inviteonly")
Expand Down Expand Up @@ -218,6 +220,47 @@ class ModuleOverride : public Module
return MOD_RES_PASSTHRU;
}

// Begin override for CHANMSG (bypassing external modules' privmsg restirctions such as muteban and chanfilter)
ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
{
if (active)
return MOD_RES_PASSTHRU;

ModResult MOD_RESULT;

if (target_type == TYPE_CHANNEL && user->IsOper() && CanOverride(user, "CHANMSG"))
{
active = true;
FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user, dest, target_type, text, status, exempt_list, msgtype));
active = false;

// If there is something stopping us from sending our privmsg to the channel then we override
if (MOD_RESULT == MOD_RES_DENY)
{
Channel* channel = static_cast<Channel*>(dest);
ServerInstance->SNO->WriteGlobalSno('v',user->nick+" used oper override to send a message on "+channel->name);
return MOD_RES_ALLOW;
}
// We already ran FIRST_MOD_RESULT, so if there was no MOD_RES_DENY then they were all passthrus, so there's no point in re-running it anyway
return MOD_RES_ALLOW;
}
return MOD_RES_PASSTHRU;
}

// For preventing "cannot send message to channel" errors during CHANMSG override
ModResult OnNumeric(User* user, const Numeric::Numeric& numeric) CXX11_OVERRIDE
{
if (!active || numeric.GetNumeric() != ERR_CANNOTSENDTOCHAN)
return MOD_RES_PASSTHRU;

return MOD_RES_DENY;
}

void Prioritize() CXX11_OVERRIDE
{
ServerInstance->Modules->SetPriority(this, I_OnUserPreMessage, PRIORITY_FIRST);
}

Version GetVersion() CXX11_OVERRIDE
{
return Version("Provides support for allowing opers to override certain things",VF_VENDOR);
Expand Down

0 comments on commit 077dfa6

Please sign in to comment.