]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operchans.cpp
Remove On005Numeric event from a ton of modules which no longer need it (as CHANMODES...
[user/henk/code/inspircd.git] / src / modules / m_operchans.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 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 "users.h"
20 #include "channels.h"
21 #include "modules.h"
22 #include "inspircd.h"
23
24 /* $ModDesc: Provides support for oper-only chans via the +O channel mode */
25
26 class OperChans : public ModeHandler
27 {
28  public:
29         /* This is an oper-only mode */
30         OperChans(InspIRCd* Instance) : ModeHandler(Instance, 'O', 0, 0, false, MODETYPE_CHANNEL, true) { }
31
32         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
33         {
34                 if (adding)
35                 {
36                         if (!channel->IsModeSet('O'))
37                         {
38                                 channel->SetMode('O',true);
39                                 return MODEACTION_ALLOW;
40                         }
41                 }
42                 else
43                 {
44                         if (channel->IsModeSet('O'))
45                         {
46                                 channel->SetMode('O',false);
47                                 return MODEACTION_ALLOW;
48                         }
49                 }
50
51                 return MODEACTION_DENY;
52         }
53 };
54
55 class ModuleOperChans : public Module
56 {
57         
58         OperChans* oc;
59  public:
60         ModuleOperChans(InspIRCd* Me)
61                 : Module::Module(Me)
62         {
63                                 
64                 oc = new OperChans(ServerInstance);
65                 ServerInstance->AddMode(oc, 'O');
66         }
67
68         void Implements(char* List)
69         {
70                 List[I_OnUserPreJoin] = 1;
71         }
72
73         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
74         {
75                 if (!*user->oper)
76                 {
77                         if (chan)
78                         {
79                                 if (chan->IsModeSet('O'))
80                                 {
81                                         user->WriteServ("520 %s %s :Only IRC operators may join the channel %s (+O is set)",user->nick, chan->name,chan->name);
82                                         return 1;
83                                 }
84                         }
85                 }
86                 return 0;
87         }
88         
89         virtual ~ModuleOperChans()
90         {
91                 DELETE(oc);
92         }
93         
94         virtual Version GetVersion()
95         {
96                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
97         }
98 };
99
100
101 class ModuleOperChansFactory : public ModuleFactory
102 {
103  public:
104         ModuleOperChansFactory()
105         {
106         }
107         
108         ~ModuleOperChansFactory()
109         {
110         }
111         
112         virtual Module * CreateModule(InspIRCd* Me)
113         {
114                 return new ModuleOperChans(Me);
115         }
116         
117 };
118
119
120 extern "C" void * init_module( void )
121 {
122         return new ModuleOperChansFactory;
123 }
124