]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_override.cpp
Changed behaviour of module API to pass Server* to the constructor, rather than have...
[user/henk/code/inspircd.git] / src / modules / m_override.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2004 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 unreal-style oper-override */
26
27 class ModuleOverride : public Module
28 {
29         Server *Srv;
30         bool NoisyOverride;
31         ConfigReader *Conf;
32         
33  public:
34  
35         ModuleOverride(Server* Me)
36                 : Module::Module(Me)
37         {
38         
39                 // here we initialise our module. Use new to create new instances of the required
40                 // classes.
41                 
42                 Srv = Me;
43                 Conf = new ConfigReader;
44                 
45                 // read our config options (main config file)
46                 NoisyOverride = Conf->ReadFlag("override","noisy",0);
47         }
48         
49         virtual void OnRehash(std::string parameter)
50         {
51                 // on a rehash we delete our classes for good measure and create them again.
52                 delete Conf;
53                 Conf = new ConfigReader;
54                 // re-read our config options on a rehash
55                 NoisyOverride = Conf->ReadFlag("override","noisy",0);
56         }
57
58         virtual void On005Numeric(std::string &output)
59         {
60                 output = output + std::string(" OVERRIDE");
61         }
62
63         virtual bool CanOverride(userrec* source, char* token)
64         {
65                 // checks to see if the oper's type has <type:override>
66                 for (int j =0; j < Conf->Enumerate("type"); j++)
67                 {
68                         std::string typen = Conf->ReadValue("type","name",j);
69                         if (!strcmp(typen.c_str(),source->oper))
70                         {
71                                 // its defined, return its value as a boolean for if the token is set
72                                 std::string tokenlist = Conf->ReadValue("type","override",j);
73                                 return strstr(tokenlist.c_str(),token);
74                         }
75                 }
76                 // its not defined at all, count as false
77                 return false;
78         }
79         
80         virtual int OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type)
81         {
82                 if (strchr(source->modes,'o'))
83                 {
84                         if ((Srv) && (source) && (channel))
85                         {
86                                 // Fix by brain - allow the change if they arent on channel - rely on boolean short-circuit
87                                 // to not check the other items in the statement if they arent on the channel
88                                 if ((!Srv->IsOnChannel(source,channel)) || ((Srv->ChanMode(source,channel) != "%") && (Srv->ChanMode(source,channel) != "@")))
89                                 {
90                                         switch (access_type)
91                                         {
92                                                 case AC_KICK:
93                                                         if (CanOverride(source,"KICK"))
94                                                         {
95                                                                 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Kicked "+std::string(dest->nick)+" on "+std::string(channel->name));
96                                                                 return ACR_ALLOW;
97                                                         }
98                                                         else return ACR_DEFAULT;
99                                                 break;
100                                                 case AC_DEOP:
101                                                         if (CanOverride(source,"MODEOP"))
102                                                         {
103                                                                 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Deopped "+std::string(dest->nick)+" on "+std::string(channel->name));
104                                                                 return ACR_ALLOW;
105                                                         }
106                                                         else return ACR_DEFAULT;
107                                                 break;
108                                                 case AC_OP:
109                                                         if (CanOverride(source,"MODEDEOP"))
110                                                         {
111                                                                 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Opped "+std::string(dest->nick)+" on "+std::string(channel->name));
112                                                                 return ACR_ALLOW;
113                                                         }
114                                                         else return ACR_DEFAULT;
115                                                 break;
116                                                 case AC_VOICE:
117                                                         if (CanOverride(source,"MODEVOICE"))
118                                                         {
119                                                                 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Voiced "+std::string(dest->nick)+" on "+std::string(channel->name));
120                                                                 return ACR_ALLOW;
121                                                         }
122                                                         else return ACR_DEFAULT;
123                                                 break;
124                                                 case AC_DEVOICE:
125                                                         if (CanOverride(source,"MODEDEVOICE"))
126                                                         {
127                                                                 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Devoiced "+std::string(dest->nick)+" on "+std::string(channel->name));
128                                                                 return ACR_ALLOW;
129                                                         }
130                                                         else return ACR_DEFAULT;
131                                                 break;
132                                                 case AC_HALFOP:
133                                                         if (CanOverride(source,"MODEHALFOP"))
134                                                         {
135                                                                 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Halfopped "+std::string(dest->nick)+" on "+std::string(channel->name));
136                                                                 return ACR_ALLOW;
137                                                         }
138                                                         else return ACR_DEFAULT;
139                                                 break;
140                                                 case AC_DEHALFOP:
141                                                         if (CanOverride(source,"MODEDEHALFOP"))
142                                                         {
143                                                                 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Dehalfopped "+std::string(dest->nick)+" on "+std::string(channel->name));
144                                                                 return ACR_ALLOW;
145                                                         }
146                                                         else return ACR_DEFAULT;
147                                                 break;
148                                         }
149                                 }
150                         }
151                         if (CanOverride(source,"OTHERMODE"))
152                         {
153                                 return ACR_ALLOW;
154                         }
155                         else
156                         {
157                                 return ACR_DEFAULT;
158                         }
159                 }
160
161                 return ACR_DEFAULT;
162         }
163         
164         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
165         {
166                 if (strchr(user->modes,'o'))
167                 {
168                         if (chan)
169                         {
170                                 if ((chan->binarymodes & CM_INVITEONLY) && (CanOverride(user,"INVITE")))
171                                 {
172                                         if (NoisyOverride)
173                                         {
174                                                 if (!user->IsInvited(chan->name))
175                                                 {
176                                                         WriteChannelWithServ((char*)Srv->GetServerName().c_str(),chan,"NOTICE %s :%s invited himself into the channel",cname,user->nick);
177                                                 }
178                                         }
179                                         Srv->SendOpers("*** "+std::string(user->nick)+" used operoverride to bypass +i on "+std::string(cname));
180                                         return -1;
181                                 }
182                                 if ((chan->key[0]) && (CanOverride(user,"KEY")))
183                                 {
184                                         if (NoisyOverride)
185                                                 WriteChannelWithServ((char*)Srv->GetServerName().c_str(),chan,"NOTICE %s :%s bypassed the channel key",cname,user->nick);
186                                         Srv->SendOpers("*** "+std::string(user->nick)+" used operoverride to bypass +k on "+std::string(cname));
187                                         return -1;
188                                 }
189                                 if ((chan->limit >= Srv->CountUsers(chan)) && (CanOverride(user,"LIMIT")))
190                                 {
191                                         if (NoisyOverride)
192                                                 WriteChannelWithServ((char*)Srv->GetServerName().c_str(),chan,"NOTICE %s :%s passed through your channel limit",cname,user->nick);
193                                         Srv->SendOpers("*** "+std::string(user->nick)+" used operoverride to bypass +l on "+std::string(cname));
194                                         return -1;
195                                 }
196
197                                 if (CanOverride(user,"BANWALK"))
198                                 {
199                                         // other join
200                                         return -1;
201                                 }
202                         }
203                 }
204                 return 0;
205         }
206         
207         virtual ~ModuleOverride()
208         {
209                 delete Conf;
210         }
211         
212         virtual Version GetVersion()
213         {
214                 return Version(1,0,0,1,VF_VENDOR);
215         }
216 };
217
218
219 class ModuleOverrideFactory : public ModuleFactory
220 {
221  public:
222         ModuleOverrideFactory()
223         {
224         }
225         
226         ~ModuleOverrideFactory()
227         {
228         }
229         
230         virtual Module * CreateModule(Server* Me)
231         {
232                 return new ModuleOverride(Me);
233         }
234         
235 };
236
237
238 extern "C" void * init_module( void )
239 {
240         return new ModuleOverrideFactory;
241 }
242