]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_restrictchans.cpp
Changed behaviour of module API to pass Server* to the constructor, rather than have...
[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         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
39         {
40                 // user is not an oper
41                 if (!strchr(user->modes,'o'))
42                 {
43                         // channel does not yet exist (record is null, about to be created IF we were to allow it)
44                         if (!chan)
45                         {
46                                 WriteServ(user->fd,"530 %s %s :Only IRC operators may create new channels",user->nick,cname,cname);
47                                 return 1;
48                         }
49                 }
50                 return 0;
51         }
52         
53         virtual ~ModuleRestrictChans()
54         {
55         }
56         
57         virtual Version GetVersion()
58         {
59                 return Version(1,0,0,1,VF_VENDOR);
60         }
61 };
62
63
64 class ModuleRestrictChansFactory : public ModuleFactory
65 {
66  public:
67         ModuleRestrictChansFactory()
68         {
69         }
70         
71         ~ModuleRestrictChansFactory()
72         {
73         }
74         
75         virtual Module * CreateModule(Server* Me)
76         {
77                 return new ModuleRestrictChans(Me);
78         }
79         
80 };
81
82
83 extern "C" void * init_module( void )
84 {
85         return new ModuleRestrictChansFactory;
86 }
87