ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_knock.c
Revision: 741
Committed: Sun Jul 23 13:49:20 2006 UTC (19 years, 1 month ago) by adx
Content type: text/x-csrc
File size: 5112 byte(s)
Log Message:
+ removed s_conf.h and superseded parts of s_conf.c

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

Properties

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