ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/m_knock.c
Revision: 1243
Committed: Fri Sep 30 10:47:53 2011 UTC (12 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 5267 byte(s)
Log Message:
- move content of msg.h, ircd_handler.h and handlers.h into parse.h and
  remove headers accordingly
- killed common.h
- remove m_killhost.c and m_flags.c from contrib/
- sort out unused header includes here and there

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * m_knock.c: Requests to be invited to a channel.
4 *
5 * Copyright (C) 2002 by the past and present ircd coders, and others.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 *
22 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "list.h"
27 #include "channel.h"
28 #include "channel_mode.h"
29 #include "client.h"
30 #include "hash.h"
31 #include "irc_string.h"
32 #include "sprintf_irc.h"
33 #include "ircd.h"
34 #include "numeric.h"
35 #include "send.h"
36 #include "s_conf.h"
37 #include "parse.h"
38 #include "modules.h"
39 #include "s_serv.h"
40 #include "s_user.h"
41
42
43 /* m_knock
44 * parv[0] = sender prefix
45 * parv[1] = channel
46 *
47 * The KNOCK command has the following syntax:
48 * :<sender> KNOCK <channel>
49 *
50 * If a user is not banned from the channel they can use the KNOCK
51 * command to have the server NOTICE the channel operators notifying
52 * they would like to join. Helpful if the channel is invite-only, the
53 * key is forgotten, or the channel is full (INVITE can bypass each one
54 * of these conditions. Concept by Dianora <db@db.net> and written by
55 * <anonymous>
56 */
57 static void
58 m_knock(struct Client *client_p, struct Client *source_p,
59 int parc, char *parv[])
60 {
61 struct Channel *chptr = NULL;
62
63 if (EmptyString(parv[1]))
64 {
65 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
66 me.name, source_p->name, "KNOCK");
67 return;
68 }
69
70 if (!ConfigChannel.use_knock && MyClient(source_p))
71 {
72 sendto_one(source_p, form_str(ERR_KNOCKDISABLED),
73 me.name, source_p->name);
74 return;
75 }
76
77 if ((chptr = hash_find_channel(parv[1])) == NULL)
78 {
79 sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
80 me.name, source_p->name, parv[1]);
81 return;
82 }
83
84 /* Normal channel, just be sure they aren't on it */
85 if (IsMember(source_p, chptr))
86 {
87 sendto_one(source_p, form_str(ERR_KNOCKONCHAN), me.name,
88 source_p->name, chptr->chname);
89 return;
90 }
91
92 if (!((chptr->mode.mode & MODE_INVITEONLY) || (*chptr->mode.key) ||
93 (chptr->mode.limit && dlink_list_length(&chptr->members) >=
94 chptr->mode.limit)))
95 {
96 sendto_one(source_p, form_str(ERR_CHANOPEN), me.name,
97 source_p->name, chptr->chname);
98 return;
99 }
100
101 if (MyClient(source_p))
102 {
103 /*
104 * Don't allow a knock if the user is banned, or the channel is private
105 */
106 if (PrivateChannel(chptr) || is_banned(chptr, source_p))
107 {
108 sendto_one(source_p, form_str(ERR_CANNOTSENDTOCHAN),
109 me.name, source_p->name, chptr->chname);
110 return;
111 }
112
113 /*
114 * flood protection:
115 * allow one knock per user per knock_delay
116 * allow one knock per channel per knock_delay_channel
117 *
118 * we only limit local requests..
119 */
120 if ((source_p->localClient->last_knock + ConfigChannel.knock_delay) >
121 CurrentTime)
122 {
123 sendto_one(source_p, form_str(ERR_TOOMANYKNOCK), me.name,
124 source_p->name, chptr->chname, "user");
125 return;
126 }
127
128 if ((chptr->last_knock + ConfigChannel.knock_delay_channel) > CurrentTime)
129 {
130 sendto_one(source_p, form_str(ERR_TOOMANYKNOCK), me.name,
131 source_p->name, chptr->chname, "channel");
132 return;
133 }
134
135 source_p->localClient->last_knock = CurrentTime;
136
137 sendto_one(source_p, form_str(RPL_KNOCKDLVR), me.name,
138 source_p->name, chptr->chname);
139 }
140
141 chptr->last_knock = CurrentTime;
142
143 if (ConfigChannel.use_knock)
144 sendto_channel_local(CHFL_CHANOP, 0, chptr, form_str(RPL_KNOCK),
145 me.name, chptr->chname, chptr->chname,
146 source_p->name, source_p->username,
147 source_p->host);
148
149 sendto_server(client_p, chptr, CAP_KNOCK|CAP_TS6, NOCAPS,
150 ":%s KNOCK %s", ID(source_p), chptr->chname);
151 sendto_server(client_p, chptr, CAP_KNOCK, CAP_TS6,
152 ":%s KNOCK %s", source_p->name, chptr->chname);
153 }
154
155 static struct Message knock_msgtab = {
156 "KNOCK", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
157 { m_unregistered, m_knock, m_knock, m_ignore, m_knock, m_ignore }
158 };
159
160 static void
161 module_init(void)
162 {
163 mod_add_cmd(&knock_msgtab);
164 add_capability("KNOCK", CAP_KNOCK, 1);
165 add_isupport("KNOCK", NULL, -1);
166 }
167
168 static void
169 module_exit(void)
170 {
171 mod_del_cmd(&knock_msgtab);
172 delete_capability("KNOCK");
173 delete_isupport("KNOCK");
174 }
175
176 struct module module_entry = {
177 .node = { NULL, NULL, NULL },
178 .name = NULL,
179 .version = "$Revision$",
180 .handle = NULL,
181 .modinit = module_init,
182 .modexit = module_exit,
183 .flags = 0
184 };

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision