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, such as m_chanfilter and m_muteban.
  • Loading branch information
B00mX0r committed Nov 27, 2017
1 parent fa95bb4 commit 55452ab
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 @@ -29,6 +29,7 @@

class ModuleOverride : public Module
{
bool active;
bool RequireKey;
bool NoisyOverride;
ChanModeReference topiclock;
Expand Down Expand Up @@ -65,7 +66,8 @@ class ModuleOverride : public Module

public:
ModuleOverride()
: topiclock(this, "topiclock")
: active(false)
, topiclock(this, "topiclock")
, inviteonly(this, "inviteonly")
, key(this, "key")
, limit(this, "limit")
Expand Down Expand Up @@ -199,6 +201,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 55452ab

Please sign in to comment.