ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/m_knock.c
Revision: 886
Committed: Wed Oct 31 18:45:58 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: 5233 byte(s)
Log Message:
- Fixed comment in m_knock.c and make use of the PrivateChannel macro
  to confuse people less

File Contents

# User Rev Content
1 adx 30 /*
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 knight 31 * $Id$
23 adx 30 */
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 michael 885 static void m_knock(struct Client *, struct Client *, int, char *[]);
46 adx 30
47     struct Message knock_msgtab = {
48     "KNOCK", 0, 0, 2, 0, MFLG_SLOW, 0,
49 michael 885 { m_unregistered, m_knock, m_knock, m_ignore, m_knock, m_ignore }
50 adx 30 };
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 knight 31 const char *_version = "$Revision$";
70 adx 30 #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 michael 885 struct Channel *chptr = NULL;
91 adx 30
92 michael 885 if (EmptyString(parv[1]))
93 adx 30 {
94     sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
95     me.name, source_p->name, "KNOCK");
96     return;
97     }
98    
99 michael 885 if (!ConfigChannel.use_knock && MyClient(source_p))
100 adx 30 {
101 michael 885 sendto_one(source_p, form_str(ERR_KNOCKDISABLED),
102     me.name, source_p->name);
103 adx 30 return;
104     }
105    
106 michael 885 if ((chptr = hash_find_channel(parv[1])) == NULL)
107 adx 30 {
108 michael 885 sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
109     me.name, source_p->name, parv[1]);
110 adx 30 return;
111     }
112    
113     /* Normal channel, just be sure they aren't on it */
114     if (IsMember(source_p, chptr))
115     {
116 michael 885 sendto_one(source_p, form_str(ERR_KNOCKONCHAN), me.name,
117     source_p->name, chptr->chname);
118 adx 30 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 michael 885 sendto_one(source_p, form_str(ERR_CHANOPEN), me.name,
126     source_p->name, chptr->chname);
127 adx 30 return;
128     }
129    
130 michael 885 if (MyClient(source_p))
131 adx 30 {
132 michael 886 /*
133     * Don't allow a knock if the user is banned, or the channel is private
134     */
135     if (PrivateChannel(chptr) || is_banned(chptr, source_p))
136 michael 885 {
137     sendto_one(source_p, form_str(ERR_CANNOTSENDTOCHAN),
138     me.name, source_p->name, chptr->chname);
139     return;
140     }
141 adx 30
142 michael 885 /*
143     * flood protection:
144     * allow one knock per user per knock_delay
145     * allow one knock per channel per knock_delay_channel
146     *
147     * we only limit local requests..
148     */
149     if ((source_p->localClient->last_knock + ConfigChannel.knock_delay) >
150     CurrentTime)
151     {
152     sendto_one(source_p, form_str(ERR_TOOMANYKNOCK), me.name,
153     source_p->name, chptr->chname, "user");
154     return;
155     }
156 adx 30
157 michael 885 if ((chptr->last_knock + ConfigChannel.knock_delay_channel) > CurrentTime)
158     {
159     sendto_one(source_p, form_str(ERR_TOOMANYKNOCK), me.name,
160     source_p->name, chptr->chname, "channel");
161     return;
162     }
163 adx 30
164 michael 885 source_p->localClient->last_knock = CurrentTime;
165 adx 30
166 michael 885 sendto_one(source_p, form_str(RPL_KNOCKDLVR), me.name,
167     source_p->name, chptr->chname);
168     }
169 adx 30
170     chptr->last_knock = CurrentTime;
171    
172 michael 885 if (ConfigChannel.use_knock)
173     sendto_channel_local(CHFL_CHANOP, NO, chptr, form_str(RPL_KNOCK),
174     me.name, chptr->chname, chptr->chname,
175     source_p->name, source_p->username,
176     source_p->host);
177 adx 30
178 michael 885 sendto_server(client_p, chptr, CAP_KNOCK|CAP_TS6, NOCAPS,
179 michael 886 ":%s KNOCK %s", ID(source_p), chptr->chname);
180 michael 885 sendto_server(client_p, chptr, CAP_KNOCK, CAP_TS6,
181 michael 886 ":%s KNOCK %s", source_p->name, chptr->chname);
182 adx 30 }

Properties

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