ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_knock.c
Revision: 4588
Committed: Tue Aug 26 15:59:07 2014 UTC (11 years ago) by michael
Content type: text/x-csrc
File size: 4677 byte(s)
Log Message:
- Renamed 'localClient' Client structure member to just 'connection'

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2820 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 2820 * Copyright (c) 1998-2014 ircd-hybrid development team
5 adx 30 *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18 michael 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 2820 /*! \file m_knock.c
23     * \brief Includes required functions for processing the KNOCK command.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28 michael 1011 #include "list.h"
29 adx 30 #include "channel.h"
30     #include "channel_mode.h"
31     #include "client.h"
32     #include "hash.h"
33     #include "irc_string.h"
34     #include "ircd.h"
35     #include "numeric.h"
36     #include "send.h"
37 michael 1309 #include "conf.h"
38 adx 30 #include "parse.h"
39     #include "modules.h"
40 michael 3347 #include "server.h"
41     #include "user.h"
42 adx 30
43    
44 michael 3344 /*! \brief KNOCK command handler
45 adx 30 *
46 michael 3344 * \param source_p Pointer to allocated Client struct from which the message
47     * originally comes from. This can be a local or remote client.
48     * \param parc Integer holding the number of supplied arguments.
49     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
50     * pointers.
51     * \note Valid arguments for this command are:
52     * - parv[0] = command
53     * - parv[1] = channel name
54 adx 30 */
55 michael 2820 static int
56 michael 3156 m_knock(struct Client *source_p, int parc, char *parv[])
57 adx 30 {
58 michael 885 struct Channel *chptr = NULL;
59 adx 30
60 michael 885 if (EmptyString(parv[1]))
61 adx 30 {
62 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "KNOCK");
63 michael 2820 return 0;
64 adx 30 }
65    
66 michael 885 if ((chptr = hash_find_channel(parv[1])) == NULL)
67 adx 30 {
68 michael 3109 sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[1]);
69 michael 2820 return 0;
70 adx 30 }
71    
72     /* Normal channel, just be sure they aren't on it */
73     if (IsMember(source_p, chptr))
74     {
75 michael 3109 sendto_one_numeric(source_p, &me, ERR_KNOCKONCHAN, chptr->chname);
76 michael 2820 return 0;
77 adx 30 }
78    
79 michael 3481 if (!((chptr->mode.mode & MODE_INVITEONLY) || chptr->mode.key[0] ||
80 adx 30 (chptr->mode.limit && dlink_list_length(&chptr->members) >=
81     chptr->mode.limit)))
82     {
83 michael 3109 sendto_one_numeric(source_p, &me, ERR_CHANOPEN, chptr->chname);
84 michael 2820 return 0;
85 adx 30 }
86    
87 michael 885 if (MyClient(source_p))
88 adx 30 {
89 michael 886 /*
90     * Don't allow a knock if the user is banned, or the channel is private
91     */
92     if (PrivateChannel(chptr) || is_banned(chptr, source_p))
93 michael 885 {
94 michael 3109 sendto_one_numeric(source_p, &me, ERR_CANNOTSENDTOCHAN, chptr->chname);
95 michael 2820 return 0;
96 michael 885 }
97 adx 30
98 michael 4588 if ((source_p->connection->knock.last_attempt + ConfigChannel.knock_client_time) < CurrentTime)
99     source_p->connection->knock.count = 0;
100 michael 3860
101 michael 4588 if (source_p->connection->knock.count > ConfigChannel.knock_client_count)
102 michael 885 {
103 michael 3109 sendto_one_numeric(source_p, &me, ERR_TOOMANYKNOCK, chptr->chname, "user");
104 michael 2820 return 0;
105 michael 885 }
106 adx 30
107 michael 885 if ((chptr->last_knock + ConfigChannel.knock_delay_channel) > CurrentTime)
108     {
109 michael 3109 sendto_one_numeric(source_p, &me, ERR_TOOMANYKNOCK, chptr->chname, "channel");
110 michael 2820 return 0;
111 michael 885 }
112 adx 30
113 michael 4588 source_p->connection->knock.last_attempt = CurrentTime;
114     source_p->connection->knock.count++;
115 michael 4081
116 michael 3109 sendto_one_numeric(source_p, &me, RPL_KNOCKDLVR, chptr->chname);
117 michael 885 }
118 adx 30
119     chptr->last_knock = CurrentTime;
120    
121 michael 1496 sendto_channel_local(CHFL_CHANOP, 0, chptr,
122     ":%s NOTICE @%s :KNOCK: %s (%s [%s@%s] has asked for an invite)",
123 michael 1495 me.name, chptr->chname, chptr->chname,
124 michael 1496 source_p->name,
125     source_p->username,
126 michael 1495 source_p->host);
127 adx 30
128 michael 3186 sendto_server(source_p, CAP_KNOCK, NOCAPS, ":%s KNOCK %s",
129     source_p->id, chptr->chname);
130 michael 2820 return 0;
131 adx 30 }
132 michael 1230
133 michael 2820 static struct Message knock_msgtab =
134     {
135 michael 4545 "KNOCK", NULL, 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
136 michael 1230 { m_unregistered, m_knock, m_knock, m_ignore, m_knock, m_ignore }
137     };
138    
139     static void
140     module_init(void)
141     {
142     mod_add_cmd(&knock_msgtab);
143     add_capability("KNOCK", CAP_KNOCK, 1);
144     add_isupport("KNOCK", NULL, -1);
145     }
146    
147     static void
148     module_exit(void)
149     {
150     mod_del_cmd(&knock_msgtab);
151     delete_capability("KNOCK");
152     delete_isupport("KNOCK");
153     }
154    
155 michael 2820 struct module module_entry =
156     {
157 michael 1230 .node = { NULL, NULL, NULL },
158     .name = NULL,
159     .version = "$Revision$",
160     .handle = NULL,
161     .modinit = module_init,
162     .modexit = module_exit,
163     .flags = 0
164     };

Properties

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