ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/m_knock.c
Revision: 1178
Committed: Mon Aug 15 08:11:31 2011 UTC (12 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 5187 byte(s)
Log Message:
- Cleanup and restore older parts of the irc-command parser.
  Gives back ability to specify maximum amount of parameters
  that are processed within a command.

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

Properties

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