mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-09 18:49:03 -04:00
Added m_censor.cpp mode +G module
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@822 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
parent
da8fe330c2
commit
b513b12594
12
docs/censor.conf.example
Normal file
12
docs/censor.conf.example
Normal file
@ -0,0 +1,12 @@
|
||||
# Configuration file for m_censor.so (1.0.0.0)
|
||||
# C.J.Edwards May 2004.
|
||||
#
|
||||
|
||||
# The tags for this module are formatted as follows:
|
||||
#
|
||||
# <badword text="simple word"
|
||||
# replace="text to replace with">
|
||||
|
||||
<badword text="shit" replace="poo">
|
||||
<badword pattern="fuck" reason="(censored)">
|
||||
|
@ -1,7 +1,7 @@
|
||||
[Project]
|
||||
FileName=InspIRCd.dev
|
||||
Name=InspIRCd - The Inspire Internet Relay Chat Daemon
|
||||
UnitCount=61
|
||||
UnitCount=62
|
||||
Type=1
|
||||
Ver=1
|
||||
ObjFiles=
|
||||
@ -655,3 +655,13 @@ Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit62]
|
||||
FileName=modules\m_censor.cpp
|
||||
CompileCpp=1
|
||||
Folder=Modules/Server
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
[Editors]
|
||||
Focused=43
|
||||
Focused=-1
|
||||
Order=2,4,6,3,7,25,5,24,39,42,43,1,46,0,49,-1
|
||||
|
||||
[Editor_0]
|
||||
@ -165,9 +165,9 @@ LeftChar=1
|
||||
[Editor_20]
|
||||
Open=1
|
||||
Top=0
|
||||
CursorCol=14
|
||||
CursorRow=276
|
||||
TopLine=245
|
||||
CursorCol=1
|
||||
CursorRow=321
|
||||
TopLine=263
|
||||
LeftChar=1
|
||||
|
||||
[Editor_21]
|
||||
@ -216,10 +216,10 @@ CursorRow=16
|
||||
TopLine=1
|
||||
LeftChar=1
|
||||
[Editor_27]
|
||||
Open=0
|
||||
Open=1
|
||||
Top=0
|
||||
CursorCol=1
|
||||
CursorRow=16
|
||||
CursorCol=44
|
||||
CursorRow=34
|
||||
TopLine=1
|
||||
LeftChar=1
|
||||
[Editor_28]
|
||||
@ -253,9 +253,9 @@ LeftChar=1
|
||||
[Editor_32]
|
||||
Open=1
|
||||
Top=0
|
||||
CursorCol=86
|
||||
CursorRow=65
|
||||
TopLine=18
|
||||
CursorCol=28
|
||||
CursorRow=120
|
||||
TopLine=75
|
||||
LeftChar=1
|
||||
[Editor_33]
|
||||
Open=0
|
||||
@ -329,10 +329,10 @@ TopLine=256
|
||||
LeftChar=1
|
||||
[Editor_43]
|
||||
Open=1
|
||||
Top=1
|
||||
CursorCol=32
|
||||
CursorRow=601
|
||||
TopLine=552
|
||||
Top=0
|
||||
CursorCol=26
|
||||
CursorRow=683
|
||||
TopLine=651
|
||||
LeftChar=1
|
||||
[Editor_44]
|
||||
Open=0
|
||||
@ -363,11 +363,11 @@ CursorRow=88
|
||||
TopLine=69
|
||||
LeftChar=1
|
||||
[Editor_48]
|
||||
Open=0
|
||||
Open=1
|
||||
Top=0
|
||||
CursorCol=1
|
||||
CursorRow=16
|
||||
TopLine=1
|
||||
TopLine=112
|
||||
LeftChar=1
|
||||
[Editor_49]
|
||||
Open=1
|
||||
@ -453,3 +453,10 @@ CursorCol=22
|
||||
CursorRow=50
|
||||
TopLine=12
|
||||
LeftChar=1
|
||||
[Editor_61]
|
||||
Open=1
|
||||
Top=1
|
||||
CursorCol=19
|
||||
CursorRow=179
|
||||
TopLine=135
|
||||
LeftChar=1
|
||||
|
200
src/modules/m_censor.cpp
Normal file
200
src/modules/m_censor.cpp
Normal file
@ -0,0 +1,200 @@
|
||||
/* +------------------------------------+
|
||||
* | Inspire Internet Relay Chat Daemon |
|
||||
* +------------------------------------+
|
||||
*
|
||||
* Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
|
||||
* E-mail:
|
||||
* <brain@chatspike.net>
|
||||
* <Craig@chatspike.net>
|
||||
*
|
||||
* Written by Craig Edwards, Craig McLure, and others.
|
||||
* This program is free but copyrighted software; see
|
||||
* the file COPYING for details.
|
||||
*
|
||||
* ---------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include "users.h"
|
||||
#include "channels.h"
|
||||
#include "modules.h"
|
||||
|
||||
/* $ModDesc: Provides user and channel +G mode */
|
||||
|
||||
class ModuleCensor : public Module
|
||||
{
|
||||
Server *Srv;
|
||||
ConfigReader *Conf, *MyConf;
|
||||
|
||||
public:
|
||||
ModuleCensor()
|
||||
{
|
||||
// read the configuration file on startup.
|
||||
// it is perfectly valid to set <censor file> to the value of the
|
||||
// main config file, then append your <badword> tags to the bottom
|
||||
// of the main config... but rather messy. That's why the capability
|
||||
// of using a seperate config file is provided.
|
||||
Srv = new Server;
|
||||
Conf = new ConfigReader;
|
||||
std::string Censorfile = Conf->ReadValue("censor","file",0);
|
||||
MyConf = new ConfigReader(Censorfile);
|
||||
if ((Censorfile == "") || (!MyConf->Verify()))
|
||||
{
|
||||
printf("Error, could not find <censor file=\"\"> definition in your config file!");
|
||||
exit(0);
|
||||
}
|
||||
Srv->Log(DEFAULT,std::string("m_censor: read configuration from ")+Censorfile);
|
||||
Srv->AddExtendedMode('G',MT_CHANNEL,false,0,0);
|
||||
Srv->AddExtendedMode('G',MT_CLIENT,false,0,0);
|
||||
}
|
||||
|
||||
virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
|
||||
{
|
||||
// check if this is our mode character...
|
||||
if (modechar == 'G')
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~ModuleCensor()
|
||||
{
|
||||
delete Srv;
|
||||
delete MyConf;
|
||||
delete Conf;
|
||||
}
|
||||
|
||||
virtual void ReplaceLine(std::string &text,std::string pattern, std::string replace)
|
||||
{
|
||||
while (strstr(text.c_str(),pattern.c_str()))
|
||||
{
|
||||
int pos = text.find(pattern);
|
||||
text.erase(pos,pattern.length());
|
||||
text.insert(pos,replace);
|
||||
}
|
||||
}
|
||||
|
||||
// format of a config entry is <badword text="shit" replace="poo">
|
||||
|
||||
virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text)
|
||||
{
|
||||
bool active = false;
|
||||
for (int index = 0; index < MyConf->Enumerate("badword"); index++)
|
||||
{
|
||||
std::string pattern = MyConf->ReadValue("badword","text",index);
|
||||
if (strstr(text.c_str(),pattern.c_str()))
|
||||
{
|
||||
std::string replace = MyConf->ReadValue("badword","replace",index);
|
||||
|
||||
if (target_type == TYPE_USER)
|
||||
{
|
||||
userrec* t = (userrec*)dest;
|
||||
active = (strchr(t->modes,'G') > 0);
|
||||
}
|
||||
else if (target_type == TYPE_CHANNEL)
|
||||
{
|
||||
chanrec* t = (chanrec*)dest;
|
||||
active = (t->IsCustomModeSet('G'));
|
||||
}
|
||||
|
||||
if (active)
|
||||
{
|
||||
this->ReplaceLine(text,pattern,replace);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
|
||||
{
|
||||
bool active = false;
|
||||
for (int index = 0; index < MyConf->Enumerate("badword"); index++)
|
||||
{
|
||||
std::string pattern = MyConf->ReadValue("badword","text",index);
|
||||
if (strstr(text.c_str(),pattern.c_str()))
|
||||
{
|
||||
std::string replace = MyConf->ReadValue("badword","replace",index);
|
||||
|
||||
if (target_type == TYPE_USER)
|
||||
{
|
||||
userrec* t = (userrec*)dest;
|
||||
active = (strchr(t->modes,'G') > 0);
|
||||
}
|
||||
else if (target_type == TYPE_CHANNEL)
|
||||
{
|
||||
chanrec* t = (chanrec*)dest;
|
||||
active = (t->IsCustomModeSet('G'));
|
||||
}
|
||||
|
||||
if (active)
|
||||
{
|
||||
this->ReplaceLine(text,pattern,replace);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual void OnRehash()
|
||||
{
|
||||
// reload our config file on rehash - we must destroy and re-allocate the classes
|
||||
// to call the constructor again and re-read our data.
|
||||
delete Conf;
|
||||
delete MyConf;
|
||||
Conf = new ConfigReader;
|
||||
std::string Censorfile = Conf->ReadValue("censor","file",0);
|
||||
// this automatically re-reads the configuration file into the class
|
||||
MyConf = new ConfigReader(Censorfile);
|
||||
if ((Censorfile == "") || (!MyConf->Verify()))
|
||||
{
|
||||
// bail if the user forgot to create a config file
|
||||
printf("Error, could not find <censor file=\"\"> definition in your config file!");
|
||||
exit(0);
|
||||
}
|
||||
Srv->Log(DEFAULT,std::string("m_censor: read configuration from ")+Censorfile);
|
||||
}
|
||||
|
||||
virtual Version GetVersion()
|
||||
{
|
||||
// This is version 2 because version 1.x is the unreleased unrealircd module
|
||||
return Version(1,0,0,0);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// stuff down here is the module-factory stuff. For basic modules you can ignore this.
|
||||
|
||||
class ModuleCensorFactory : public ModuleFactory
|
||||
{
|
||||
public:
|
||||
ModuleCensorFactory()
|
||||
{
|
||||
}
|
||||
|
||||
~ModuleCensorFactory()
|
||||
{
|
||||
}
|
||||
|
||||
virtual Module * CreateModule()
|
||||
{
|
||||
return new ModuleCensor;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
extern "C" void * init_module( void )
|
||||
{
|
||||
return new ModuleCensorFactory;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user