]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_knock.cpp
Atheme wont work right, because this wasnt VF_COMMON. If its not VF_COMMON, its not...
[user/henk/code/inspircd.git] / src / modules / m_knock.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 <string>
21 #include "users.h"
22 #include "channels.h"
23 #include "modules.h"
24 #include "configreader.h"
25 #include "inspircd.h"
26
27 /* $ModDesc: Provides support for /KNOCK and mode +K */
28
29 /** Handles the /KNOCK command
30  */
31 class cmd_knock : public command_t
32 {
33  public:
34         cmd_knock (InspIRCd* Instance) : command_t(Instance,"KNOCK", 0, 2)
35         {
36                 this->source = "m_knock.so";
37                 syntax = "<channel> <reason>";
38         }
39         
40         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
41         {
42                 chanrec* c = ServerInstance->FindChan(parameters[0]);
43
44                 if (!c)
45                 {
46                         user->WriteServ("401 %s %s :No such channel",user->nick, parameters[0]);
47                         return CMD_FAILURE;
48                 }
49
50                 std::string line = "";
51
52                 if (c->IsModeSet('K'))
53                 {
54                         user->WriteServ("480 %s :Can't KNOCK on %s, +K is set.",user->nick, c->name);
55                         return CMD_FAILURE;
56                 }
57
58                 for (int i = 1; i < pcnt - 1; i++)
59                 {
60                         line = line + std::string(parameters[i]) + " ";
61                 }
62                 line = line + std::string(parameters[pcnt-1]);
63
64                 if (c->modes[CM_INVITEONLY])
65                 {
66                         c->WriteChannelWithServ((char*)ServerInstance->Config->ServerName,  "NOTICE %s :User %s is KNOCKing on %s (%s)", c->name, user->nick, c->name, line.c_str());
67                         user->WriteServ("NOTICE %s :KNOCKing on %s",user->nick,c->name);
68                         return CMD_SUCCESS;
69                 }
70                 else
71                 {
72                         user->WriteServ("480 %s :Can't KNOCK on %s, channel is not invite only so knocking is pointless!",user->nick, c->name);
73                         return CMD_FAILURE;
74                 }
75
76                 return CMD_SUCCESS;
77         }
78 };
79
80 /** Handles channel mode +K
81  */
82 class Knock : public ModeHandler
83 {
84  public:
85         Knock(InspIRCd* Instance) : ModeHandler(Instance, 'K', 0, 0, false, MODETYPE_CHANNEL, false) { }
86
87         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
88         {
89                 if (adding)
90                 {
91                         if (!channel->IsModeSet('K'))
92                         {
93                                 channel->SetMode('K',true);
94                                 return MODEACTION_ALLOW;
95                         }
96                 }
97                 else
98                 {
99                         if (channel->IsModeSet('K'))
100                         {
101                                 channel->SetMode('K',false);
102                                 return MODEACTION_ALLOW;
103                         }
104                 }
105
106                 return MODEACTION_DENY;
107         }
108 };
109
110 class ModuleKnock : public Module
111 {
112         cmd_knock* mycommand;
113         Knock* kn;
114  public:
115         ModuleKnock(InspIRCd* Me) : Module::Module(Me)
116         {
117                 
118                 kn = new Knock(ServerInstance);
119                 ServerInstance->AddMode(kn, 'K');
120                 mycommand = new cmd_knock(ServerInstance);
121                 ServerInstance->AddCommand(mycommand);
122         }
123
124         void Implements(char* List)
125         {
126         }
127
128         virtual ~ModuleKnock()
129         {
130                 ServerInstance->Modes->DelMode(kn);
131                 DELETE(kn);
132         }
133
134         virtual Version GetVersion()
135         {
136                 return Version(1,0,0,1,VF_COMMON|VF_VENDOR);
137         }
138 };
139
140 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
141
142 class ModuleKnockFactory : public ModuleFactory
143 {
144  public:
145         ModuleKnockFactory()
146         {
147         }
148         
149         ~ModuleKnockFactory()
150         {
151         }
152         
153         virtual Module * CreateModule(InspIRCd* Me)
154         {
155                 return new ModuleKnock(Me);
156         }
157         
158 };
159
160
161 extern "C" void * init_module( void )
162 {
163         return new ModuleKnockFactory;
164 }
165