]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_override.cpp
- Anal tidy of some comments
[user/henk/code/inspircd.git] / src / modules / m_override.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 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         void Implements(char* List)
59         {
60                 List[I_OnRehash] = List[I_OnAccessCheck] = List[I_On005Numeric] = List[I_OnUserPreJoin] = List[I_OnUserPreKick] = 1;
61         }
62
63         virtual void On005Numeric(std::string &output)
64         {
65                 output = output + std::string(" OVERRIDE");
66         }
67
68         virtual bool CanOverride(userrec* source, char* token)
69         {
70                 // checks to see if the oper's type has <type:override>
71                 for (int j =0; j < Conf->Enumerate("type"); j++)
72                 {
73                         std::string typen = Conf->ReadValue("type","name",j);
74                         if (!strcmp(typen.c_str(),source->oper))
75                         {
76                                 // its defined, return its value as a boolean for if the token is set
77                                 std::string tokenlist = Conf->ReadValue("type","override",j);
78                                 return strstr(tokenlist.c_str(),token);
79                         }
80                 }
81                 // its not defined at all, count as false
82                 return false;
83         }
84
85         virtual int OnUserPreKick(userrec* source, userrec* user, chanrec* chan, std::string reason)
86         {
87                 if ((*source->oper) && (CanOverride(source,"KICK")))
88                 {
89                         if (((Srv->ChanMode(source,chan) == "%") && (Srv->ChanMode(user,chan) == "@")) || (Srv->ChanMode(source,chan) == ""))
90                         {
91                                 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Kicked "+std::string(user->nick)+" on "+std::string(chan->name)+" ("+reason+")");
92                         }
93                         /* Returning -1 explicitly allows the kick */
94                         return -1;
95                 }
96                 return 0;
97         }
98         
99         virtual int OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type)
100         {
101                 if (*source->oper)
102                 {
103                         if ((Srv) && (source) && (channel))
104                         {
105                                 // Fix by brain - allow the change if they arent on channel - rely on boolean short-circuit
106                                 // to not check the other items in the statement if they arent on the channel
107                                 if ((!Srv->IsOnChannel(source,channel)) || ((Srv->ChanMode(source,channel) != "%") && (Srv->ChanMode(source,channel) != "@")))
108                                 {
109                                         switch (access_type)
110                                         {
111                                                 case AC_DEOP:
112                                                         if (CanOverride(source,"MODEDEOP"))
113                                                         {
114                                                                 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Deopped "+std::string(dest->nick)+" on "+std::string(channel->name));
115                                                                 return ACR_ALLOW;
116                                                         }
117                                                         else return ACR_DEFAULT;
118                                                 break;
119                                                 case AC_OP:
120                                                         if (CanOverride(source,"MODEOP"))
121                                                         {
122                                                                 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Opped "+std::string(dest->nick)+" on "+std::string(channel->name));
123                                                                 return ACR_ALLOW;
124                                                         }
125                                                         else return ACR_DEFAULT;
126                                                 break;
127                                                 case AC_VOICE:
128                                                         if (CanOverride(source,"MODEVOICE"))
129                                                         {
130                                                                 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Voiced "+std::string(dest->nick)+" on "+std::string(channel->name));
131                                                                 return ACR_ALLOW;
132                                                         }
133                                                         else return ACR_DEFAULT;
134                                                 break;
135                                                 case AC_DEVOICE:
136                                                         if (CanOverride(source,"MODEDEVOICE"))
137                                                         {
138                                                                 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Devoiced "+std::string(dest->nick)+" on "+std::string(channel->name));
139                                                                 return ACR_ALLOW;
140                                                         }
141                                                         else return ACR_DEFAULT;
142                                                 break;
143                                                 case AC_HALFOP:
144                                                         if (CanOverride(source,"MODEHALFOP"))
145                                                         {
146                                                                 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Halfopped "+std::string(dest->nick)+" on "+std::string(channel->name));
147                                                                 return ACR_ALLOW;
148                                                         }
149                                                         else return ACR_DEFAULT;
150                                                 break;
151                                                 case AC_DEHALFOP:
152                                                         if (CanOverride(source,"MODEDEHALFOP"))
153                                                         {
154                                                                 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Dehalfopped "+std::string(dest->nick)+" on "+std::string(channel->name));
155                                                                 return ACR_ALLOW;
156                                                         }
157                                                         else return ACR_DEFAULT;
158                                                 break;
159                                         }
160                                 }
161                         }
162                         if (CanOverride(source,"OTHERMODE"))
163                         {
164                                 return ACR_ALLOW;
165                         }
166                         else
167                         {
168                                 return ACR_DEFAULT;
169                         }
170                 }
171
172                 return ACR_DEFAULT;
173         }
174         
175         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
176         {
177                 if (strchr(user->modes,'o'))
178                 {
179                         if (chan)
180                         {
181                                 if ((chan->binarymodes & CM_INVITEONLY) && (CanOverride(user,"INVITE")))
182                                 {
183                                         if (NoisyOverride)
184                                         {
185                                                 irc::string x = chan->name;
186                                                 if (!user->IsInvited(x))
187                                                 {
188                                                         WriteChannelWithServ((char*)Srv->GetServerName().c_str(),chan,"NOTICE %s :%s invited himself into the channel",cname,user->nick);
189                                                 }
190                                         }
191                                         Srv->SendOpers("*** "+std::string(user->nick)+" used operoverride to bypass +i on "+std::string(cname));
192                                         return -1;
193                                 }
194                                 if ((chan->key[0]) && (CanOverride(user,"KEY")))
195                                 {
196                                         if (NoisyOverride)
197                                                 WriteChannelWithServ((char*)Srv->GetServerName().c_str(),chan,"NOTICE %s :%s bypassed the channel key",cname,user->nick);
198                                         Srv->SendOpers("*** "+std::string(user->nick)+" used operoverride to bypass +k on "+std::string(cname));
199                                         return -1;
200                                 }
201                                 if ((chan->limit >= Srv->CountUsers(chan)) && (CanOverride(user,"LIMIT")))
202                                 {
203                                         if (NoisyOverride)
204                                                 WriteChannelWithServ((char*)Srv->GetServerName().c_str(),chan,"NOTICE %s :%s passed through your channel limit",cname,user->nick);
205                                         Srv->SendOpers("*** "+std::string(user->nick)+" used operoverride to bypass +l on "+std::string(cname));
206                                         return -1;
207                                 }
208
209                                 if (CanOverride(user,"BANWALK"))
210                                 {
211                                         // other join
212                                         return -1;
213                                 }
214                         }
215                 }
216                 return 0;
217         }
218         
219         virtual ~ModuleOverride()
220         {
221                 delete Conf;
222         }
223         
224         virtual Version GetVersion()
225         {
226                 return Version(1,0,0,1,VF_VENDOR);
227         }
228 };
229
230
231 class ModuleOverrideFactory : public ModuleFactory
232 {
233  public:
234         ModuleOverrideFactory()
235         {
236         }
237         
238         ~ModuleOverrideFactory()
239         {
240         }
241         
242         virtual Module * CreateModule(Server* Me)
243         {
244                 return new ModuleOverride(Me);
245         }
246         
247 };
248
249
250 extern "C" void * init_module( void )
251 {
252         return new ModuleOverrideFactory;
253 }
254