]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_override.cpp
Change 974 numeric to 490 to avoid collision with Insp's failed to load module error
[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] = 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 OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type)
86         {
87                 if (strchr(source->modes,'o'))
88                 {
89                         if ((Srv) && (source) && (channel))
90                         {
91                                 // Fix by brain - allow the change if they arent on channel - rely on boolean short-circuit
92                                 // to not check the other items in the statement if they arent on the channel
93                                 if ((!Srv->IsOnChannel(source,channel)) || ((Srv->ChanMode(source,channel) != "%") && (Srv->ChanMode(source,channel) != "@")))
94                                 {
95                                         switch (access_type)
96                                         {
97                                                 case AC_KICK:
98                                                         if (CanOverride(source,"KICK"))
99                                                         {
100                                                                 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Kicked "+std::string(dest->nick)+" on "+std::string(channel->name));
101                                                                 return ACR_ALLOW;
102                                                         }
103                                                         else return ACR_DEFAULT;
104                                                 break;
105                                                 case AC_DEOP:
106                                                         if (CanOverride(source,"MODEOP"))
107                                                         {
108                                                                 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Deopped "+std::string(dest->nick)+" on "+std::string(channel->name));
109                                                                 return ACR_ALLOW;
110                                                         }
111                                                         else return ACR_DEFAULT;
112                                                 break;
113                                                 case AC_OP:
114                                                         if (CanOverride(source,"MODEDEOP"))
115                                                         {
116                                                                 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Opped "+std::string(dest->nick)+" on "+std::string(channel->name));
117                                                                 return ACR_ALLOW;
118                                                         }
119                                                         else return ACR_DEFAULT;
120                                                 break;
121                                                 case AC_VOICE:
122                                                         if (CanOverride(source,"MODEVOICE"))
123                                                         {
124                                                                 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Voiced "+std::string(dest->nick)+" on "+std::string(channel->name));
125                                                                 return ACR_ALLOW;
126                                                         }
127                                                         else return ACR_DEFAULT;
128                                                 break;
129                                                 case AC_DEVOICE:
130                                                         if (CanOverride(source,"MODEDEVOICE"))
131                                                         {
132                                                                 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Devoiced "+std::string(dest->nick)+" on "+std::string(channel->name));
133                                                                 return ACR_ALLOW;
134                                                         }
135                                                         else return ACR_DEFAULT;
136                                                 break;
137                                                 case AC_HALFOP:
138                                                         if (CanOverride(source,"MODEHALFOP"))
139                                                         {
140                                                                 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Halfopped "+std::string(dest->nick)+" on "+std::string(channel->name));
141                                                                 return ACR_ALLOW;
142                                                         }
143                                                         else return ACR_DEFAULT;
144                                                 break;
145                                                 case AC_DEHALFOP:
146                                                         if (CanOverride(source,"MODEDEHALFOP"))
147                                                         {
148                                                                 Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Dehalfopped "+std::string(dest->nick)+" on "+std::string(channel->name));
149                                                                 return ACR_ALLOW;
150                                                         }
151                                                         else return ACR_DEFAULT;
152                                                 break;
153                                         }
154                                 }
155                         }
156                         if (CanOverride(source,"OTHERMODE"))
157                         {
158                                 return ACR_ALLOW;
159                         }
160                         else
161                         {
162                                 return ACR_DEFAULT;
163                         }
164                 }
165
166                 return ACR_DEFAULT;
167         }
168         
169         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
170         {
171                 if (strchr(user->modes,'o'))
172                 {
173                         if (chan)
174                         {
175                                 if ((chan->binarymodes & CM_INVITEONLY) && (CanOverride(user,"INVITE")))
176                                 {
177                                         if (NoisyOverride)
178                                         {
179                                                 irc::string x = chan->name;
180                                                 if (!user->IsInvited(x))
181                                                 {
182                                                         WriteChannelWithServ((char*)Srv->GetServerName().c_str(),chan,"NOTICE %s :%s invited himself into the channel",cname,user->nick);
183                                                 }
184                                         }
185                                         Srv->SendOpers("*** "+std::string(user->nick)+" used operoverride to bypass +i on "+std::string(cname));
186                                         return -1;
187                                 }
188                                 if ((chan->key[0]) && (CanOverride(user,"KEY")))
189                                 {
190                                         if (NoisyOverride)
191                                                 WriteChannelWithServ((char*)Srv->GetServerName().c_str(),chan,"NOTICE %s :%s bypassed the channel key",cname,user->nick);
192                                         Srv->SendOpers("*** "+std::string(user->nick)+" used operoverride to bypass +k on "+std::string(cname));
193                                         return -1;
194                                 }
195                                 if ((chan->limit >= Srv->CountUsers(chan)) && (CanOverride(user,"LIMIT")))
196                                 {
197                                         if (NoisyOverride)
198                                                 WriteChannelWithServ((char*)Srv->GetServerName().c_str(),chan,"NOTICE %s :%s passed through your channel limit",cname,user->nick);
199                                         Srv->SendOpers("*** "+std::string(user->nick)+" used operoverride to bypass +l on "+std::string(cname));
200                                         return -1;
201                                 }
202
203                                 if (CanOverride(user,"BANWALK"))
204                                 {
205                                         // other join
206                                         return -1;
207                                 }
208                         }
209                 }
210                 return 0;
211         }
212         
213         virtual ~ModuleOverride()
214         {
215                 delete Conf;
216         }
217         
218         virtual Version GetVersion()
219         {
220                 return Version(1,0,0,1,VF_VENDOR);
221         }
222 };
223
224
225 class ModuleOverrideFactory : public ModuleFactory
226 {
227  public:
228         ModuleOverrideFactory()
229         {
230         }
231         
232         ~ModuleOverrideFactory()
233         {
234         }
235         
236         virtual Module * CreateModule(Server* Me)
237         {
238                 return new ModuleOverride(Me);
239         }
240         
241 };
242
243
244 extern "C" void * init_module( void )
245 {
246         return new ModuleOverrideFactory;
247 }
248