]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nokicks.cpp
1afabd182052cf4d27288589f8a95259b382e68d
[user/henk/code/inspircd.git] / src / modules / m_nokicks.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 channel mode +Q */
23
24 class ModuleNoKicks : public Module
25 {
26         Server *Srv;
27         
28  public:
29  
30         ModuleNoKicks()
31         {
32                 Srv = new Server;
33                 Srv->AddExtendedMode('Q',MT_CHANNEL,false,0,0);
34         }
35
36         virtual void On005Numeric(std::string &output)
37         {
38                 std::stringstream line(output);
39                 std::string temp1, temp2;
40                 while (!line.eof())
41                 {
42                         line >> temp1;
43                         if (temp1.substr(0,10) == "CHANMODES=")
44                         {
45                                 // append the chanmode to the end
46                                 temp1 = temp1.substr(10,temp1.length());
47                                 temp1 = "CHANMODES=" + temp1 + "Q";
48                         }
49                         temp2 = temp2 + temp1 + " ";
50                 }
51                 if (temp2.length())
52                         output = temp2.substr(0,temp2.length()-1);
53         }
54
55         virtual int OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type)
56         {
57                 if (access_type == AC_KICK)
58                 {
59                         if (channel->IsCustomModeSet('Q'))
60                         {
61                                 if ((Srv->IsUlined(source->nick)) || (Srv->IsUlined(source->server)) || (!strcmp(source->server,"")))
62                                 {
63                                         // ulines can still kick with +Q in place
64                                         return ACR_ALLOW;
65                                 }
66                                 else
67                                 {
68                                         // nobody else can (not even opers with override, and founders)
69                                         WriteServ(source->fd,"484 %s %s :Can't kick user %s from channel (+Q set)",source->nick, channel->name,dest->nick);
70                                         return ACR_DENY;
71                                 }
72                         }
73                 }
74                 return ACR_DEFAULT;
75         }
76         
77         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
78         {
79                 // check if this is our mode character...
80                 if ((modechar == 'Q') && (type == MT_CHANNEL))
81                 {
82                         return 1;
83                 }
84                 else
85                 {
86                         return 0;
87                 }
88         }
89
90         virtual ~ModuleNoKicks()
91         {
92                 delete Srv;
93         }
94         
95         virtual Version GetVersion()
96         {
97                 return Version(1,0,0,0);
98         }
99 };
100
101
102 class ModuleNoKicksFactory : public ModuleFactory
103 {
104  public:
105         ModuleNoKicksFactory()
106         {
107         }
108         
109         ~ModuleNoKicksFactory()
110         {
111         }
112         
113         virtual Module * CreateModule()
114         {
115                 return new ModuleNoKicks;
116         }
117         
118 };
119
120
121 extern "C" void * init_module( void )
122 {
123         return new ModuleNoKicksFactory;
124 }
125