Merge pull request #133 from nenolod/feature/mlock-2.1

serverside MLOCK for inspircd 2.1
This commit is contained in:
Robin Burchell 2012-05-23 03:18:02 -07:00
commit fa73de4f90
2 changed files with 82 additions and 0 deletions

View File

@ -999,6 +999,12 @@
# Msg flood module: Adds message/notice flood protection (+f)
#<module name="m_messageflood.so">
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
# MLOCK module: Adds support for server-side enforcement of services
# side MLOCKs. Basically, this module suppresses any mode change that
# would likely be immediately bounced by services.
#<module name="m_mlock.so">
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
# MySQL module: Allows other SQL modules to access MySQL databases
# through a unified API.

76
src/modules/m_mlock.cpp Normal file
View File

@ -0,0 +1,76 @@
/*
* InspIRCd -- Internet Relay Chat Daemon
*
* Copyright (C) 2012 William Pitcock <nenolod@dereferenced.org>
*
* This file is part of InspIRCd. InspIRCd is free software: you can
* redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "inspircd.h"
class ModuleMLock : public Module
{
private:
StringExtItem mlock;
public:
ModuleMLock() : mlock(EXTENSIBLE_CHANNEL, "mlock", this) {};
void init()
{
ServerInstance->Modules->Attach(I_OnPreMode, this);
}
Version GetVersion()
{
return Version("Implements the ability to have server-side MLOCK enforcement.", VF_VENDOR);
}
void Prioritize()
{
ServerInstance->Modules->SetPriority(this, I_OnPreMode, PRIORITY_FIRST);
}
ModResult OnPreMode(User* source, Extensible *e, irc::modestacker &ms)
{
Channel *ch = dynamic_cast<Channel *>(e);
if (!ch)
return MOD_RES_PASSTHRU;
if (!IS_LOCAL(source))
return MOD_RES_PASSTHRU;
std::string *mlock_str = mlock.get(e);
if (!mlock_str || mlock_str->empty())
return MOD_RES_PASSTHRU;
for(std::vector<irc::modechange>::iterator iter = ms.sequence.begin(); iter != ms.sequence.end(); ++iter)
{
ModeHandler *mh = ServerInstance->Modes->FindMode(iter->mode);
char modechar = mh->GetModeChar();
if (mlock_str->find(modechar))
{
source->WriteNumeric(742, "%s %c %s :MODE cannot be set due to channel having an active MLOCK restriction policy",
ch->name.c_str(), modechar, mlock_str->c_str());
return MOD_RES_DENY;
}
}
return MOD_RES_PASSTHRU;
}
};
MODULE_INIT(ModuleMLock)