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: 8280
Committed: Tue Feb 20 19:30:33 2018 UTC (8 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 4751 byte(s)
Log Message:
- Update copyright years

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1998-2018 ircd-hybrid development team
5 *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
20 */
21
22 /*! \file m_knock.c
23 * \brief Includes required functions for processing the KNOCK command.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #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 #include "conf.h"
38 #include "parse.h"
39 #include "modules.h"
40 #include "server_capab.h"
41 #include "user.h"
42 #include "isupport.h"
43
44
45 /*! \brief KNOCK command handler
46 *
47 * \param source_p Pointer to allocated Client struct from which the message
48 * originally comes from. This can be a local or remote client.
49 * \param parc Integer holding the number of supplied arguments.
50 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
51 * pointers.
52 * \note Valid arguments for this command are:
53 * - parv[0] = command
54 * - parv[1] = channel name
55 */
56 static int
57 m_knock(struct Client *source_p, int parc, char *parv[])
58 {
59 struct Channel *chptr = NULL;
60
61 if (EmptyString(parv[1]))
62 {
63 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "KNOCK");
64 return 0;
65 }
66
67 if ((chptr = hash_find_channel(parv[1])) == NULL)
68 {
69 sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[1]);
70 return 0;
71 }
72
73 /* Normal channel, just be sure they aren't on it */
74 if (IsMember(source_p, chptr))
75 {
76 sendto_one_numeric(source_p, &me, ERR_KNOCKONCHAN, chptr->name);
77 return 0;
78 }
79
80 if (!((chptr->mode.mode & MODE_INVITEONLY) || chptr->mode.key[0] ||
81 (chptr->mode.limit && dlink_list_length(&chptr->members) >=
82 chptr->mode.limit)))
83 {
84 sendto_one_numeric(source_p, &me, ERR_CHANOPEN, chptr->name);
85 return 0;
86 }
87
88 if (MyClient(source_p))
89 {
90 /*
91 * Don't allow a knock if the user is banned, or the channel is private
92 */
93 if (PrivateChannel(chptr) || is_banned(chptr, source_p))
94 {
95 sendto_one_numeric(source_p, &me, ERR_CANNOTSENDTOCHAN, chptr->name);
96 return 0;
97 }
98
99 if ((source_p->connection->knock.last_attempt + ConfigChannel.knock_client_time) < CurrentTime)
100 source_p->connection->knock.count = 0;
101
102 if (source_p->connection->knock.count > ConfigChannel.knock_client_count)
103 {
104 sendto_one_numeric(source_p, &me, ERR_TOOMANYKNOCK, chptr->name, "user");
105 return 0;
106 }
107
108 if ((chptr->last_knock + ConfigChannel.knock_delay_channel) > CurrentTime)
109 {
110 sendto_one_numeric(source_p, &me, ERR_TOOMANYKNOCK, chptr->name, "channel");
111 return 0;
112 }
113
114 source_p->connection->knock.last_attempt = CurrentTime;
115 source_p->connection->knock.count++;
116
117 sendto_one_numeric(source_p, &me, RPL_KNOCKDLVR, chptr->name);
118 }
119
120 chptr->last_knock = CurrentTime;
121 sendto_channel_local(NULL, chptr, CHFL_CHANOP | CHFL_HALFOP, 0, 0,
122 ":%s NOTICE %%%s :KNOCK: %s (%s [%s@%s] has asked for an invite)",
123 me.name, chptr->name, chptr->name,
124 source_p->name,
125 source_p->username,
126 source_p->host);
127
128 sendto_server(source_p, CAPAB_KNOCK, 0, ":%s KNOCK %s",
129 source_p->id, chptr->name);
130 return 0;
131 }
132
133 static struct Message knock_msgtab =
134 {
135 .cmd = "KNOCK",
136 .args_min = 2,
137 .args_max = MAXPARA,
138 .handlers[UNREGISTERED_HANDLER] = m_unregistered,
139 .handlers[CLIENT_HANDLER] = m_knock,
140 .handlers[SERVER_HANDLER] = m_knock,
141 .handlers[ENCAP_HANDLER] = m_ignore,
142 .handlers[OPER_HANDLER] = m_knock
143 };
144
145 static void
146 module_init(void)
147 {
148 mod_add_cmd(&knock_msgtab);
149 capab_add("KNOCK", CAPAB_KNOCK);
150 isupport_add("KNOCK", NULL, -1);
151 }
152
153 static void
154 module_exit(void)
155 {
156 mod_del_cmd(&knock_msgtab);
157 capab_del("KNOCK");
158 isupport_delete("KNOCK");
159 }
160
161 struct module module_entry =
162 {
163 .version = "$Revision$",
164 .modinit = module_init,
165 .modexit = module_exit,
166 };

Properties

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