]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operchans.cpp
Remove global namespacing, makes modules compile FASTAH. Also massive update on heade...
[user/henk/code/inspircd.git] / src / modules / m_operchans.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "users.h"
15 #include "channels.h"
16 #include "modules.h"
17 #include "inspircd.h"
18
19 /* $ModDesc: Provides support for oper-only chans via the +O channel mode */
20
21 class OperChans : public ModeHandler
22 {
23  public:
24         /* This is an oper-only mode */
25         OperChans(InspIRCd* Instance) : ModeHandler(Instance, 'O', 0, 0, false, MODETYPE_CHANNEL, true) { }
26
27         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
28         {
29                 if (adding)
30                 {
31                         if (!channel->IsModeSet('O'))
32                         {
33                                 channel->SetMode('O',true);
34                                 return MODEACTION_ALLOW;
35                         }
36                 }
37                 else
38                 {
39                         if (channel->IsModeSet('O'))
40                         {
41                                 channel->SetMode('O',false);
42                                 return MODEACTION_ALLOW;
43                         }
44                 }
45
46                 return MODEACTION_DENY;
47         }
48 };
49
50 class ModuleOperChans : public Module
51 {
52         
53         OperChans* oc;
54  public:
55         ModuleOperChans(InspIRCd* Me)
56                 : Module::Module(Me)
57         {
58                                 
59                 oc = new OperChans(ServerInstance);
60                 ServerInstance->AddMode(oc, 'O');
61         }
62
63         void Implements(char* List)
64         {
65                 List[I_OnUserPreJoin] = 1;
66         }
67
68         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname, std::string &privs)
69         {
70                 if (!*user->oper)
71                 {
72                         if (chan)
73                         {
74                                 if (chan->IsModeSet('O'))
75                                 {
76                                         user->WriteServ("520 %s %s :Only IRC operators may join the channel %s (+O is set)",user->nick, chan->name,chan->name);
77                                         return 1;
78                                 }
79                         }
80                 }
81                 return 0;
82         }
83         
84         virtual ~ModuleOperChans()
85         {
86                 ServerInstance->Modes->DelMode(oc);
87                 DELETE(oc);
88         }
89         
90         virtual Version GetVersion()
91         {
92                 return Version(1,1,0,0,VF_VENDOR|VF_COMMON,API_VERSION);
93         }
94 };
95
96
97 class ModuleOperChansFactory : public ModuleFactory
98 {
99  public:
100         ModuleOperChansFactory()
101         {
102         }
103         
104         ~ModuleOperChansFactory()
105         {
106         }
107         
108         virtual Module * CreateModule(InspIRCd* Me)
109         {
110                 return new ModuleOperChans(Me);
111         }
112         
113 };
114
115
116 extern "C" void * init_module( void )
117 {
118         return new ModuleOperChansFactory;
119 }
120