1 |
adx |
30 |
/* |
2 |
|
|
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
|
|
* m_knock.c: Requests to be invited to a channel. |
4 |
|
|
* |
5 |
|
|
* Copyright (C) 2002 by the past and present ircd coders, and others. |
6 |
|
|
* |
7 |
|
|
* This program is free software; you can redistribute it and/or modify |
8 |
|
|
* it under the terms of the GNU General Public License as published by |
9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
10 |
|
|
* (at your option) any later version. |
11 |
|
|
* |
12 |
|
|
* This program is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with this program; if not, write to the Free Software |
19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
|
|
* USA |
21 |
|
|
* |
22 |
knight |
31 |
* $Id$ |
23 |
adx |
30 |
*/ |
24 |
|
|
|
25 |
|
|
#include "stdinc.h" |
26 |
michael |
1011 |
#include "list.h" |
27 |
adx |
30 |
#include "channel.h" |
28 |
|
|
#include "channel_mode.h" |
29 |
|
|
#include "client.h" |
30 |
|
|
#include "hash.h" |
31 |
|
|
#include "irc_string.h" |
32 |
|
|
#include "ircd.h" |
33 |
|
|
#include "numeric.h" |
34 |
|
|
#include "send.h" |
35 |
michael |
1309 |
#include "conf.h" |
36 |
adx |
30 |
#include "parse.h" |
37 |
|
|
#include "modules.h" |
38 |
|
|
#include "s_serv.h" |
39 |
|
|
#include "s_user.h" |
40 |
|
|
|
41 |
|
|
|
42 |
|
|
/* m_knock |
43 |
|
|
* parv[0] = sender prefix |
44 |
|
|
* parv[1] = channel |
45 |
|
|
* |
46 |
|
|
* The KNOCK command has the following syntax: |
47 |
|
|
* :<sender> KNOCK <channel> |
48 |
|
|
* |
49 |
|
|
* If a user is not banned from the channel they can use the KNOCK |
50 |
|
|
* command to have the server NOTICE the channel operators notifying |
51 |
|
|
* they would like to join. Helpful if the channel is invite-only, the |
52 |
|
|
* key is forgotten, or the channel is full (INVITE can bypass each one |
53 |
|
|
* of these conditions. Concept by Dianora <db@db.net> and written by |
54 |
|
|
* <anonymous> |
55 |
|
|
*/ |
56 |
|
|
static void |
57 |
|
|
m_knock(struct Client *client_p, struct Client *source_p, |
58 |
|
|
int parc, char *parv[]) |
59 |
|
|
{ |
60 |
michael |
885 |
struct Channel *chptr = NULL; |
61 |
adx |
30 |
|
62 |
michael |
885 |
if (EmptyString(parv[1])) |
63 |
adx |
30 |
{ |
64 |
michael |
1832 |
sendto_one(source_p, ERR_NEEDMOREPARAMS, |
65 |
adx |
30 |
me.name, source_p->name, "KNOCK"); |
66 |
|
|
return; |
67 |
|
|
} |
68 |
|
|
|
69 |
michael |
885 |
if ((chptr = hash_find_channel(parv[1])) == NULL) |
70 |
adx |
30 |
{ |
71 |
michael |
1832 |
sendto_one(source_p, ERR_NOSUCHCHANNEL, |
72 |
michael |
885 |
me.name, source_p->name, parv[1]); |
73 |
adx |
30 |
return; |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
/* Normal channel, just be sure they aren't on it */ |
77 |
|
|
if (IsMember(source_p, chptr)) |
78 |
|
|
{ |
79 |
michael |
1832 |
sendto_one(source_p, ERR_KNOCKONCHAN, me.name, |
80 |
michael |
885 |
source_p->name, chptr->chname); |
81 |
adx |
30 |
return; |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
if (!((chptr->mode.mode & MODE_INVITEONLY) || (*chptr->mode.key) || |
85 |
|
|
(chptr->mode.limit && dlink_list_length(&chptr->members) >= |
86 |
|
|
chptr->mode.limit))) |
87 |
|
|
{ |
88 |
michael |
1832 |
sendto_one(source_p, ERR_CHANOPEN, me.name, |
89 |
michael |
885 |
source_p->name, chptr->chname); |
90 |
adx |
30 |
return; |
91 |
|
|
} |
92 |
|
|
|
93 |
michael |
885 |
if (MyClient(source_p)) |
94 |
adx |
30 |
{ |
95 |
michael |
886 |
/* |
96 |
|
|
* Don't allow a knock if the user is banned, or the channel is private |
97 |
|
|
*/ |
98 |
|
|
if (PrivateChannel(chptr) || is_banned(chptr, source_p)) |
99 |
michael |
885 |
{ |
100 |
michael |
1832 |
sendto_one(source_p, ERR_CANNOTSENDTOCHAN, |
101 |
michael |
885 |
me.name, source_p->name, chptr->chname); |
102 |
|
|
return; |
103 |
|
|
} |
104 |
adx |
30 |
|
105 |
michael |
885 |
/* |
106 |
|
|
* flood protection: |
107 |
|
|
* allow one knock per user per knock_delay |
108 |
|
|
* allow one knock per channel per knock_delay_channel |
109 |
|
|
* |
110 |
|
|
* we only limit local requests.. |
111 |
|
|
*/ |
112 |
|
|
if ((source_p->localClient->last_knock + ConfigChannel.knock_delay) > |
113 |
|
|
CurrentTime) |
114 |
|
|
{ |
115 |
michael |
1832 |
sendto_one(source_p, ERR_TOOMANYKNOCK, me.name, |
116 |
michael |
885 |
source_p->name, chptr->chname, "user"); |
117 |
|
|
return; |
118 |
|
|
} |
119 |
adx |
30 |
|
120 |
michael |
885 |
if ((chptr->last_knock + ConfigChannel.knock_delay_channel) > CurrentTime) |
121 |
|
|
{ |
122 |
michael |
1832 |
sendto_one(source_p, ERR_TOOMANYKNOCK, me.name, |
123 |
michael |
885 |
source_p->name, chptr->chname, "channel"); |
124 |
|
|
return; |
125 |
|
|
} |
126 |
adx |
30 |
|
127 |
michael |
885 |
source_p->localClient->last_knock = CurrentTime; |
128 |
adx |
30 |
|
129 |
michael |
1832 |
sendto_one(source_p, RPL_KNOCKDLVR, me.name, |
130 |
michael |
885 |
source_p->name, chptr->chname); |
131 |
|
|
} |
132 |
adx |
30 |
|
133 |
|
|
chptr->last_knock = CurrentTime; |
134 |
|
|
|
135 |
michael |
1496 |
sendto_channel_local(CHFL_CHANOP, 0, chptr, |
136 |
|
|
":%s NOTICE @%s :KNOCK: %s (%s [%s@%s] has asked for an invite)", |
137 |
michael |
1495 |
me.name, chptr->chname, chptr->chname, |
138 |
michael |
1496 |
source_p->name, |
139 |
|
|
source_p->username, |
140 |
michael |
1495 |
source_p->host); |
141 |
adx |
30 |
|
142 |
michael |
1474 |
sendto_server(client_p, CAP_KNOCK|CAP_TS6, NOCAPS, |
143 |
michael |
886 |
":%s KNOCK %s", ID(source_p), chptr->chname); |
144 |
michael |
1474 |
sendto_server(client_p, CAP_KNOCK, CAP_TS6, |
145 |
michael |
886 |
":%s KNOCK %s", source_p->name, chptr->chname); |
146 |
adx |
30 |
} |
147 |
michael |
1230 |
|
148 |
|
|
static struct Message knock_msgtab = { |
149 |
|
|
"KNOCK", 0, 0, 2, MAXPARA, MFLG_SLOW, 0, |
150 |
|
|
{ m_unregistered, m_knock, m_knock, m_ignore, m_knock, m_ignore } |
151 |
|
|
}; |
152 |
|
|
|
153 |
|
|
static void |
154 |
|
|
module_init(void) |
155 |
|
|
{ |
156 |
|
|
mod_add_cmd(&knock_msgtab); |
157 |
|
|
add_capability("KNOCK", CAP_KNOCK, 1); |
158 |
|
|
add_isupport("KNOCK", NULL, -1); |
159 |
|
|
} |
160 |
|
|
|
161 |
|
|
static void |
162 |
|
|
module_exit(void) |
163 |
|
|
{ |
164 |
|
|
mod_del_cmd(&knock_msgtab); |
165 |
|
|
delete_capability("KNOCK"); |
166 |
|
|
delete_isupport("KNOCK"); |
167 |
|
|
} |
168 |
|
|
|
169 |
|
|
struct module module_entry = { |
170 |
|
|
.node = { NULL, NULL, NULL }, |
171 |
|
|
.name = NULL, |
172 |
|
|
.version = "$Revision$", |
173 |
|
|
.handle = NULL, |
174 |
|
|
.modinit = module_init, |
175 |
|
|
.modexit = module_exit, |
176 |
|
|
.flags = 0 |
177 |
|
|
}; |