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