]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nokicks.cpp
Fix these too!
[user/henk/code/inspircd.git] / src / modules / m_nokicks.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 "inspircd.h"
24
25 /* $ModDesc: Provides support for unreal-style channel mode +Q */
26
27
28
29 class NoKicks : public ModeHandler
30 {
31  public:
32         NoKicks(InspIRCd* Instance) : ModeHandler(Instance, 'Q', 0, 0, false, MODETYPE_CHANNEL, false) { }
33
34         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
35         {
36                 if (adding)
37                 {
38                         if (!channel->IsModeSet('Q'))
39                         {
40                                 channel->SetMode('Q',true);
41                                 return MODEACTION_ALLOW;
42                         }
43                 }
44                 else
45                 {
46                         if (channel->IsModeSet('Q'))
47                         {
48                                 channel->SetMode('Q',false);
49                                 return MODEACTION_ALLOW;
50                         }
51                 }
52
53                 return MODEACTION_DENY;
54         }
55 };
56
57 class ModuleNoKicks : public Module
58 {
59         
60         NoKicks* nk;
61         
62  public:
63  
64         ModuleNoKicks(InspIRCd* Me)
65                 : Module::Module(Me)
66         {
67                 
68                 nk = new NoKicks(ServerInstance);
69                 ServerInstance->AddMode(nk, 'Q');
70         }
71
72         void Implements(char* List)
73         {
74                 List[I_OnAccessCheck] = 1;
75         }
76
77         virtual int OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type)
78         {
79                 if (access_type == AC_KICK)
80                 {
81                         if (channel->IsModeSet('Q'))
82                         {
83                                 if ((ServerInstance->ULine(source->nick)) || (ServerInstance->ULine(source->server)) || (!*source->server))
84                                 {
85                                         // ulines can still kick with +Q in place
86                                         return ACR_ALLOW;
87                                 }
88                                 else
89                                 {
90                                         // nobody else can (not even opers with override, and founders)
91                                         source->WriteServ("484 %s %s :Can't kick user %s from channel (+Q set)",source->nick, channel->name,dest->nick);
92                                         return ACR_DENY;
93                                 }
94                         }
95                 }
96                 return ACR_DEFAULT;
97         }
98
99         virtual ~ModuleNoKicks()
100         {
101                 ServerInstance->Modes->DelMode(nk);
102                 DELETE(nk);
103         }
104         
105         virtual Version GetVersion()
106         {
107                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
108         }
109 };
110
111
112 class ModuleNoKicksFactory : public ModuleFactory
113 {
114  public:
115         ModuleNoKicksFactory()
116         {
117         }
118         
119         ~ModuleNoKicksFactory()
120         {
121         }
122         
123         virtual Module * CreateModule(InspIRCd* Me)
124         {
125                 return new ModuleNoKicks(Me);
126         }
127         
128 };
129
130
131 extern "C" void * init_module( void )
132 {
133         return new ModuleNoKicksFactory;
134 }
135