Skip to content

Commit

Permalink
Add m_insp_joinpartspam - First release.
Browse files Browse the repository at this point in the history
Implement better support for the InspIRCd 2.0 Extras
m_joinpartspam. Verify cycle, duration, and block time
parameters; and disallow channel redirects when using
ChanServ MODE for this custom mode.
  • Loading branch information
genius3000 committed Mar 8, 2019
1 parent 4a7724b commit 8746f7c
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ To send a notice (via email and/or memo) to a user that their registered nicknam
channel is soon to expire and/or expired. Fully configurable with what to send for and
how to send the notices, when to send the pre-expiry notices, and the messages sent.

### m_insp_joinpartspam
Adds (almost) proper support for the InspIRCd 2.0 Extras module m_joinpartspam. Use
this module to ensure the mode is not abusable through ChanServ MODE. Channel redirects
with this mode are disallowed here, as we can't verify the parameter.
Requires a restart to load, can be reloaded live though.

### [m_xlinetoakill](https://modules.anope.org/index.php?page=view&id=285 "View module on the Anope Module Site")
Syncs X-Lines (G, Z, R) from the uplink IRCd to the AKILL list. Works on server sync
and as X-Lines are added or removed. Requires OperServ, AKILL, and the InspIRCd 2.0
Expand Down
104 changes: 104 additions & 0 deletions m_insp_joinpartspam.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Support for InspIRCd 2.0 Extras m_joinpartspam.
*
* (C) 2019 - Matt Schatz (genius3000@g3k.solutions)
* Please refer to the GPL License in use by Anope at:
* https://github.com/anope/anope/blob/master/docs/COPYING
*
* Provides the required logic for the mode to be mostly
* functional with ChanServ MODE but not abusable.
*
* Configuration to put into your modules config:
module { name = "m_insp_joinpartspam" }
*
*/

#include "module.h"


static Module *me;

class ChannelModeJoinPartSpam : public ChannelModeParam
{
bool ParseCycles(sepstream &stream) const
{
Anope::string strcycles;
if (!stream.GetToken(strcycles))
return false;

int result = convertTo<int>(strcycles);
if (result < 2 || result > 20)
return false;

return true;
}

bool ParseSeconds(sepstream &stream) const
{
Anope::string strseconds;
if (!stream.GetToken(strseconds))
return false;

int result = convertTo<int>(strseconds);
if (result < 1 || result > 43200)
return false;

return true;
}

public:
ChannelModeJoinPartSpam(const Anope::string &modename, const char modechar) : ChannelModeParam(modename, modechar, true) { }

bool IsValid(Anope::string &value) const anope_override
{
sepstream stream(value, ':');

if (!ParseCycles(stream))
return false;
// This checks duration first then block time.
if (!ParseSeconds(stream) || !ParseSeconds(stream))
return false;
// Disallow any redirect from here, we can't verify the parameter.
if (!stream.StreamEnd())
return false;

return true;
}
};

class InspJoinPartSpam : public Module
{
const Anope::string modename;
const char modechar;

public:
InspJoinPartSpam(const Anope::string &modname, const Anope::string &creator)
: Module(modname, creator, THIRD)
, modename("JOINPARTSPAM")
, modechar('x')
{
if (Anope::VersionMajor() != 2 || Anope::VersionMinor() != 0)
throw ModuleException("Requires version 2.0.x of Anope.");

if (!ModuleManager::FindModule("inspircd20"))
throw ModuleException("This module only works with the InspIRCd 2.0 protocol.");

ChannelMode *cm = ModeManager::FindChannelModeByChar(modechar);
if (cm)
throw ModuleException("A channel mode with character '" + Anope::string(modechar) + "' already exists.");

this->SetAuthor("genius3000");
this->SetVersion("1.0.0");
me = this;
ModeManager::AddChannelMode(new ChannelModeJoinPartSpam(modename, modechar));
}

~InspJoinPartSpam()
{
ChannelMode *cm = ModeManager::FindChannelModeByChar(modechar);
if (cm)
ModeManager::RemoveChannelMode(cm);
}
};

MODULE_INIT(InspJoinPartSpam)

0 comments on commit 8746f7c

Please sign in to comment.