ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/m_knock.c
Revision: 885
Committed: Wed Oct 31 18:09:24 2007 UTC (16 years, 4 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.2/modules/m_knock.c
File size: 5238 byte(s)
Log Message:
- Removed LazyLinks in 7.2 to stop people from asking why we keep
  broken code for half a decade. LL will be implemented in a smarter
  fashion in due time

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

Properties

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