]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operchans.cpp
Windows support. Tested and working to compile on freebsd and linux. Next step is...
[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(Me)
57         {
58                                 
59                 oc = new OperChans(ServerInstance);
60                 if (!ServerInstance->AddMode(oc, 'O'))
61                         throw ModuleException("Could not add new modes!");
62         }
63
64         void Implements(char* List)
65         {
66                 List[I_OnUserPreJoin] = 1;
67         }
68
69         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname, std::string &privs)
70         {
71                 if (!IS_OPER(user))
72                 {
73                         if (chan)
74                         {
75                                 if (chan->IsModeSet('O'))
76                                 {
77                                         user->WriteServ("520 %s %s :Only IRC operators may join the channel %s (+O is set)",user->nick, chan->name,chan->name);
78                                         return 1;
79                                 }
80                         }
81                 }
82                 return 0;
83         }
84         
85         virtual ~ModuleOperChans()
86         {
87                 ServerInstance->Modes->DelMode(oc);
88                 DELETE(oc);
89         }
90         
91         virtual Version GetVersion()
92         {
93                 return Version(1,1,0,0,VF_VENDOR|VF_COMMON,API_VERSION);
94         }
95 };
96
97
98 class ModuleOperChansFactory : public ModuleFactory
99 {
100  public:
101         ModuleOperChansFactory()
102         {
103         }
104         
105         ~ModuleOperChansFactory()
106         {
107         }
108         
109         virtual Module * CreateModule(InspIRCd* Me)
110         {
111                 return new ModuleOperChans(Me);
112         }
113         
114 };
115
116
117 extern "C" DllExport void * init_module( void )
118 {
119         return new ModuleOperChansFactory;
120 }
121