ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_invite.c
Revision: 9857
Committed: Fri Jan 1 04:43:22 2021 UTC (3 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 7895 byte(s)
Log Message:
- Bump copyright years

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2021 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_invite.c
23 * \brief Includes required functions for processing the INVITE command.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "channel.h"
30 #include "channel_invite.h"
31 #include "channel_mode.h"
32 #include "client.h"
33 #include "conf.h"
34 #include "hash.h"
35 #include "irc_string.h"
36 #include "ircd.h"
37 #include "numeric.h"
38 #include "send.h"
39 #include "parse.h"
40 #include "modules.h"
41 #include "packet.h"
42
43
44 /*! \brief INVITE command handler
45 *
46 * \param source_p Pointer to allocated Client struct from which the message
47 * originally comes from. This can be a local or remote client.
48 * \param parc Integer holding the number of supplied arguments.
49 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
50 * pointers.
51 * \note Valid arguments for this command are:
52 * - parv[0] = command
53 * - parv[1] = user to invite
54 * - parv[2] = channel name
55 */
56 static void
57 m_invite(struct Client *source_p, int parc, char *parv[])
58 {
59 if (parc < 2)
60 {
61 dlink_node *node;
62
63 DLINK_FOREACH(node, source_p->connection->invited.head)
64 {
65 const struct Invite *const invite = node->data;
66 sendto_one_numeric(source_p, &me, RPL_INVITELIST, invite->channel->name);
67 }
68
69 sendto_one_numeric(source_p, &me, RPL_ENDOFINVITELIST);
70 return;
71 }
72
73 if (parc < 3 || EmptyString(parv[2]))
74 {
75 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "INVITE");
76 return;
77 }
78
79 struct Client *target_p = find_person(source_p, parv[1]);
80 if (target_p == NULL)
81 {
82 sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, parv[1]);
83 return;
84 }
85
86 struct Channel *channel = hash_find_channel(parv[2]);
87 if (channel == NULL)
88 {
89 sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[2]);
90 return;
91 }
92
93 struct ChannelMember *member = member_find_link(source_p, channel);
94 if (member == NULL)
95 {
96 sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, channel->name);
97 return;
98 }
99
100 if (member_has_flags(member, CHFL_CHANOP | CHFL_HALFOP) == false)
101 {
102 sendto_one_numeric(source_p, &me, ERR_CHANOPRIVSNEEDED, channel->name);
103 return;
104 }
105
106 if (member_find_link(target_p, channel))
107 {
108 sendto_one_numeric(source_p, &me, ERR_USERONCHANNEL, target_p->name, channel->name);
109 return;
110 }
111
112 if ((source_p->connection->invite.last_attempt + ConfigChannel.invite_client_time) < event_base->time.sec_monotonic)
113 source_p->connection->invite.count = 0;
114
115 if (source_p->connection->invite.count > ConfigChannel.invite_client_count)
116 {
117 sendto_one_numeric(source_p, &me, ERR_TOOMANYINVITE, channel->name, "user");
118 return;
119 }
120
121 if ((channel->last_invite_time + ConfigChannel.invite_delay_channel) > event_base->time.sec_monotonic)
122 {
123 sendto_one_numeric(source_p, &me, ERR_TOOMANYINVITE, channel->name, "channel");
124 return;
125 }
126
127 source_p->connection->invite.last_attempt = event_base->time.sec_monotonic;
128 source_p->connection->invite.count++;
129
130 sendto_one_numeric(source_p, &me, RPL_INVITING, target_p->name, channel->name);
131
132 if (target_p->away[0])
133 sendto_one_numeric(source_p, &me, RPL_AWAY, target_p->name, target_p->away);
134
135 channel->last_invite_time = event_base->time.sec_monotonic;
136
137 if (MyConnect(target_p))
138 {
139 sendto_one(target_p, ":%s!%s@%s INVITE %s :%s",
140 source_p->name, source_p->username,
141 source_p->host,
142 target_p->name, channel->name);
143
144 if (HasCMode(channel, MODE_INVITEONLY))
145 invite_add(channel, target_p); /* Add the invite if channel is +i */
146 }
147
148 if (HasCMode(channel, MODE_INVITEONLY))
149 {
150 sendto_channel_local(NULL, channel, CHFL_CHANOP | CHFL_HALFOP, 0, CAP_INVITE_NOTIFY,
151 ":%s NOTICE %%%s :%s is inviting %s to %s.",
152 me.name, channel->name, source_p->name, target_p->name, channel->name);
153 sendto_channel_local(NULL, channel, CHFL_CHANOP | CHFL_HALFOP, CAP_INVITE_NOTIFY, 0,
154 ":%s!%s@%s INVITE %s %s", source_p->name, source_p->username,
155 source_p->host, target_p->name, channel->name);
156 }
157
158 sendto_server(source_p, 0, 0, ":%s INVITE %s %s %ju",
159 source_p->id, target_p->id,
160 channel->name, channel->creation_time);
161 }
162
163 /*! \brief INVITE command handler
164 *
165 * \param source_p Pointer to allocated Client struct from which the message
166 * originally comes from. This can be a local or remote client.
167 * \param parc Integer holding the number of supplied arguments.
168 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
169 * pointers.
170 * \note Valid arguments for this command are:
171 * - parv[0] = command
172 * - parv[1] = user to invite
173 * - parv[2] = channel name
174 * - parv[3] = channel timestamp
175 */
176 static void
177 ms_invite(struct Client *source_p, int parc, char *parv[])
178 {
179 struct Client *target_p = find_person(source_p, parv[1]);
180 if (target_p == NULL)
181 return;
182
183 struct Channel *channel = hash_find_channel(parv[2]);
184 if (channel == NULL)
185 return;
186
187 if (member_find_link(target_p, channel))
188 return;
189
190 if (strtoumax(parv[3], NULL, 10) > channel->creation_time)
191 return;
192
193 channel->last_invite_time = event_base->time.sec_monotonic;
194
195 if (MyConnect(target_p))
196 {
197 sendto_one(target_p, ":%s!%s@%s INVITE %s :%s",
198 source_p->name, source_p->username,
199 source_p->host,
200 target_p->name, channel->name);
201
202 if (HasCMode(channel, MODE_INVITEONLY))
203 invite_add(channel, target_p); /* Add the invite if channel is +i */
204 }
205
206 if (HasCMode(channel, MODE_INVITEONLY))
207 {
208 sendto_channel_local(NULL, channel, CHFL_CHANOP | CHFL_HALFOP, 0, CAP_INVITE_NOTIFY,
209 ":%s NOTICE %%%s :%s is inviting %s to %s.",
210 me.name, channel->name, source_p->name, target_p->name, channel->name);
211 sendto_channel_local(NULL, channel, CHFL_CHANOP | CHFL_HALFOP, CAP_INVITE_NOTIFY, 0,
212 ":%s!%s@%s INVITE %s %s", source_p->name, source_p->username,
213 source_p->host, target_p->name, channel->name);
214 }
215
216 sendto_server(source_p, 0, 0, ":%s INVITE %s %s %ju",
217 source_p->id, target_p->id,
218 channel->name, channel->creation_time);
219 }
220
221
222 static struct Message invite_msgtab =
223 {
224 .cmd = "INVITE",
225 .handlers[UNREGISTERED_HANDLER] = { .handler = m_unregistered },
226 .handlers[CLIENT_HANDLER] = { .handler = m_invite, .end_grace_period = true },
227 .handlers[SERVER_HANDLER] = { .handler = ms_invite, .args_min = 4 },
228 .handlers[ENCAP_HANDLER] = { .handler = m_ignore },
229 .handlers[OPER_HANDLER] = { .handler = m_invite, .end_grace_period = true }
230 };
231
232 static void
233 module_init(void)
234 {
235 mod_add_cmd(&invite_msgtab);
236 }
237
238 static void
239 module_exit(void)
240 {
241 mod_del_cmd(&invite_msgtab);
242 }
243
244 struct module module_entry =
245 {
246 .version = "$Revision$",
247 .modinit = module_init,
248 .modexit = module_exit,
249 };

Properties

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