The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download | Blog | Stats
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

ModuleBlockCAPS Class Reference

Inheritance diagram for ModuleBlockCAPS:

Inheritance graph
[legend]
Collaboration diagram for ModuleBlockCAPS:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ModuleBlockCAPS (InspIRCd *Me)
void Implements (char *List)
 The Implements function specifies which methods a module should receive events for.
virtual void OnRehash (userrec *user, const std::string &param)
 Called on rehash.
virtual int OnUserPreMessage (userrec *user, void *dest, int target_type, std::string &text, char status, CUList &exempt_list)
 Called whenever a user is about to PRIVMSG A user or a channel, before any processing is done.
virtual int OnUserPreNotice (userrec *user, void *dest, int target_type, std::string &text, char status, CUList &exempt_list)
 Called whenever a user is about to NOTICE A user or a channel, before any processing is done.
void ReadConf ()
virtual ~ModuleBlockCAPS ()
virtual Version GetVersion ()
 Returns the version number of a Module.

Private Attributes

BlockCapsbc
int percent
unsigned int minlen
char capsmap [256]

Detailed Description

Definition at line 53 of file m_blockcaps.cpp.


Constructor & Destructor Documentation

ModuleBlockCAPS::ModuleBlockCAPS InspIRCd Me  )  [inline]
 

Definition at line 61 of file m_blockcaps.cpp.

References InspIRCd::AddMode(), bc, OnRehash(), and Module::ServerInstance.

00061                                       : Module(Me)
00062         {
00063                 OnRehash(NULL,"");
00064                 bc = new BlockCaps(ServerInstance);
00065                 if (!ServerInstance->AddMode(bc, 'P'))
00066                 {
00067                         delete bc;
00068                         throw ModuleException("Could not add new modes!");
00069                 }
00070         }

virtual ModuleBlockCAPS::~ModuleBlockCAPS  )  [inline, virtual]
 

Definition at line 148 of file m_blockcaps.cpp.

References bc, DELETE(), ModeParser::DelMode(), InspIRCd::Modes, and Module::ServerInstance.

00149         {
00150                 ServerInstance->Modes->DelMode(bc);
00151                 DELETE(bc);
00152         }


Member Function Documentation

virtual Version ModuleBlockCAPS::GetVersion  )  [inline, virtual]
 

Returns the version number of a Module.

The method should return a Version object with its version information assigned via Version::Version

Reimplemented from Module.

Definition at line 154 of file m_blockcaps.cpp.

References API_VERSION, VF_COMMON, and VF_VENDOR.

00155         {
00156                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
00157         }

void ModuleBlockCAPS::Implements char *  List  )  [inline, virtual]
 

The Implements function specifies which methods a module should receive events for.

The char* parameter passed to this function contains a set of true or false values (1 or 0) which indicate wether each function is implemented. You must use the Iimplementation enum (documented elsewhere on this page) to mark functions as active. For example, to receive events for OnUserJoin():

Implements[I_OnUserJoin] = 1;

Parameters:
The implement list

Reimplemented from Module.

Definition at line 72 of file m_blockcaps.cpp.

References I_OnRehash, I_OnUserPreMessage, and I_OnUserPreNotice.

00073         {
00074                 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnRehash] = 1;
00075         }

virtual void ModuleBlockCAPS::OnRehash userrec user,
const std::string param
[inline, virtual]
 

Called on rehash.

This method is called prior to a /REHASH or when a SIGHUP is received from the operating system. You should use it to reload any files so that your module keeps in step with the rest of the application. If a parameter is given, the core has done nothing. The module receiving the event can decide if this parameter has any relevence to it.

Parameters:
user The user performing the rehash, if any -- if this is server initiated, the value of this variable will be NULL.
parameter The (optional) parameter given to REHASH from the user.

Reimplemented from Module.

Definition at line 77 of file m_blockcaps.cpp.

References ReadConf().

Referenced by ModuleBlockCAPS().

00078         {
00079                 ReadConf();
00080         }

virtual int ModuleBlockCAPS::OnUserPreMessage userrec user,
void *  dest,
int  target_type,
std::string text,
char  status,
CUList exempt_list
[inline, virtual]
 

Called whenever a user is about to PRIVMSG A user or a channel, before any processing is done.

Returning any nonzero value from this function stops the process immediately, causing no output to be sent to the user by the core. If you do this you must produce your own numerics, notices etc. This is useful for modules which may want to filter or redirect messages. target_type can be one of TYPE_USER or TYPE_CHANNEL. If the target_type value is a user, you must cast dest to a userrec* otherwise you must cast it to a chanrec*, this is the details of where the message is destined to be sent.

Parameters:
user The user sending the message
dest The target of the message (chanrec* or userrec*)
target_type The type of target (TYPE_USER or TYPE_CHANNEL)
text Changeable text being sent by the user
status The status being used, e.g. PRIVMSG #chan has status== '@', 0 to send to everyone.
exempt_list A list of users not to send to. For channel messages, this will usually contain just the sender. It will be ignored for private messages.
Returns:
1 to deny the message, 0 to allow it

Reimplemented from Module.

Definition at line 82 of file m_blockcaps.cpp.

References capsmap, IS_LOCAL, chanrec::IsModeSet(), minlen, chanrec::name, userrec::nick, percent, TYPE_CHANNEL, and userrec::WriteServ().

Referenced by OnUserPreNotice().

00083         {
00084                 if (target_type == TYPE_CHANNEL)
00085                 {
00086                         if ((!IS_LOCAL(user)) || (text.length() < minlen))
00087                                 return 0;
00088 
00089                         chanrec* c = (chanrec*)dest;
00090 
00091                         if (c->IsModeSet('P'))
00092                         {
00093                                 int caps = 0;
00094                                 char* actstr = "\1ACTION ";
00095                                 int act = 0;
00096 
00097                                 for (std::string::iterator i = text.begin(); i != text.end(); i++)
00098                                 {
00099                                         /* Smart fix for suggestion from Jobe, ignore CTCP ACTION (part of /ME) */
00100                                         if (*actstr && *i == *actstr++ && act != -1)
00101                                         {
00102                                                 act++;
00103                                                 continue;
00104                                         }
00105                                         else
00106                                                 act = -1;
00107 
00108                                         caps += capsmap[(unsigned char)*i];
00109                                 }
00110                                 if ( ((caps*100)/(int)text.length()) >= percent )
00111                                 {
00112                                         user->WriteServ( "404 %s %s :Your line cannot be more than %d%% capital letters if it is %d or more letters long", user->nick, c->name, percent, minlen);
00113                                         return 1;
00114                                 }
00115                         }
00116                 }
00117                 return 0;
00118         }

virtual int ModuleBlockCAPS::OnUserPreNotice userrec user,
void *  dest,
int  target_type,
std::string text,
char  status,
CUList exempt_list
[inline, virtual]
 

Called whenever a user is about to NOTICE A user or a channel, before any processing is done.

Returning any nonzero value from this function stops the process immediately, causing no output to be sent to the user by the core. If you do this you must produce your own numerics, notices etc. This is useful for modules which may want to filter or redirect messages. target_type can be one of TYPE_USER or TYPE_CHANNEL. If the target_type value is a user, you must cast dest to a userrec* otherwise you must cast it to a chanrec*, this is the details of where the message is destined to be sent. You may alter the message text as you wish before relinquishing control to the next module in the chain, and if no other modules block the text this altered form of the text will be sent out to the user and possibly to other servers.

Parameters:
user The user sending the message
dest The target of the message (chanrec* or userrec*)
target_type The type of target (TYPE_USER or TYPE_CHANNEL)
text Changeable text being sent by the user
status The status being used, e.g. PRIVMSG #chan has status== '@', 0 to send to everyone.
exempt_list A list of users not to send to. For channel notices, this will usually contain just the sender. It will be ignored for private notices.
Returns:
1 to deny the NOTICE, 0 to allow it

Reimplemented from Module.

Definition at line 120 of file m_blockcaps.cpp.

References OnUserPreMessage().

00121         {
00122                 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
00123         }

void ModuleBlockCAPS::ReadConf  )  [inline]
 

Definition at line 125 of file m_blockcaps.cpp.

References capsmap, Conf, DEFAULT, InspIRCd::Log(), MAXBUF, minlen, percent, ConfigReader::ReadInteger(), ConfigReader::ReadValue(), and Module::ServerInstance.

Referenced by OnRehash().

00126         {
00127                 ConfigReader Conf(ServerInstance);
00128                 percent = Conf.ReadInteger("blockcaps", "percent", "100", 0, true);
00129                 minlen = Conf.ReadInteger("blockcaps", "minlen", "1", 0, true);
00130                 std::string hmap = Conf.ReadValue("blockcaps", "capsmap", 0);
00131                 if (hmap.empty())
00132                         hmap = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
00133                 memset(&capsmap, 0, 255);
00134                 for (std::string::iterator n = hmap.begin(); n != hmap.end(); n++)
00135                         capsmap[(unsigned char)*n] = 1;
00136                 if (percent < 1 || percent > 100)
00137                 {
00138                         ServerInstance->Log(DEFAULT, "<blockcaps:percent> out of range, setting to default of 100.");
00139                         percent = 100;
00140                 }
00141                 if (minlen < 1 || minlen > MAXBUF-1)
00142                 {
00143                         ServerInstance->Log(DEFAULT, "<blockcaps:minlen> out of range, setting to default of 1.");
00144                         minlen = 1;
00145                 }
00146         }


Member Data Documentation

BlockCaps* ModuleBlockCAPS::bc [private]
 

Definition at line 55 of file m_blockcaps.cpp.

Referenced by ModuleBlockCAPS(), and ~ModuleBlockCAPS().

char ModuleBlockCAPS::capsmap[256] [private]
 

Definition at line 58 of file m_blockcaps.cpp.

Referenced by OnUserPreMessage(), and ReadConf().

unsigned int ModuleBlockCAPS::minlen [private]
 

Definition at line 57 of file m_blockcaps.cpp.

Referenced by OnUserPreMessage(), and ReadConf().

int ModuleBlockCAPS::percent [private]
 

Definition at line 56 of file m_blockcaps.cpp.

Referenced by OnUserPreMessage(), and ReadConf().


The documentation for this class was generated from the following file: