]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * m_knock.c: Requests to be invited to a channel. | |
4 | * | |
5 | * Copyright (C) 1996-2002 Hybrid Development Team | |
6 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
21 | * USA | |
22 | * | |
732a8c53 | 23 | * $Id: m_knock.c 3570 2007-09-09 19:19:23Z jilles $ |
212380e3 AC |
24 | */ |
25 | ||
26 | #include "stdinc.h" | |
212380e3 AC |
27 | #include "channel.h" |
28 | #include "client.h" | |
29 | #include "hash.h" | |
4562c604 | 30 | #include "match.h" |
212380e3 AC |
31 | #include "ircd.h" |
32 | #include "numeric.h" | |
33 | #include "send.h" | |
34 | #include "s_conf.h" | |
35 | #include "msg.h" | |
36 | #include "parse.h" | |
37 | #include "modules.h" | |
38 | #include "s_serv.h" | |
39 | ||
40 | static int m_knock(struct Client *, struct Client *, int, const char **); | |
41 | ||
42 | struct Message knock_msgtab = { | |
43 | "KNOCK", 0, 0, 0, MFLG_SLOW, | |
44 | {mg_unreg, {m_knock, 2}, {m_knock, 2}, mg_ignore, mg_ignore, {m_knock, 2}} | |
45 | }; | |
46 | ||
47 | mapi_clist_av1 knock_clist[] = { &knock_msgtab, NULL }; | |
732a8c53 | 48 | DECLARE_MODULE_AV1(knock, NULL, NULL, knock_clist, NULL, NULL, "$Revision: 3570 $"); |
212380e3 AC |
49 | |
50 | /* m_knock | |
51 | * parv[0] = sender prefix | |
52 | * parv[1] = channel | |
53 | * | |
54 | * The KNOCK command has the following syntax: | |
55 | * :<sender> KNOCK <channel> | |
56 | * | |
57 | * If a user is not banned from the channel they can use the KNOCK | |
58 | * command to have the server NOTICE the channel operators notifying | |
59 | * they would like to join. Helpful if the channel is invite-only, the | |
60 | * key is forgotten, or the channel is full (INVITE can bypass each one | |
61 | * of these conditions. Concept by Dianora <db@db.net> and written by | |
62 | * <anonymous> | |
63 | */ | |
64 | static int | |
65 | m_knock(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
66 | { | |
67 | struct Channel *chptr; | |
68 | char *p, *name; | |
69 | ||
70 | if(MyClient(source_p) && ConfigChannel.use_knock == 0) | |
71 | { | |
72 | sendto_one(source_p, form_str(ERR_KNOCKDISABLED), | |
73 | me.name, source_p->name); | |
74 | return 0; | |
75 | } | |
76 | ||
77 | name = LOCAL_COPY(parv[1]); | |
78 | ||
79 | /* dont allow one knock to multiple chans */ | |
80 | if((p = strchr(name, ','))) | |
81 | *p = '\0'; | |
82 | ||
83 | if(!IsChannelName(name)) | |
84 | { | |
85 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
86 | form_str(ERR_NOSUCHCHANNEL), name); | |
87 | return 0; | |
88 | } | |
89 | ||
90 | if((chptr = find_channel(name)) == NULL) | |
91 | { | |
92 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
93 | form_str(ERR_NOSUCHCHANNEL), name); | |
94 | return 0; | |
95 | } | |
96 | ||
97 | if(IsMember(source_p, chptr)) | |
98 | { | |
99 | if(MyClient(source_p)) | |
100 | sendto_one(source_p, form_str(ERR_KNOCKONCHAN), | |
101 | me.name, source_p->name, name); | |
102 | return 0; | |
103 | } | |
104 | ||
105 | if(!((chptr->mode.mode & MODE_INVITEONLY) || (*chptr->mode.key) || | |
106 | (chptr->mode.limit && | |
5b96d9a6 | 107 | rb_dlink_list_length(&chptr->members) >= (unsigned long)chptr->mode.limit))) |
212380e3 AC |
108 | { |
109 | sendto_one_numeric(source_p, ERR_CHANOPEN, | |
110 | form_str(ERR_CHANOPEN), name); | |
111 | return 0; | |
112 | } | |
113 | ||
114 | /* cant knock to a +p channel */ | |
115 | if(HiddenChannel(chptr)) | |
116 | { | |
117 | sendto_one_numeric(source_p, ERR_CANNOTSENDTOCHAN, | |
118 | form_str(ERR_CANNOTSENDTOCHAN), name); | |
119 | return 0; | |
120 | } | |
121 | ||
122 | ||
123 | if(MyClient(source_p)) | |
124 | { | |
125 | /* don't allow a knock if the user is banned */ | |
126 | if(is_banned(chptr, source_p, NULL, NULL, NULL) == CHFL_BAN || | |
127 | is_quieted(chptr, source_p, NULL, NULL, NULL) == CHFL_BAN) | |
128 | { | |
129 | sendto_one_numeric(source_p, ERR_CANNOTSENDTOCHAN, | |
130 | form_str(ERR_CANNOTSENDTOCHAN), name); | |
131 | return 0; | |
132 | } | |
133 | ||
134 | /* local flood protection: | |
135 | * allow one knock per user per knock_delay | |
136 | * allow one knock per channel per knock_delay_channel | |
137 | */ | |
138 | if(!IsOper(source_p) && | |
e3354945 | 139 | (source_p->localClient->last_knock + ConfigChannel.knock_delay) > rb_current_time()) |
212380e3 AC |
140 | { |
141 | sendto_one(source_p, form_str(ERR_TOOMANYKNOCK), | |
142 | me.name, source_p->name, name, "user"); | |
143 | return 0; | |
144 | } | |
e3354945 | 145 | else if((chptr->last_knock + ConfigChannel.knock_delay_channel) > rb_current_time()) |
212380e3 AC |
146 | { |
147 | sendto_one(source_p, form_str(ERR_TOOMANYKNOCK), | |
148 | me.name, source_p->name, name, "channel"); | |
149 | return 0; | |
150 | } | |
151 | ||
152 | /* ok, we actually can send the knock, tell client */ | |
e3354945 | 153 | source_p->localClient->last_knock = rb_current_time(); |
212380e3 AC |
154 | |
155 | sendto_one(source_p, form_str(RPL_KNOCKDLVR), | |
156 | me.name, source_p->name, name); | |
157 | } | |
158 | ||
e3354945 | 159 | chptr->last_knock = rb_current_time(); |
212380e3 AC |
160 | |
161 | if(ConfigChannel.use_knock) | |
732a8c53 JT |
162 | sendto_channel_local(chptr->mode.mode & MODE_FREEINVITE ? ALL_MEMBERS : ONLY_CHANOPS, |
163 | chptr, form_str(RPL_KNOCK), | |
212380e3 AC |
164 | me.name, name, name, source_p->name, |
165 | source_p->username, source_p->host); | |
166 | ||
167 | sendto_server(client_p, chptr, CAP_KNOCK|CAP_TS6, NOCAPS, | |
168 | ":%s KNOCK %s", use_id(source_p), name); | |
169 | sendto_server(client_p, chptr, CAP_KNOCK, CAP_TS6, | |
170 | ":%s KNOCK %s", source_p->name, name); | |
171 | return 0; | |
172 | } | |
173 |