]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_override.cpp
Added 005 numeric handling to most of the modules
[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                                 if ((Srv->ChanMode(source,channel) != "%") && (Srv->ChanMode(source,channel) != "@"))
68                                 {
69                                         switch (access_type)
70                                         {
71                                                 case AC_KICK:
72                                                         Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Kicked "+std::string(dest->nick)+" on "+std::string(channel->name));
73                                                 break;
74                                                 case AC_DEOP:
75                                                         Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Deopped "+std::string(dest->nick)+" on "+std::string(channel->name));
76                                                 break;
77                                                 case AC_OP:
78                                                         Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Opped "+std::string(dest->nick)+" on "+std::string(channel->name));
79                                                 break;
80                                                 case AC_VOICE:
81                                                         Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Voiced "+std::string(dest->nick)+" on "+std::string(channel->name));
82                                                 break;
83                                                 case AC_DEVOICE:
84                                                         Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Devoiced "+std::string(dest->nick)+" on "+std::string(channel->name));
85                                                 break;
86                                                 case AC_HALFOP:
87                                                         Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Halfopped "+std::string(dest->nick)+" on "+std::string(channel->name));
88                                                 break;
89                                                 case AC_DEHALFOP:
90                                                         Srv->SendOpers("*** NOTICE: "+std::string(source->nick)+" Override-Dehalfopped "+std::string(dest->nick)+" on "+std::string(channel->name));
91                                                 break;
92                                         }
93                                 }
94                         }
95                         return ACR_ALLOW;
96                 }
97
98                 return ACR_DEFAULT;
99         }
100         
101         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname)
102         {
103                 if (strchr(user->modes,'o'))
104                 {
105                         if (chan)
106                         {
107                                 if ((chan->inviteonly) || (chan->key[0]) || (chan->limit >= Srv->CountUsers(chan)))
108                                 {
109                                         if (NoisyOverride)
110                                         {
111                                                 if (!user->IsInvited(chan->name))
112                                                 {
113                                                         WriteChannelWithServ((char*)Srv->GetServerName().c_str(),chan,user,"NOTICE %s :%s invited himself into the channel",cname,user->nick);
114                                                 }
115                                         }
116                                         Srv->SendOpers("*** "+std::string(user->nick)+" used operoverride to bypass +i, +k or +l on "+std::string(cname));
117                                 }
118                                 return -1;
119                         }
120                 }
121                 return 0;
122         }
123         
124         virtual ~ModuleOverride()
125         {
126                 delete Conf;
127                 delete Srv;
128         }
129         
130         virtual Version GetVersion()
131         {
132                 return Version(1,0,0,0);
133         }
134 };
135
136
137 class ModuleOverrideFactory : public ModuleFactory
138 {
139  public:
140         ModuleOverrideFactory()
141         {
142         }
143         
144         ~ModuleOverrideFactory()
145         {
146         }
147         
148         virtual Module * CreateModule()
149         {
150                 return new ModuleOverride;
151         }
152         
153 };
154
155
156 extern "C" void * init_module( void )
157 {
158         return new ModuleOverrideFactory;
159 }
160