]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_restrictchans.cpp
Converted to 'Implements' system
[user/henk/code/inspircd.git] / src / modules / m_restrictchans.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 using namespace std;
18
19 #include <stdio.h>
20 #include "users.h"
21 #include "channels.h"
22 #include "modules.h"
23 #include "helperfuncs.h"
24
25 /* $ModDesc: Only opers may create new channels if this module is loaded */
26
27 Server *Srv;
28          
29 class ModuleRestrictChans : public Module
30 {
31  public:
32         ModuleRestrictChans(Server* Me)
33                 : Module::Module(Me)
34         {
35                 Srv = Me;
36         }
37
38         void Implements(char* List)
39         {
40                 List[I_OnUserPreJoin] = 1;
41         }
42         
43         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
44         {
45                 // user is not an oper
46                 if (!strchr(user->modes,'o'))
47                 {
48                         // channel does not yet exist (record is null, about to be created IF we were to allow it)
49                         if (!chan)
50                         {
51                                 WriteServ(user->fd,"530 %s %s :Only IRC operators may create new channels",user->nick,cname,cname);
52                                 return 1;
53                         }
54                 }
55                 return 0;
56         }
57         
58         virtual ~ModuleRestrictChans()
59         {
60         }
61         
62         virtual Version GetVersion()
63         {
64                 return Version(1,0,0,1,VF_VENDOR);
65         }
66 };
67
68
69 class ModuleRestrictChansFactory : public ModuleFactory
70 {
71  public:
72         ModuleRestrictChansFactory()
73         {
74         }
75         
76         ~ModuleRestrictChansFactory()
77         {
78         }
79         
80         virtual Module * CreateModule(Server* Me)
81         {
82                 return new ModuleRestrictChans(Me);
83         }
84         
85 };
86
87
88 extern "C" void * init_module( void )
89 {
90         return new ModuleRestrictChansFactory;
91 }
92