/[svn]/ircd-hybrid/branches/8.2.x/modules/m_invite.c
ViewVC logotype

Contents of /ircd-hybrid/branches/8.2.x/modules/m_invite.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7329 - (show annotations)
Thu Feb 18 21:07:50 2016 UTC (6 years, 11 months ago) by michael
File MIME type: text/x-chdr
File size: 7777 byte(s)
- Now that we got time_t to work nicely on openbsd with snprintf's conversion specifiers,
  we ran into a similiar issue on Raspbian/ARMv7's time_t which is of signed 32 bit and
  doesn't cope at all with %j. Instead of doing tricks, get rid of time_t everywhere and
  forever and use uintmax_t instead which has at least a 'standardized' conversion specifier
  associated with it.

1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2016 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 if ((chptr->last_invite + ConfigChannel.invite_delay_channel) > CurrentTime)
123 {
124 sendto_one_numeric(source_p, &me, ERR_TOOMANYINVITE, chptr->name, "channel");
125 return 0;
126 }
127
128 source_p->connection->invite.last_attempt = CurrentTime;
129 source_p->connection->invite.count++;
130
131 sendto_one_numeric(source_p, &me, RPL_INVITING, target_p->name, chptr->name);
132
133 if (target_p->away[0])
134 sendto_one_numeric(source_p, &me, RPL_AWAY, target_p->name, target_p->away);
135
136 chptr->last_invite = CurrentTime;
137
138 if (MyConnect(target_p))
139 {
140 sendto_one(target_p, ":%s!%s@%s INVITE %s :%s",
141 source_p->name, source_p->username,
142 source_p->host,
143 target_p->name, chptr->name);
144
145 if (chptr->mode.mode & MODE_INVITEONLY)
146 add_invite(chptr, target_p); /* Add the invite if channel is +i */
147 }
148
149 if (chptr->mode.mode & MODE_INVITEONLY)
150 {
151 sendto_channel_local(NULL, chptr, CHFL_CHANOP | CHFL_HALFOP, 0, CAP_INVITE_NOTIFY,
152 ":%s NOTICE %%%s :%s is inviting %s to %s.",
153 me.name, chptr->name, source_p->name, target_p->name, chptr->name);
154 sendto_channel_local(NULL, chptr, CHFL_CHANOP | CHFL_HALFOP, CAP_INVITE_NOTIFY, 0,
155 ":%s!%s@%s INVITE %s %s", source_p->name, source_p->username,
156 source_p->host, target_p->name, chptr->name);
157 }
158
159 sendto_server(source_p, 0, 0, ":%s INVITE %s %s %ju",
160 source_p->id, target_p->id,
161 chptr->name, chptr->creationtime);
162 return 0;
163 }
164
165 /*! \brief INVITE command handler
166 *
167 * \param source_p Pointer to allocated Client struct from which the message
168 * originally comes from. This can be a local or remote client.
169 * \param parc Integer holding the number of supplied arguments.
170 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
171 * pointers.
172 * \note Valid arguments for this command are:
173 * - parv[0] = command
174 * - parv[1] = user to invite
175 * - parv[2] = channel name
176 * - parv[3] = channel timestamp
177 */
178 static int
179 ms_invite(struct Client *source_p, int parc, char *parv[])
180 {
181 struct Client *target_p = NULL;
182 struct Channel *chptr = NULL;
183
184 if (parc < 3 || EmptyString(parv[2]))
185 return 0;
186
187 if ((target_p = find_person(source_p, parv[1])) == NULL)
188 return 0;
189
190 if ((chptr = hash_find_channel(parv[2])) == NULL)
191 return 0;
192
193 if (IsMember(target_p, chptr))
194 return 0;
195
196 if (parc > 3 && IsDigit(*parv[3]))
197 if (strtoumax(parv[3], NULL, 10) > chptr->creationtime)
198 return 0;
199
200 chptr->last_invite = CurrentTime;
201
202 if (MyConnect(target_p))
203 {
204 sendto_one(target_p, ":%s!%s@%s INVITE %s :%s",
205 source_p->name, source_p->username,
206 source_p->host,
207 target_p->name, chptr->name);
208
209 if (chptr->mode.mode & MODE_INVITEONLY)
210 add_invite(chptr, target_p); /* Add the invite if channel is +i */
211 }
212
213 if (chptr->mode.mode & MODE_INVITEONLY)
214 {
215 sendto_channel_local(NULL, chptr, CHFL_CHANOP | CHFL_HALFOP, 0, CAP_INVITE_NOTIFY,
216 ":%s NOTICE %%%s :%s is inviting %s to %s.",
217 me.name, chptr->name, source_p->name, target_p->name, chptr->name);
218 sendto_channel_local(NULL, chptr, CHFL_CHANOP | CHFL_HALFOP, CAP_INVITE_NOTIFY, 0,
219 ":%s!%s@%s INVITE %s %s", source_p->name, source_p->username,
220 source_p->host, target_p->name, chptr->name);
221 }
222
223 sendto_server(source_p, 0, 0, ":%s INVITE %s %s %ju",
224 source_p->id, target_p->id,
225 chptr->name, chptr->creationtime);
226 return 0;
227 }
228
229
230 static struct Message invite_msgtab =
231 {
232 .cmd = "INVITE",
233 .args_max = MAXPARA,
234 .handlers[UNREGISTERED_HANDLER] = m_unregistered,
235 .handlers[CLIENT_HANDLER] = m_invite,
236 .handlers[SERVER_HANDLER] = ms_invite,
237 .handlers[ENCAP_HANDLER] = m_ignore,
238 .handlers[OPER_HANDLER] = m_invite
239 };
240
241 static void
242 module_init(void)
243 {
244 mod_add_cmd(&invite_msgtab);
245 }
246
247 static void
248 module_exit(void)
249 {
250 mod_del_cmd(&invite_msgtab);
251 }
252
253 struct module module_entry =
254 {
255 .version = "$Revision$",
256 .modinit = module_init,
257 .modexit = module_exit,
258 };

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28