ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_knock.c
Revision: 8752
Committed: Tue Jan 1 11:07:01 2019 UTC (5 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 4781 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-2019 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 const char *const name = parv[1];
60
61 if (EmptyString(name))
62 {
63 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "KNOCK");
64 return 0;
65 }
66
67 struct Channel *chptr;
68 if ((chptr = hash_find_channel(name)) == NULL)
69 {
70 sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, name);
71 return 0;
72 }
73
74 /* Normal channel, just be sure they aren't on it. */
75 if (IsMember(source_p, chptr))
76 {
77 sendto_one_numeric(source_p, &me, ERR_KNOCKONCHAN, chptr->name);
78 return 0;
79 }
80
81 if (!((chptr->mode.mode & MODE_INVITEONLY) || chptr->mode.key[0] ||
82 (chptr->mode.limit && dlink_list_length(&chptr->members) >=
83 chptr->mode.limit)))
84 {
85 sendto_one_numeric(source_p, &me, ERR_CHANOPEN, chptr->name);
86 return 0;
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(chptr) || is_banned(chptr, source_p) == true)
95 {
96 sendto_one_numeric(source_p, &me, ERR_CANNOTSENDTOCHAN, chptr->name);
97 return 0;
98 }
99
100 if ((source_p->connection->knock.last_attempt + ConfigChannel.knock_client_time) < CurrentTime)
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, chptr->name, "user");
106 return 0;
107 }
108
109 if ((chptr->last_knock + ConfigChannel.knock_delay_channel) > CurrentTime)
110 {
111 sendto_one_numeric(source_p, &me, ERR_TOOMANYKNOCK, chptr->name, "channel");
112 return 0;
113 }
114
115 source_p->connection->knock.last_attempt = CurrentTime;
116 source_p->connection->knock.count++;
117
118 sendto_one_numeric(source_p, &me, RPL_KNOCKDLVR, chptr->name);
119 }
120
121 chptr->last_knock = CurrentTime;
122 sendto_channel_local(NULL, chptr, CHFL_CHANOP | CHFL_HALFOP, 0, 0,
123 ":%s NOTICE %%%s :KNOCK: %s (%s [%s@%s] has asked for an invite)",
124 me.name, chptr->name, chptr->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, chptr->name);
131 return 0;
132 }
133
134 static struct Message knock_msgtab =
135 {
136 .cmd = "KNOCK",
137 .args_min = 2,
138 .args_max = MAXPARA,
139 .handlers[UNREGISTERED_HANDLER] = m_unregistered,
140 .handlers[CLIENT_HANDLER] = m_knock,
141 .handlers[SERVER_HANDLER] = m_knock,
142 .handlers[ENCAP_HANDLER] = m_ignore,
143 .handlers[OPER_HANDLER] = m_knock
144 };
145
146 static void
147 module_init(void)
148 {
149 mod_add_cmd(&knock_msgtab);
150 capab_add("KNOCK", CAPAB_KNOCK);
151 isupport_add("KNOCK", NULL, -1);
152 }
153
154 static void
155 module_exit(void)
156 {
157 mod_del_cmd(&knock_msgtab);
158 capab_del("KNOCK");
159 isupport_delete("KNOCK");
160 }
161
162 struct module module_entry =
163 {
164 .version = "$Revision$",
165 .modinit = module_init,
166 .modexit = module_exit,
167 };

Properties

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