]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operchans.cpp
ba9a4d79fc4c1784ec51877c33cc057904da8542
[user/henk/code/inspircd.git] / src / modules / m_operchans.cpp
1 #include <stdio.h>
2
3 #include "users.h"
4 #include "channels.h"
5 #include "modules.h"
6
7 /* $ModDesc: Provides support for oper-only chans via the +O channel mode */
8
9 Server *Srv;
10          
11
12 class ModuleOperChans : public Module
13 {
14  public:
15         ModuleOperChans()
16         {
17                 Srv = new Server;
18
19                 // Add a mode +O for channels with no parameters                
20                 Srv->AddExtendedMode('O',MT_CHANNEL,false,0,0);
21         }
22         
23         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
24         {
25                 if ((modechar == 'O') && (type == MT_CHANNEL))
26                 {
27                         chanrec* chan = (chanrec*)target;
28                         
29                         if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,"")) || (strchr(user->modes,'o')))
30                         {
31                                 return 1;
32                         }
33                         else
34                         {
35                                 // eat the mode change, return an error
36                                 WriteServ(user->fd,"468 %s %s :Only servers and opers may set channel mode +O",user->nick, chan->name);
37                                 return 0;
38                         }
39         
40                         // must return 1 to handle the mode!
41                         return 1;
42                 }
43                 
44                 return 0;
45         }
46         
47         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
48         {
49                 if (!strchr(user->modes,'o'))
50                 {
51                         if (chan)
52                         {
53                                 if (chan->IsCustomModeSet('O'))
54                                 {
55                                         WriteServ(user->fd,"520 %s %s :Only IRC operators may join the channel %s (+O is set)",user->nick, chan->name,chan->name);
56                                         return 1;
57                                 }
58                         }
59                 }
60                 return 0;
61         }
62         
63         virtual ~ModuleOperChans()
64         {
65                 delete Srv;
66         }
67         
68         virtual Version GetVersion()
69         {
70                 return Version(1,0,0,0);
71         }
72         
73         virtual void OnUserConnect(userrec* user)
74         {
75         }
76
77 };
78
79
80 class ModuleOperChansFactory : public ModuleFactory
81 {
82  public:
83         ModuleOperChansFactory()
84         {
85         }
86         
87         ~ModuleOperChansFactory()
88         {
89         }
90         
91         virtual Module * CreateModule()
92         {
93                 return new ModuleOperChans;
94         }
95         
96 };
97
98
99 extern "C" void * init_module( void )
100 {
101         return new ModuleOperChansFactory;
102 }
103