ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_knock.c
Revision: 470
Committed: Fri Feb 17 05:07:43 2006 UTC (18 years, 2 months ago) by db
Content type: text/x-csrc
File size: 5132 byte(s)
Log Message:
- fix compile errors with moved modules.h
- fix a few missing includes, msg.h and parse.h


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 "handlers.h"
27 #include "channel.h"
28 #include "channel_mode.h"
29 #include "client.h"
30 #include "hash.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 "conf/modules.h"
38 #include "s_serv.h"
39 #include "s_user.h"
40 #include "common.h"
41
42 static void m_knock(struct Client *, struct Client *, int, char *[]);
43
44 struct Message knock_msgtab = {
45 "KNOCK", 0, 0, 2, 0, MFLG_SLOW, 0,
46 { m_unregistered, m_knock, m_knock, m_ignore, m_knock, m_ignore }
47 };
48
49 INIT_MODULE(m_knock, "$Revision$")
50 {
51 mod_add_cmd(&knock_msgtab);
52 add_capability("KNOCK", CAP_KNOCK, 1);
53 add_isupport("KNOCK", NULL, -1);
54 }
55
56 CLEANUP_MODULE
57 {
58 delete_isupport("KNOCK");
59 delete_capability("KNOCK");
60 mod_del_cmd(&knock_msgtab);
61 }
62
63 /* m_knock
64 * parv[0] = sender prefix
65 * parv[1] = channel
66 *
67 * The KNOCK command has the following syntax:
68 * :<sender> KNOCK <channel>
69 *
70 * If a user is not banned from the channel they can use the KNOCK
71 * command to have the server NOTICE the channel operators notifying
72 * they would like to join. Helpful if the channel is invite-only, the
73 * key is forgotten, or the channel is full (INVITE can bypass each one
74 * of these conditions. Concept by Dianora <db@db.net> and written by
75 * <anonymous>
76 */
77 static void
78 m_knock(struct Client *client_p, struct Client *source_p,
79 int parc, char *parv[])
80 {
81 struct Channel *chptr = NULL;
82
83 if (*parv[1] == '\0')
84 {
85 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
86 me.name, source_p->name, "KNOCK");
87 return;
88 }
89
90 if (!ConfigChannel.use_knock && MyClient(source_p))
91 {
92 sendto_one(source_p, form_str(ERR_KNOCKDISABLED),
93 me.name, source_p->name);
94 return;
95 }
96
97 if ((chptr = hash_find_channel(parv[1])) == NULL)
98 {
99 sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
100 me.name, source_p->name, parv[1]);
101 return;
102 }
103
104 /* Normal channel, just be sure they aren't on it */
105 if (IsMember(source_p, chptr))
106 {
107 sendto_one(source_p, form_str(ERR_KNOCKONCHAN), me.name,
108 source_p->name, chptr->chname);
109 return;
110 }
111
112 if (!((chptr->mode.mode & MODE_INVITEONLY) || (*chptr->mode.key) ||
113 (chptr->mode.limit && dlink_list_length(&chptr->members) >=
114 chptr->mode.limit)))
115 {
116 sendto_one(source_p, form_str(ERR_CHANOPEN), me.name,
117 source_p->name, chptr->chname);
118 return;
119 }
120
121 if (MyClient(source_p))
122 {
123 /* don't allow a knock if the user is banned, or the channel is secret */
124 if ((chptr->mode.mode & MODE_PARANOID) || is_banned(chptr, source_p))
125 {
126 sendto_one(source_p, form_str(ERR_CANNOTSENDTOCHAN),
127 me.name, source_p->name, chptr->chname);
128 return;
129 }
130
131 /*
132 * flood protection:
133 * allow one knock per user per knock_delay
134 * allow one knock per channel per knock_delay_channel
135 *
136 * we only limit local requests..
137 */
138 if ((source_p->localClient->last_knock + ConfigChannel.knock_delay) >
139 CurrentTime)
140 {
141 sendto_one(source_p, form_str(ERR_TOOMANYKNOCK), me.name,
142 source_p->name, chptr->chname, "user");
143 return;
144 }
145
146 if ((chptr->last_knock + ConfigChannel.knock_delay_channel) > CurrentTime)
147 {
148 sendto_one(source_p, form_str(ERR_TOOMANYKNOCK), me.name,
149 source_p->name, chptr->chname, "channel");
150 return;
151 }
152
153 source_p->localClient->last_knock = CurrentTime;
154
155 sendto_one(source_p, form_str(RPL_KNOCKDLVR), me.name,
156 source_p->name, chptr->chname);
157 }
158
159 chptr->last_knock = CurrentTime;
160
161 if (ConfigChannel.use_knock)
162 sendto_channel_local(CHFL_CHANOP, NO, chptr, form_str(RPL_KNOCK),
163 me.name, chptr->chname, chptr->chname,
164 source_p->name, source_p->username,
165 source_p->host);
166
167 sendto_server(client_p, source_p, chptr, CAP_KNOCK|CAP_TS6, NOCAPS,
168 ":%s KNOCK %s %s", ID(source_p), chptr->chname);
169 sendto_server(client_p, source_p, chptr, CAP_KNOCK, CAP_TS6,
170 ":%s KNOCK %s %s", source_p->name, chptr->chname);
171 }

Properties

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