]> jfr.im git - irc/quakenet/snircd.git/blame - ircd/m_invite.c
Should be unsigned long for A
[irc/quakenet/snircd.git] / ircd / m_invite.c
CommitLineData
189935b1 1/*
2 * IRC - Internet Relay Chat, ircd/m_invite.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
5 *
6 * See file AUTHORS in IRC package for additional names of
7 * the programmers.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 1, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 * $Id: m_invite.c,v 1.25 2005/09/13 15:17:46 entrope Exp $
24 */
25
26/*
27 * m_functions execute protocol messages on this server:
28 *
29 * cptr is always NON-NULL, pointing to a *LOCAL* client
30 * structure (with an open socket connected!). This
31 * identifies the physical socket where the message
32 * originated (or which caused the m_function to be
33 * executed--some m_functions may call others...).
34 *
35 * sptr is the source of the message, defined by the
36 * prefix part of the message if present. If not
37 * or prefix not found, then sptr==cptr.
38 *
39 * (!IsServer(cptr)) => (cptr == sptr), because
40 * prefixes are taken *only* from servers...
41 *
42 * (IsServer(cptr))
43 * (sptr == cptr) => the message didn't
44 * have the prefix.
45 *
46 * (sptr != cptr && IsServer(sptr) means
47 * the prefix specified servername. (?)
48 *
49 * (sptr != cptr && !IsServer(sptr) means
50 * that message originated from a remote
51 * user (not local).
52 *
53 * combining
54 *
55 * (!IsServer(sptr)) means that, sptr can safely
56 * taken as defining the target structure of the
57 * message in this server.
58 *
59 * *Always* true (if 'parse' and others are working correct):
60 *
61 * 1) sptr->from == cptr (note: cptr->from == cptr)
62 *
63 * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
64 * *cannot* be a local connection, unless it's
65 * actually cptr!). [MyConnect(x) should probably
66 * be defined as (x == x->from) --msa ]
67 *
68 * parc number of variable parameter strings (if zero,
69 * parv is allowed to be NULL)
70 *
71 * parv a NULL terminated list of parameter pointers,
72 *
73 * parv[0], sender (prefix string), if not present
74 * this points to an empty string.
75 * parv[1]...parv[parc-1]
76 * pointers to additional parameters
77 * parv[parc] == NULL, *always*
78 *
79 * note: it is guaranteed that parv[0]..parv[parc-1] are all
80 * non-NULL pointers.
81 */
82#include "config.h"
83
84#include "channel.h"
85#include "client.h"
86#include "hash.h"
87#include "ircd.h"
88#include "ircd_features.h"
89#include "ircd_log.h"
90#include "ircd_reply.h"
91#include "ircd_string.h"
92#include "list.h"
93#include "msg.h"
94#include "numeric.h"
95#include "numnicks.h"
96#include "s_user.h"
97#include "send.h"
98#include "struct.h"
99
100/* #include <assert.h> -- Now using assert in ircd_log.h */
101
102/*
103 * m_invite - generic message handler
104 *
105 * parv[0] - sender prefix
106 * parv[1] - user to invite
107 * parv[2] - channel name
108 *
109 * - INVITE now is accepted only if who does it is chanop (this of course
110 * implies that channel must exist and he must be on it).
111 *
112 * - On the other side it IS processed even if channel is NOT invite only
113 * leaving room for other enhancements like inviting banned ppl. -- Nemesi
114 *
115 * - Invite with no parameters now lists the channels you are invited to.
116 * - Isomer 23 Oct 99
117 */
118int m_invite(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
119{
120 struct Client *acptr;
121 struct Channel *chptr;
122
123 if (parc < 2 ) {
124 /*
125 * list the channels you have an invite to.
126 */
127 struct SLink *lp;
128 for (lp = cli_user(sptr)->invited; lp; lp = lp->next)
129 send_reply(cptr, RPL_INVITELIST, lp->value.chptr->chname);
130 send_reply(cptr, RPL_ENDOFINVITELIST);
131 return 0;
132 }
133
134 if (parc < 3 || EmptyString(parv[2]))
135 return need_more_params(sptr, "INVITE");
136
137 if (!(acptr = FindUser(parv[1]))) {
138 send_reply(sptr, ERR_NOSUCHNICK, parv[1]);
139 return 0;
140 }
141
142 if (is_silenced(sptr, acptr))
143 return 0;
144
145 if (!IsChannelName(parv[2])
146 || !strIsIrcCh(parv[2])
147 || !(chptr = FindChannel(parv[2]))) {
148 send_reply(sptr, ERR_NOSUCHCHANNEL, parv[2]);
149 return 0;
150 }
151
152 if (!find_channel_member(sptr, chptr)) {
153 send_reply(sptr, ERR_NOTONCHANNEL, chptr->chname);
154 return 0;
155 }
156
157 if (find_channel_member(acptr, chptr)) {
158 send_reply(sptr, ERR_USERONCHANNEL, cli_name(acptr), chptr->chname);
159 return 0;
160 }
161
162 if (!is_chan_op(sptr, chptr)) {
163 send_reply(sptr, ERR_CHANOPRIVSNEEDED, chptr->chname);
164 return 0;
165 }
166
167 /* If we get here, it was a VALID and meaningful INVITE */
168
d8e74551 169 if (IsAccountOnly(acptr) && !IsAccount(sptr) && !IsOper(sptr)) {
170 send_reply(sptr, ERR_ACCOUNTONLY, cli_name(acptr));
171 return 0;
172 }
173
189935b1 174 if (check_target_limit(sptr, acptr, cli_name(acptr), 0))
175 return 0;
176
177 send_reply(sptr, RPL_INVITING, cli_name(acptr), chptr->chname);
178
179 if (cli_user(acptr)->away)
180 send_reply(sptr, RPL_AWAY, cli_name(acptr), cli_user(acptr)->away);
181
182 if (MyConnect(acptr)) {
183 add_invite(acptr, chptr);
184 sendcmdto_one(sptr, CMD_INVITE, acptr, "%s %H", cli_name(acptr), chptr);
185 } else if (!IsLocalChannel(chptr->chname)) {
186 sendcmdto_one(sptr, CMD_INVITE, acptr, "%s %H %Tu", cli_name(acptr), chptr,
187 chptr->creationtime);
188 }
189
190 if (!IsLocalChannel(chptr->chname) || MyConnect(acptr)) {
191 if (feature_bool(FEAT_ANNOUNCE_INVITES)) {
192 /* Announce to channel operators. */
193 sendcmdto_channel_butserv_butone(&his, get_error_numeric(RPL_ISSUEDINVITE)->str,
194 NULL, chptr, sptr, SKIP_NONOPS,
195 "%H %C %C :%C has been invited by %C",
196 chptr, acptr, sptr, acptr, sptr);
197 /* Announce to servers with channel operators. */
198 sendcmdto_channel_servers_butone(sptr, NULL, TOK_INVITE, chptr, acptr, SKIP_NONOPS,
199 "%s %H %Tu", cli_name(acptr),
200 chptr, chptr->creationtime);
201 }
202 }
203
204 return 0;
205}
206
207/*
208 * ms_invite - server message handler
209 *
210 * parv[0] - sender prefix
211 * parv[1] - user to invite
212 * parv[2] - channel name
213 * parv[3] - (optional) channel timestamp
214 *
215 * - INVITE now is accepted only if who does it is chanop (this of course
216 * implies that channel must exist and he must be on it).
217 *
218 * - On the other side it IS processed even if channel is NOT invite only
219 * leaving room for other enhancements like inviting banned ppl. -- Nemesi
220 *
221 * - Invite with no parameters now lists the channels you are invited to.
222 * - Isomer 23 Oct 99
223 *
224 * - Invite with too-late timestamp, or with no timestamp from a bursting
225 * server, is silently discarded. - Entrope 19 Jan 05
226 */
227int ms_invite(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
228{
229 struct Client *acptr;
230 struct Channel *chptr;
231 time_t invite_ts;
232
233 if (IsServer(sptr)) {
234 /*
235 * this will blow up if we get an invite from a server
236 * we look for channel membership in sptr below.
237 */
238 return protocol_violation(sptr,"Server attempting to invite");
239 }
240 if (parc < 3 || EmptyString(parv[2])) {
241 /*
242 * should have been handled upstream, ignore it.
243 */
244 protocol_violation(sptr,"Too few arguments to invite");
245 return need_more_params(sptr,"INVITE");
246 }
247 if (!IsGlobalChannel(parv[2])) {
248 /*
249 * should not be sent
250 */
251 return protocol_violation(sptr, "Invite to a non-standard channel %s",parv[2]);
252 }
253 if (!(acptr = FindUser(parv[1]))) {
254 send_reply(sptr, ERR_NOSUCHNICK, parv[1]);
255 return 0;
256 }
257
258 if (!(chptr = FindChannel(parv[2]))) {
259 /*
260 * allow invites to non existent channels, bleah
261 * avoid JOIN, INVITE, PART abuse
262 */
263 sendcmdto_one(sptr, CMD_INVITE, acptr, "%C :%s", acptr, parv[2]);
264 return 0;
265 }
266
267 if (parc > 3) {
268 invite_ts = atoi(parv[3]);
269 if (invite_ts > chptr->creationtime)
270 return 0;
271 } else if (IsBurstOrBurstAck(cptr))
272 return 0;
273
274 if (!IsChannelService(sptr) && !find_channel_member(sptr, chptr)) {
275 send_reply(sptr, ERR_NOTONCHANNEL, chptr->chname);
276 return 0;
277 }
278
279 if (find_channel_member(acptr, chptr)) {
280 send_reply(sptr, ERR_USERONCHANNEL, cli_name(acptr), chptr->chname);
281 return 0;
282 }
283
284 if (is_silenced(sptr, acptr))
285 return 0;
286
287 if (MyConnect(acptr)) {
288 add_invite(acptr, chptr);
289 sendcmdto_one(sptr, CMD_INVITE, acptr, "%s %H", cli_name(acptr), chptr);
290 } else {
291 sendcmdto_one(sptr, CMD_INVITE, acptr, "%s %H %Tu", cli_name(acptr), chptr,
292 chptr->creationtime);
293 }
294
295 if (feature_bool(FEAT_ANNOUNCE_INVITES)) {
296 /* Announce to channel operators. */
297 sendcmdto_channel_butserv_butone(&his, get_error_numeric(RPL_ISSUEDINVITE)->str,
298 NULL, chptr, sptr, SKIP_NONOPS,
299 "%H %C %C :%C has been invited by %C",
300 chptr, acptr, sptr, acptr, sptr);
301 /* Announce to servers with channel operators. */
302 sendcmdto_channel_servers_butone(sptr, NULL, TOK_INVITE, chptr, acptr, SKIP_NONOPS,
303 "%s %H %Tu", cli_name(acptr), chptr,
304 chptr->creationtime);
305 }
306
307 return 0;
308}