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