]> jfr.im git - irc/rqf/shadowircd.git/blob - modules/m_knock.c
autogen.sh is not necessary at this time, and did not work anyway.
[irc/rqf/shadowircd.git] / modules / m_knock.c
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 *
23 * $Id: m_knock.c 3570 2007-09-09 19:19:23Z jilles $
24 */
25
26 #include "stdinc.h"
27 #include "channel.h"
28 #include "client.h"
29 #include "hash.h"
30 #include "match.h"
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 };
48 DECLARE_MODULE_AV1(knock, NULL, NULL, knock_clist, NULL, NULL, "$Revision: 3570 $");
49
50 /* m_knock
51 * parv[1] = channel
52 *
53 * The KNOCK command has the following syntax:
54 * :<sender> KNOCK <channel>
55 *
56 * If a user is not banned from the channel they can use the KNOCK
57 * command to have the server NOTICE the channel operators notifying
58 * they would like to join. Helpful if the channel is invite-only, the
59 * key is forgotten, or the channel is full (INVITE can bypass each one
60 * of these conditions. Concept by Dianora <db@db.net> and written by
61 * <anonymous>
62 */
63 static int
64 m_knock(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
65 {
66 struct Channel *chptr;
67 char *p, *name;
68
69 if(MyClient(source_p) && ConfigChannel.use_knock == 0)
70 {
71 sendto_one(source_p, form_str(ERR_KNOCKDISABLED),
72 me.name, source_p->name);
73 return 0;
74 }
75
76 name = LOCAL_COPY(parv[1]);
77
78 /* dont allow one knock to multiple chans */
79 if((p = strchr(name, ',')))
80 *p = '\0';
81
82 if(!IsChannelName(name))
83 {
84 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
85 form_str(ERR_NOSUCHCHANNEL), name);
86 return 0;
87 }
88
89 if((chptr = find_channel(name)) == NULL)
90 {
91 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
92 form_str(ERR_NOSUCHCHANNEL), name);
93 return 0;
94 }
95
96 if(IsMember(source_p, chptr))
97 {
98 if(MyClient(source_p))
99 sendto_one(source_p, form_str(ERR_KNOCKONCHAN),
100 me.name, source_p->name, name);
101 return 0;
102 }
103
104 if(!((chptr->mode.mode & MODE_INVITEONLY) || (*chptr->mode.key) ||
105 (chptr->mode.limit &&
106 rb_dlink_list_length(&chptr->members) >= (unsigned long)chptr->mode.limit)))
107 {
108 sendto_one_numeric(source_p, ERR_CHANOPEN,
109 form_str(ERR_CHANOPEN), name);
110 return 0;
111 }
112
113 /* cant knock to a +p channel */
114 if(HiddenChannel(chptr))
115 {
116 sendto_one_numeric(source_p, ERR_CANNOTSENDTOCHAN,
117 form_str(ERR_CANNOTSENDTOCHAN), name);
118 return 0;
119 }
120
121
122 if(MyClient(source_p))
123 {
124 /* don't allow a knock if the user is banned */
125 if(is_banned(chptr, source_p, NULL, NULL, NULL) == CHFL_BAN ||
126 is_quieted(chptr, source_p, NULL, NULL, NULL) == CHFL_BAN)
127 {
128 sendto_one_numeric(source_p, ERR_CANNOTSENDTOCHAN,
129 form_str(ERR_CANNOTSENDTOCHAN), name);
130 return 0;
131 }
132
133 /* local flood protection:
134 * allow one knock per user per knock_delay
135 * allow one knock per channel per knock_delay_channel
136 */
137 if(!IsOper(source_p) &&
138 (source_p->localClient->last_knock + ConfigChannel.knock_delay) > rb_current_time())
139 {
140 sendto_one(source_p, form_str(ERR_TOOMANYKNOCK),
141 me.name, source_p->name, name, "user");
142 return 0;
143 }
144 else if((chptr->last_knock + ConfigChannel.knock_delay_channel) > rb_current_time())
145 {
146 sendto_one(source_p, form_str(ERR_TOOMANYKNOCK),
147 me.name, source_p->name, name, "channel");
148 return 0;
149 }
150
151 /* ok, we actually can send the knock, tell client */
152 source_p->localClient->last_knock = rb_current_time();
153
154 sendto_one(source_p, form_str(RPL_KNOCKDLVR),
155 me.name, source_p->name, name);
156 }
157
158 chptr->last_knock = rb_current_time();
159
160 if(ConfigChannel.use_knock)
161 sendto_channel_local(chptr->mode.mode & MODE_FREEINVITE ? ALL_MEMBERS : ONLY_CHANOPS,
162 chptr, form_str(RPL_KNOCK),
163 me.name, name, name, source_p->name,
164 source_p->username, source_p->host);
165
166 sendto_server(client_p, chptr, CAP_KNOCK|CAP_TS6, NOCAPS,
167 ":%s KNOCK %s", use_id(source_p), name);
168 sendto_server(client_p, chptr, CAP_KNOCK, CAP_TS6,
169 ":%s KNOCK %s", source_p->name, name);
170 return 0;
171 }
172