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