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