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