]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operchans.cpp
Holy christ that was a LOT OF SPACES. TABS, USE THEM, LOVE THEM, APPRECIATE THEM...
[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 ModuleOperChans : public Module
28 {
29         Server* Srv;
30  public:
31         ModuleOperChans(Server* Me)
32                 : Module::Module(Me)
33         {
34                 Srv = Me;
35                 // Add a mode +O for channels with no parameters                
36                 Srv->AddExtendedMode('O',MT_CHANNEL,false,0,0);
37         }
38
39         void Implements(char* List)
40         {
41                 List[I_OnExtendedMode] = List[I_On005Numeric] = List[I_OnUserPreJoin] = 1;
42         }
43         
44         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
45         {
46                 if ((modechar == 'O') && (type == MT_CHANNEL))
47                 {
48                         chanrec* chan = (chanrec*)target;
49                         
50                         if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!*user->server) || (*user->oper))
51                         {
52                                 log(DEBUG,"Allowing mode +O");
53                                 return 1;
54                         }
55                         else
56                         {
57                                 // eat the mode change, return an error
58                                 WriteServ(user->fd,"468 %s %s :Only servers and opers may set channel mode +O",user->nick, chan->name);
59                                 return 0;
60                         }
61         
62                         // must return 1 to handle the mode!
63                         return 1;
64                 }
65                 
66                 return 0;
67         }
68
69         virtual void On005Numeric(std::string &output)
70         {
71                 InsertMode(output,"O",4);
72         }
73         
74         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
75         {
76                 if (!*user->oper)
77                 {
78                         if (chan)
79                         {
80                                 if (chan->IsModeSet('O'))
81                                 {
82                                         WriteServ(user->fd,"520 %s %s :Only IRC operators may join the channel %s (+O is set)",user->nick, chan->name,chan->name);
83                                         return 1;
84                                 }
85                         }
86                 }
87                 return 0;
88         }
89         
90         virtual ~ModuleOperChans()
91         {
92         }
93         
94         virtual Version GetVersion()
95         {
96                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
97         }
98 };
99
100
101 class ModuleOperChansFactory : public ModuleFactory
102 {
103  public:
104         ModuleOperChansFactory()
105         {
106         }
107         
108         ~ModuleOperChansFactory()
109         {
110         }
111         
112         virtual Module * CreateModule(Server* Me)
113         {
114                 return new ModuleOperChans(Me);
115         }
116         
117 };
118
119
120 extern "C" void * init_module( void )
121 {
122         return new ModuleOperChansFactory;
123 }
124