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