]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_knock.cpp
Added proper administrativia notices to CONNECT and inbound connections
[user/henk/code/inspircd.git] / src / modules / m_knock.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 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 "helperfuncs.h"
25
26 /* $ModDesc: Provides support for /KNOCK and mode +K */
27
28 Server *Srv;
29          
30 void handle_knock(char **parameters, int pcnt, userrec *user)
31 {
32         chanrec* c = Srv->FindChannel(parameters[0]);
33         std::string line = "";
34
35         for (int i = 1; i < pcnt - 1; i++)
36         {
37                 line = line + std::string(parameters[i]) + " ";
38         }
39         line = line + std::string(parameters[pcnt-1]);
40
41         if (c->IsCustomModeSet('K'))
42         {
43                 WriteServ(user->fd,"480 %s :Can't KNOCK on %s, +K is set.",user->nick, c->name);
44                 return;
45         }
46         if (c->binarymodes & CM_INVITEONLY)
47         {
48                 WriteChannelWithServ((char*)Srv->GetServerName().c_str(),c,"NOTICE %s :User %s is KNOCKing on %s (%s)",c->name,user->nick,c->name,line.c_str());
49                 WriteServ(user->fd,"NOTICE %s :KNOCKing on %s",user->nick,c->name);
50                 return;
51         }
52         else
53         {
54                 WriteServ(user->fd,"480 %s :Can't KNOCK on %s, channel is not invite only so knocking is pointless!",user->nick, c->name);
55                 return;
56         }
57 }
58
59
60 class ModuleKnock : public Module
61 {
62  public:
63         ModuleKnock()
64         {
65                 Srv = new Server;
66                 
67                 Srv->AddExtendedMode('K',MT_CHANNEL,false,0,0);
68                 Srv->AddCommand("KNOCK",handle_knock,0,2,"m_knock.so");
69         }
70
71         virtual void On005Numeric(std::string &output)
72         {
73                 std::stringstream line(output);
74                 std::string temp1, temp2;
75                 while (!line.eof())
76                 {
77                         line >> temp1;
78                         if (temp1.substr(0,10) == "CHANMODES=")
79                         {
80                                 // append the chanmode to the end
81                                 temp1 = temp1.substr(10,temp1.length());
82                                 temp1 = "CHANMODES=" + temp1 + "K";
83                         }
84                         temp2 = temp2 + temp1 + " ";
85                 }
86                 if (temp2.length())
87                 {
88                         output = temp2.substr(0,temp2.length()-1) + std::string(" KNOCK");
89                 }
90                 else output = output + std::string(" KNOCK");
91         }
92
93         virtual ~ModuleKnock()
94         {
95                 delete Srv;
96         }
97         
98         virtual Version GetVersion()
99         {
100                 return Version(1,0,0,1,VF_STATIC|VF_VENDOR);
101         }
102         
103         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
104         {
105                 // check if this is our mode character...
106                 if ((modechar == 'K') && (type == MT_CHANNEL))
107                 {
108                         return 1;
109                 }
110                 else
111                 {
112                         return 0;
113                 }
114         }
115
116 };
117
118 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
119
120 class ModuleKnockFactory : public ModuleFactory
121 {
122  public:
123         ModuleKnockFactory()
124         {
125         }
126         
127         ~ModuleKnockFactory()
128         {
129         }
130         
131         virtual Module * CreateModule()
132         {
133                 return new ModuleKnock;
134         }
135         
136 };
137
138
139 extern "C" void * init_module( void )
140 {
141         return new ModuleKnockFactory;
142 }
143