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