]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operchans.cpp
Just to mess with om's head, remove helperfuncs.h from everywhere
[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                 ServerInstance->Modes->InsertMode(output,"O",4);
80         }
81         
82         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
83         {
84                 if (!*user->oper)
85                 {
86                         if (chan)
87                         {
88                                 if (chan->IsModeSet('O'))
89                                 {
90                                         user->WriteServ("520 %s %s :Only IRC operators may join the channel %s (+O is set)",user->nick, chan->name,chan->name);
91                                         return 1;
92                                 }
93                         }
94                 }
95                 return 0;
96         }
97         
98         virtual ~ModuleOperChans()
99         {
100                 DELETE(oc);
101         }
102         
103         virtual Version GetVersion()
104         {
105                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
106         }
107 };
108
109
110 class ModuleOperChansFactory : public ModuleFactory
111 {
112  public:
113         ModuleOperChansFactory()
114         {
115         }
116         
117         ~ModuleOperChansFactory()
118         {
119         }
120         
121         virtual Module * CreateModule(InspIRCd* Me)
122         {
123                 return new ModuleOperChans(Me);
124         }
125         
126 };
127
128
129 extern "C" void * init_module( void )
130 {
131         return new ModuleOperChansFactory;
132 }
133