ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/m_knock.c
Revision: 1496
Committed: Sun Aug 5 10:02:07 2012 UTC (13 years ago) by michael
Content type: text/x-csrc
File size: 5133 byte(s)
Log Message:
- m_knock(): announce INVITE requests via NOTICE to other channel operators,
  rather than using a numeric reply for this

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 "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 ((chptr = hash_find_channel(parv[1])) == NULL)
71 {
72 sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
73 me.name, source_p->name, parv[1]);
74 return;
75 }
76
77 /* Normal channel, just be sure they aren't on it */
78 if (IsMember(source_p, chptr))
79 {
80 sendto_one(source_p, form_str(ERR_KNOCKONCHAN), me.name,
81 source_p->name, chptr->chname);
82 return;
83 }
84
85 if (!((chptr->mode.mode & MODE_INVITEONLY) || (*chptr->mode.key) ||
86 (chptr->mode.limit && dlink_list_length(&chptr->members) >=
87 chptr->mode.limit)))
88 {
89 sendto_one(source_p, form_str(ERR_CHANOPEN), me.name,
90 source_p->name, chptr->chname);
91 return;
92 }
93
94 if (MyClient(source_p))
95 {
96 /*
97 * Don't allow a knock if the user is banned, or the channel is private
98 */
99 if (PrivateChannel(chptr) || is_banned(chptr, source_p))
100 {
101 sendto_one(source_p, form_str(ERR_CANNOTSENDTOCHAN),
102 me.name, source_p->name, chptr->chname);
103 return;
104 }
105
106 /*
107 * flood protection:
108 * allow one knock per user per knock_delay
109 * allow one knock per channel per knock_delay_channel
110 *
111 * we only limit local requests..
112 */
113 if ((source_p->localClient->last_knock + ConfigChannel.knock_delay) >
114 CurrentTime)
115 {
116 sendto_one(source_p, form_str(ERR_TOOMANYKNOCK), me.name,
117 source_p->name, chptr->chname, "user");
118 return;
119 }
120
121 if ((chptr->last_knock + ConfigChannel.knock_delay_channel) > CurrentTime)
122 {
123 sendto_one(source_p, form_str(ERR_TOOMANYKNOCK), me.name,
124 source_p->name, chptr->chname, "channel");
125 return;
126 }
127
128 source_p->localClient->last_knock = CurrentTime;
129
130 sendto_one(source_p, form_str(RPL_KNOCKDLVR), me.name,
131 source_p->name, chptr->chname);
132 }
133
134 chptr->last_knock = CurrentTime;
135
136 sendto_channel_local(CHFL_CHANOP, 0, chptr,
137 ":%s NOTICE @%s :KNOCK: %s (%s [%s@%s] has asked for an invite)",
138 me.name, chptr->chname, chptr->chname,
139 source_p->name,
140 source_p->username,
141 source_p->host);
142
143 sendto_server(client_p, CAP_KNOCK|CAP_TS6, NOCAPS,
144 ":%s KNOCK %s", ID(source_p), chptr->chname);
145 sendto_server(client_p, CAP_KNOCK, CAP_TS6,
146 ":%s KNOCK %s", source_p->name, chptr->chname);
147 }
148
149 static struct Message knock_msgtab = {
150 "KNOCK", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
151 { m_unregistered, m_knock, m_knock, m_ignore, m_knock, m_ignore }
152 };
153
154 static void
155 module_init(void)
156 {
157 mod_add_cmd(&knock_msgtab);
158 add_capability("KNOCK", CAP_KNOCK, 1);
159 add_isupport("KNOCK", NULL, -1);
160 }
161
162 static void
163 module_exit(void)
164 {
165 mod_del_cmd(&knock_msgtab);
166 delete_capability("KNOCK");
167 delete_isupport("KNOCK");
168 }
169
170 struct module module_entry = {
171 .node = { NULL, NULL, NULL },
172 .name = NULL,
173 .version = "$Revision$",
174 .handle = NULL,
175 .modinit = module_init,
176 .modexit = module_exit,
177 .flags = 0
178 };

Properties

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