ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_knock.c
Revision: 3186
Committed: Thu Mar 20 18:09:34 2014 UTC (11 years, 5 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/modules/m_knock.c
File size: 4721 byte(s)
Log Message:
- Get rid of the ID() macro

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

Properties

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