ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_invite.c
Revision: 6782
Committed: Sun Nov 15 18:49:32 2015 UTC (9 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 7504 byte(s)
Log Message:
- Use the %ju conversion specifier for time_t and get rid of these non-portable (unsigned long) casts; replace some uint64_t with uintmax_t

File Contents

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

Properties

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