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