]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nokicks.cpp
Header rearrangement, move inspircd.h to top, remove stdio, stdlib, stdblahblah that...
[user/henk/code/inspircd.git] / src / modules / m_nokicks.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "users.h"
16 #include "channels.h"
17 #include "modules.h"
18
19 /* $ModDesc: Provides support for unreal-style channel mode +Q */
20
21 class NoKicks : public ModeHandler
22 {
23  public:
24         NoKicks(InspIRCd* Instance) : ModeHandler(Instance, 'Q', 0, 0, false, MODETYPE_CHANNEL, false) { }
25
26         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
27         {
28                 if (adding)
29                 {
30                         if (!channel->IsModeSet('Q'))
31                         {
32                                 channel->SetMode('Q',true);
33                                 return MODEACTION_ALLOW;
34                         }
35                 }
36                 else
37                 {
38                         if (channel->IsModeSet('Q'))
39                         {
40                                 channel->SetMode('Q',false);
41                                 return MODEACTION_ALLOW;
42                         }
43                 }
44
45                 return MODEACTION_DENY;
46         }
47 };
48
49 class ModuleNoKicks : public Module
50 {
51         
52         NoKicks* nk;
53         
54  public:
55  
56         ModuleNoKicks(InspIRCd* Me)
57                 : Module(Me)
58         {
59                 
60                 nk = new NoKicks(ServerInstance);
61                 if (!ServerInstance->AddMode(nk, 'Q'))
62                         throw ModuleException("Could not add new modes!");
63         }
64
65         void Implements(char* List)
66         {
67                 List[I_OnAccessCheck] = 1;
68         }
69
70         virtual int OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type)
71         {
72                 if (access_type == AC_KICK)
73                 {
74                         if (channel->IsModeSet('Q'))
75                         {
76                                 if ((ServerInstance->ULine(source->nick)) || (ServerInstance->ULine(source->server)) || (!*source->server))
77                                 {
78                                         // ulines can still kick with +Q in place
79                                         return ACR_ALLOW;
80                                 }
81                                 else
82                                 {
83                                         // nobody else can (not even opers with override, and founders)
84                                         source->WriteServ("484 %s %s :Can't kick user %s from channel (+Q set)",source->nick, channel->name,dest->nick);
85                                         return ACR_DENY;
86                                 }
87                         }
88                 }
89                 return ACR_DEFAULT;
90         }
91
92         virtual ~ModuleNoKicks()
93         {
94                 ServerInstance->Modes->DelMode(nk);
95                 DELETE(nk);
96         }
97         
98         virtual Version GetVersion()
99         {
100                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
101         }
102 };
103
104
105 class ModuleNoKicksFactory : public ModuleFactory
106 {
107  public:
108         ModuleNoKicksFactory()
109         {
110         }
111         
112         ~ModuleNoKicksFactory()
113         {
114         }
115         
116         virtual Module * CreateModule(InspIRCd* Me)
117         {
118                 return new ModuleNoKicks(Me);
119         }
120         
121 };
122
123
124 extern "C" DllExport void * init_module( void )
125 {
126         return new ModuleNoKicksFactory;
127 }
128