]>
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" | |
0b904d91 | 39 | #include "supported.h" |
212380e3 | 40 | |
428ca87b | 41 | static int m_knock(struct MsgBuf *, struct Client *, struct Client *, int, const char **); |
212380e3 AC |
42 | |
43 | struct Message knock_msgtab = { | |
7baa37a9 | 44 | "KNOCK", 0, 0, 0, 0, |
212380e3 AC |
45 | {mg_unreg, {m_knock, 2}, {m_knock, 2}, mg_ignore, mg_ignore, {m_knock, 2}} |
46 | }; | |
47 | ||
0b904d91 AC |
48 | static int |
49 | _modinit(void) | |
50 | { | |
51 | add_isupport("KNOCK", isupport_boolean, &ConfigChannel.use_knock); | |
52 | return 0; | |
53 | } | |
54 | ||
55 | static void | |
56 | _moddeinit(void) | |
57 | { | |
58 | delete_isupport("KNOCK"); | |
59 | } | |
60 | ||
212380e3 | 61 | mapi_clist_av1 knock_clist[] = { &knock_msgtab, NULL }; |
0b904d91 | 62 | DECLARE_MODULE_AV1(knock, _modinit, _moddeinit, knock_clist, NULL, NULL, "$Revision: 3570 $"); |
212380e3 AC |
63 | |
64 | /* m_knock | |
212380e3 AC |
65 | * parv[1] = channel |
66 | * | |
67 | * The KNOCK command has the following syntax: | |
68 | * :<sender> KNOCK <channel> | |
69 | * | |
70 | * If a user is not banned from the channel they can use the KNOCK | |
71 | * command to have the server NOTICE the channel operators notifying | |
72 | * they would like to join. Helpful if the channel is invite-only, the | |
73 | * key is forgotten, or the channel is full (INVITE can bypass each one | |
74 | * of these conditions. Concept by Dianora <db@db.net> and written by | |
75 | * <anonymous> | |
76 | */ | |
77 | static int | |
428ca87b | 78 | m_knock(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
79 | { |
80 | struct Channel *chptr; | |
81 | char *p, *name; | |
82 | ||
83 | if(MyClient(source_p) && ConfigChannel.use_knock == 0) | |
84 | { | |
85 | sendto_one(source_p, form_str(ERR_KNOCKDISABLED), | |
86 | me.name, source_p->name); | |
87 | return 0; | |
88 | } | |
89 | ||
90 | name = LOCAL_COPY(parv[1]); | |
91 | ||
92 | /* dont allow one knock to multiple chans */ | |
93 | if((p = strchr(name, ','))) | |
94 | *p = '\0'; | |
95 | ||
212380e3 AC |
96 | if((chptr = find_channel(name)) == NULL) |
97 | { | |
98 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
99 | form_str(ERR_NOSUCHCHANNEL), name); | |
100 | return 0; | |
101 | } | |
102 | ||
103 | if(IsMember(source_p, chptr)) | |
104 | { | |
105 | if(MyClient(source_p)) | |
106 | sendto_one(source_p, form_str(ERR_KNOCKONCHAN), | |
107 | me.name, source_p->name, name); | |
108 | return 0; | |
109 | } | |
110 | ||
55abcbb2 KB |
111 | if(!((chptr->mode.mode & MODE_INVITEONLY) || (*chptr->mode.key) || |
112 | (chptr->mode.limit && | |
5b96d9a6 | 113 | rb_dlink_list_length(&chptr->members) >= (unsigned long)chptr->mode.limit))) |
212380e3 AC |
114 | { |
115 | sendto_one_numeric(source_p, ERR_CHANOPEN, | |
116 | form_str(ERR_CHANOPEN), name); | |
117 | return 0; | |
118 | } | |
119 | ||
120 | /* cant knock to a +p channel */ | |
121 | if(HiddenChannel(chptr)) | |
122 | { | |
123 | sendto_one_numeric(source_p, ERR_CANNOTSENDTOCHAN, | |
124 | form_str(ERR_CANNOTSENDTOCHAN), name); | |
125 | return 0; | |
126 | } | |
127 | ||
55abcbb2 | 128 | |
212380e3 AC |
129 | if(MyClient(source_p)) |
130 | { | |
131 | /* don't allow a knock if the user is banned */ | |
765d839d EM |
132 | if(is_banned(chptr, source_p, NULL, NULL, NULL, NULL) == CHFL_BAN || |
133 | is_quieted(chptr, source_p, NULL, NULL, NULL) == CHFL_BAN) | |
212380e3 AC |
134 | { |
135 | sendto_one_numeric(source_p, ERR_CANNOTSENDTOCHAN, | |
136 | form_str(ERR_CANNOTSENDTOCHAN), name); | |
137 | return 0; | |
138 | } | |
139 | ||
140 | /* local flood protection: | |
141 | * allow one knock per user per knock_delay | |
142 | * allow one knock per channel per knock_delay_channel | |
143 | */ | |
55abcbb2 | 144 | if(!IsOper(source_p) && |
e3354945 | 145 | (source_p->localClient->last_knock + ConfigChannel.knock_delay) > rb_current_time()) |
212380e3 AC |
146 | { |
147 | sendto_one(source_p, form_str(ERR_TOOMANYKNOCK), | |
148 | me.name, source_p->name, name, "user"); | |
149 | return 0; | |
150 | } | |
e3354945 | 151 | else if((chptr->last_knock + ConfigChannel.knock_delay_channel) > rb_current_time()) |
212380e3 AC |
152 | { |
153 | sendto_one(source_p, form_str(ERR_TOOMANYKNOCK), | |
154 | me.name, source_p->name, name, "channel"); | |
155 | return 0; | |
156 | } | |
157 | ||
158 | /* ok, we actually can send the knock, tell client */ | |
e3354945 | 159 | source_p->localClient->last_knock = rb_current_time(); |
212380e3 AC |
160 | |
161 | sendto_one(source_p, form_str(RPL_KNOCKDLVR), | |
162 | me.name, source_p->name, name); | |
163 | } | |
164 | ||
e3354945 | 165 | chptr->last_knock = rb_current_time(); |
212380e3 AC |
166 | |
167 | if(ConfigChannel.use_knock) | |
732a8c53 JT |
168 | sendto_channel_local(chptr->mode.mode & MODE_FREEINVITE ? ALL_MEMBERS : ONLY_CHANOPS, |
169 | chptr, form_str(RPL_KNOCK), | |
212380e3 AC |
170 | me.name, name, name, source_p->name, |
171 | source_p->username, source_p->host); | |
172 | ||
173 | sendto_server(client_p, chptr, CAP_KNOCK|CAP_TS6, NOCAPS, | |
174 | ":%s KNOCK %s", use_id(source_p), name); | |
175 | sendto_server(client_p, chptr, CAP_KNOCK, CAP_TS6, | |
176 | ":%s KNOCK %s", source_p->name, name); | |
177 | return 0; | |
178 | } | |
179 |