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

ModuleRestrictChans Class Reference

Inheritance diagram for ModuleRestrictChans:

Inheritance graph
[legend]
Collaboration diagram for ModuleRestrictChans:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ModuleRestrictChans (InspIRCd *Me)
virtual void OnRehash (userrec *user, const std::string &parameter)
 Called on rehash.
void Implements (char *List)
 The Implements function specifies which methods a module should receive events for.
virtual int OnUserPreJoin (userrec *user, chanrec *chan, const char *cname, std::string &privs)
 Called whenever a user is about to join a channel, before any processing is done.
virtual ~ModuleRestrictChans ()
virtual Version GetVersion ()
 Returns the version number of a Module.

Private Member Functions

void ReadConfig ()

Private Attributes

std::map< irc::string, int > allowchans

Detailed Description

Definition at line 21 of file m_restrictchans.cpp.


Constructor & Destructor Documentation

ModuleRestrictChans::ModuleRestrictChans InspIRCd Me  )  [inline]
 

Definition at line 42 of file m_restrictchans.cpp.

References ReadConfig().

00043                 : Module(Me)
00044         {
00045                 
00046                 ReadConfig();
00047         }

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

Definition at line 79 of file m_restrictchans.cpp.

00080         {
00081         }


Member Function Documentation

virtual Version ModuleRestrictChans::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 83 of file m_restrictchans.cpp.

References API_VERSION, and VF_VENDOR.

00084         {
00085                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
00086         }

void ModuleRestrictChans::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 54 of file m_restrictchans.cpp.

References I_OnRehash, and I_OnUserPreJoin.

00055         {
00056                 List[I_OnUserPreJoin] = List[I_OnRehash] = 1;
00057         }

virtual void ModuleRestrictChans::OnRehash userrec user,
const std::string parameter
[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 49 of file m_restrictchans.cpp.

References ReadConfig().

00050         {
00051                 ReadConfig();
00052         }

virtual int ModuleRestrictChans::OnUserPreJoin userrec user,
chanrec chan,
const char *  cname,
std::string privs
[inline, virtual]
 

Called whenever a user is about to join a channel, before any processing is done.

Returning a value of 1 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 mimic +b, +k, +l etc. Returning -1 from this function forces the join to be allowed, bypassing restrictions such as banlists, invite, keys etc.

IMPORTANT NOTE!

If the user joins a NEW channel which does not exist yet, OnUserPreJoin will be called BEFORE the channel record is created. This will cause chanrec* chan to be NULL. There is very little you can do in form of processing on the actual channel record at this point, however the channel NAME will still be passed in char* cname, so that you could for example implement a channel blacklist or whitelist, etc.

Parameters:
user The user joining the channel
chan If the channel is a new channel, this will be NULL, otherwise it will be a pointer to the channel being joined
cname The channel name being joined. For new channels this is valid where chan is not.
privs A string containing the users privilages when joining the channel. For new channels this will contain "@". You may alter this string to alter the user's modes on the channel.
Returns:
1 To prevent the join, 0 to allow it.

Reimplemented from Module.

Definition at line 59 of file m_restrictchans.cpp.

References allowchans, IS_LOCAL, IS_OPER, userrec::nick, and userrec::WriteServ().

00060         {
00061                 irc::string x = cname;
00062 
00063                 if (!IS_LOCAL(user))
00064                         return 0;
00065 
00066                 // user is not an oper and its not in the allow list
00067                 if ((!IS_OPER(user)) && (allowchans.find(x) == allowchans.end()))
00068                 {
00069                         // channel does not yet exist (record is null, about to be created IF we were to allow it)
00070                         if (!chan)
00071                         {
00072                                 user->WriteServ("530 %s %s :Only IRC operators may create new channels",user->nick,cname,cname);
00073                                 return 1;
00074                         }
00075                 }
00076                 return 0;
00077         }

void ModuleRestrictChans::ReadConfig  )  [inline, private]
 

Definition at line 27 of file m_restrictchans.cpp.

References allowchans, DELETE(), ConfigReader::ReadValue(), and Module::ServerInstance.

Referenced by ModuleRestrictChans(), and OnRehash().

00028         {
00029                 ConfigReader* MyConf = new ConfigReader(ServerInstance);
00030                 allowchans.clear();
00031                 for (int i = 0; i < MyConf->Enumerate("allowchannel"); i++)
00032                 {
00033                         std::string txt;
00034                         txt = MyConf->ReadValue("allowchannel", "name", i);
00035                         irc::string channel = txt.c_str();
00036                         allowchans[channel] = 1;
00037                 }
00038                 DELETE(MyConf);
00039         }


Member Data Documentation

std::map<irc::string,int> ModuleRestrictChans::allowchans [private]
 

Definition at line 25 of file m_restrictchans.cpp.

Referenced by OnUserPreJoin(), and ReadConfig().


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