ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/m_knock.c
Revision: 1230
Committed: Thu Sep 22 19:41:19 2011 UTC (12 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 5306 byte(s)
Log Message:
- cleanup module loader. Make module api more flexible

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

Properties

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