ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_knock.c
Revision: 9101
Committed: Wed Jan 1 09:58:45 2020 UTC (6 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 4886 byte(s)
Log Message:
- Bump copyright years everywhere

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1998-2020 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 void
57 m_knock(struct Client *source_p, int parc, char *parv[])
58 {
59 const char *const name = parv[1];
60
61 if (EmptyString(name))
62 {
63 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "KNOCK");
64 return;
65 }
66
67 struct Channel *channel;
68 if ((channel = hash_find_channel(name)) == NULL)
69 {
70 sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, name);
71 return;
72 }
73
74 /* Normal channel, just be sure they aren't on it. */
75 if (IsMember(source_p, channel))
76 {
77 sendto_one_numeric(source_p, &me, ERR_KNOCKONCHAN, channel->name);
78 return;
79 }
80
81 if (!((channel->mode.mode & MODE_INVITEONLY) || channel->mode.key[0] ||
82 (channel->mode.limit && dlink_list_length(&channel->members) >=
83 channel->mode.limit)))
84 {
85 sendto_one_numeric(source_p, &me, ERR_CHANOPEN, channel->name);
86 return;
87 }
88
89 if (MyClient(source_p))
90 {
91 /*
92 * Don't allow a knock if the user is banned, or the channel is private.
93 */
94 if (PrivateChannel(channel) || is_banned(channel, source_p) == true)
95 {
96 sendto_one_numeric(source_p, &me, ERR_CANNOTSENDTOCHAN, channel->name);
97 return;
98 }
99
100 if ((source_p->connection->knock.last_attempt + ConfigChannel.knock_client_time) < event_base->time.sec_monotonic)
101 source_p->connection->knock.count = 0;
102
103 if (source_p->connection->knock.count > ConfigChannel.knock_client_count)
104 {
105 sendto_one_numeric(source_p, &me, ERR_TOOMANYKNOCK, channel->name, "user");
106 return;
107 }
108
109 if ((channel->last_knock_time + ConfigChannel.knock_delay_channel) > event_base->time.sec_monotonic)
110 {
111 sendto_one_numeric(source_p, &me, ERR_TOOMANYKNOCK, channel->name, "channel");
112 return;
113 }
114
115 source_p->connection->knock.last_attempt = event_base->time.sec_monotonic;
116 source_p->connection->knock.count++;
117
118 sendto_one_numeric(source_p, &me, RPL_KNOCKDLVR, channel->name);
119 }
120
121 channel->last_knock_time = event_base->time.sec_monotonic;
122 sendto_channel_local(NULL, channel, CHFL_CHANOP | CHFL_HALFOP, 0, 0,
123 ":%s NOTICE %%%s :KNOCK: %s (%s [%s@%s] has asked for an invite)",
124 me.name, channel->name, channel->name,
125 source_p->name,
126 source_p->username,
127 source_p->host);
128
129 sendto_server(source_p, CAPAB_KNOCK, 0, ":%s KNOCK %s",
130 source_p->id, channel->name);
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