]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_override.cpp
Tons of module versionflags stuff, and checks for it in /UNLOADMODULE
[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
22 /* $ModDesc: Provides support for unreal-style oper-override */
23
24 char dummyvalue[] = "on";
25
26 class ModuleOverride : public Module
27 {
28         Server *Srv;
29         bool NoisyOverride;
30         ConfigReader *Conf;
31         
32  public:
33  
34         ModuleOverride()
35         {
36         
37                 // here we initialise our module. Use new to create new instances of the required
38                 // classes.
39                 
40                 Srv = new Server;
41                 Conf = new ConfigReader;
42                 
43                 // read our config options (main config file)
44                 NoisyOverride = Conf->ReadFlag("override","noisy",0);
45         }
46         
47         virtual void OnRehash()
48         {
49                 // on a rehash we delete our classes for good measure and create them again.
50                 delete Conf;
51                 Conf = new ConfigReader;
52                 // re-read our config options on a rehash
53                 NoisyOverride = Conf->ReadFlag("override","noisy",0);
54         }
55
56         virtual void On005Numeric(std::string &output)
57         {
58                 output = output + std::string(" OVERRIDE");
59         }
60         
61         virtual int OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type)
62         {
63                 if (strchr(source->modes,'o'))
64                 {
65                         if ((Srv) && (source) && (channel))
66                         {
67                                 // Fix by brain - allow the change if they arent on channel - rely on boolean short-circuit
68                                 // to not check the other items in the statement if they arent on the channel
69                                 if ((!Srv->IsOnChannel(source,channel)) || ((Srv->ChanMode(source,channel) != "%") && (Srv->ChanMode(source,channel) != "@")))
70                                 {
71                                         switch (access_type)
72                                         {
73                                                 case AC_KICK:
74                                                         Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Kicked "+std::string(dest->nick)+" on "+std::string(channel->name));
75                                                 break;
76                                                 case AC_DEOP:
77                                                         Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Deopped "+std::string(dest->nick)+" on "+std::string(channel->name));
78                                                 break;
79                                                 case AC_OP:
80                                                         Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Opped "+std::string(dest->nick)+" on "+std::string(channel->name));
81                                                 break;
82                                                 case AC_VOICE:
83                                                         Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Voiced "+std::string(dest->nick)+" on "+std::string(channel->name));
84                                                 break;
85                                                 case AC_DEVOICE:
86                                                         Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Devoiced "+std::string(dest->nick)+" on "+std::string(channel->name));
87                                                 break;
88                                                 case AC_HALFOP:
89                                                         Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Halfopped "+std::string(dest->nick)+" on "+std::string(channel->name));
90                                                 break;
91                                                 case AC_DEHALFOP:
92                                                         Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Dehalfopped "+std::string(dest->nick)+" on "+std::string(channel->name));
93                                                 break;
94                                         }
95                                 }
96                         }
97                         return ACR_ALLOW;
98                 }
99
100                 return ACR_DEFAULT;
101         }
102         
103         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
104         {
105                 if (strchr(user->modes,'o'))
106                 {
107                         if (chan)
108                         {
109                                 if ((chan->inviteonly) || (chan->key[0]) || (chan->limit >= Srv->CountUsers(chan)))
110                                 {
111                                         if (NoisyOverride)
112                                         {
113                                                 if (!user->IsInvited(chan->name))
114                                                 {
115                                                         WriteChannelWithServ((char*)Srv->GetServerName().c_str(),chan,user,"NOTICE %s :%s invited himself into the channel",cname,user->nick);
116                                                 }
117                                         }
118                                         Srv->SendOpers("*** "+std::string(user->nick)+" used operoverride to bypass +i, +k or +l on "+std::string(cname));
119                                 }
120                                 return -1;
121                         }
122                 }
123                 return 0;
124         }
125         
126         virtual ~ModuleOverride()
127         {
128                 delete Conf;
129                 delete Srv;
130         }
131         
132         virtual Version GetVersion()
133         {
134                 return Version(1,0,0,1,VF_VENDOR);
135         }
136 };
137
138
139 class ModuleOverrideFactory : public ModuleFactory
140 {
141  public:
142         ModuleOverrideFactory()
143         {
144         }
145         
146         ~ModuleOverrideFactory()
147         {
148         }
149         
150         virtual Module * CreateModule()
151         {
152                 return new ModuleOverride;
153         }
154         
155 };
156
157
158 extern "C" void * init_module( void )
159 {
160         return new ModuleOverrideFactory;
161 }
162