2 * IRC - Internet Relay Chat, ircd/m_invite.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
6 * See file AUTHORS in IRC package for additional names of
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)
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.
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.
27 * m_functions execute protocol messages on this server:
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...).
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.
39 * (!IsServer(cptr)) => (cptr == sptr), because
40 * prefixes are taken *only* from servers...
43 * (sptr == cptr) => the message didn't
46 * (sptr != cptr && IsServer(sptr) means
47 * the prefix specified servername. (?)
49 * (sptr != cptr && !IsServer(sptr) means
50 * that message originated from a remote
55 * (!IsServer(sptr)) means that, sptr can safely
56 * taken as defining the target structure of the
57 * message in this server.
59 * *Always* true (if 'parse' and others are working correct):
61 * 1) sptr->from == cptr (note: cptr->from == cptr)
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 ]
68 * parc number of variable parameter strings (if zero,
69 * parv is allowed to be NULL)
71 * parv a NULL terminated list of parameter pointers,
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*
79 * note: it is guaranteed that parv[0]..parv[parc-1] are all
84 * No need to include handlers.h here the signatures must match
85 * and we don't need to force a rebuild of all the handlers everytime
86 * we add a new one to the list. --Bleep
94 #include "ircd_reply.h"
95 #include "ircd_string.h"
107 * m_invite - generic message handler
109 * parv[0] - sender prefix
110 * parv[1] - user to invite
111 * parv[2] - channel name
113 * - INVITE now is accepted only if who does it is chanop (this of course
114 * implies that channel must exist and he must be on it).
116 * - On the other side it IS processed even if channel is NOT invite only
117 * leaving room for other enhancements like inviting banned ppl. -- Nemesi
119 * - Invite with no parameters now lists the channels you are invited to.
122 int m_invite(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
124 struct Client *acptr;
125 struct Channel *chptr;
129 * list the channels you have an invite to.
132 for (lp = sptr->user->invited; lp; lp = lp->next)
133 sendto_one(cptr, rpl_str(RPL_INVITELIST), me.name, cptr->name,
134 lp->value.chptr->chname);
135 sendto_one(cptr, rpl_str(RPL_ENDOFINVITELIST), me.name, cptr->name);
139 if (parc < 3 || EmptyString(parv[2]))
140 return need_more_params(sptr, "INVITE");
142 if (!(acptr = FindUser(parv[1]))) {
143 sendto_one(sptr, err_str(ERR_NOSUCHNICK), me.name, parv[0], parv[1]);
147 if (is_silenced(sptr, acptr))
150 clean_channelname(parv[2]);
152 if (!IsChannelPrefix(*parv[2]))
155 if (!(chptr = FindChannel(parv[2]))) {
156 if (IsModelessChannel(parv[2]) || IsLocalChannel(parv[2])) {
157 sendto_one(sptr, err_str(ERR_NOTONCHANNEL), me.name, parv[0], parv[2]);
161 /* Do not disallow to invite to non-existant #channels, otherwise they
162 would simply first be created, causing only MORE bandwidth usage. */
164 if (check_target_limit(sptr, acptr, acptr->name, 0))
167 sendto_one(sptr, rpl_str(RPL_INVITING), me.name, parv[0],
168 acptr->name, parv[2]);
170 if (acptr->user->away)
171 sendto_one(sptr, rpl_str(RPL_AWAY), me.name, parv[0],
172 acptr->name, acptr->user->away);
175 sendto_prefix_one(acptr, sptr, ":%s " MSG_INVITE " %s :%s", sptr->name,
176 acptr->name, parv[2]);
178 sendto_one(acptr, "%s%s " TOK_INVITE " %s :%s", NumNick(sptr),
179 acptr->name, parv[2]);
184 if (!find_channel_member(sptr, chptr)) {
185 sendto_one(sptr, err_str(ERR_NOTONCHANNEL), me.name, parv[0],
190 if (find_channel_member(acptr, chptr)) {
191 sendto_one(sptr, err_str(ERR_USERONCHANNEL),
192 me.name, parv[0], acptr->name, chptr->chname);
196 if (!is_chan_op(sptr, chptr)) {
197 sendto_one(sptr, err_str(ERR_CHANOPRIVSNEEDED),
198 me.name, parv[0], chptr->chname);
202 /* If we get here, it was a VALID and meaningful INVITE */
204 if (check_target_limit(sptr, acptr, acptr->name, 0))
207 sendto_one(sptr, rpl_str(RPL_INVITING), me.name, parv[0],
208 acptr->name, chptr->chname);
210 if (acptr->user->away)
211 sendto_one(sptr, rpl_str(RPL_AWAY), me.name, parv[0],
212 acptr->name, acptr->user->away);
214 if (MyConnect(acptr)) {
215 add_invite(acptr, chptr);
216 sendto_prefix_one(acptr, sptr, ":%s " MSG_INVITE " %s :%s",
217 sptr->name, acptr->name, chptr->chname);
220 sendto_one(acptr, "%s%s " TOK_INVITE " %s :%s",
221 NumNick(sptr), acptr->name, chptr->chname);
227 * ms_invite - server message handler
229 * parv[0] - sender prefix
230 * parv[1] - user to invite
231 * parv[2] - channel name
233 * - INVITE now is accepted only if who does it is chanop (this of course
234 * implies that channel must exist and he must be on it).
236 * - On the other side it IS processed even if channel is NOT invite only
237 * leaving room for other enhancements like inviting banned ppl. -- Nemesi
239 * - Invite with no parameters now lists the channels you are invited to.
242 int ms_invite(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
244 struct Client *acptr;
245 struct Channel *chptr;
247 if (IsServer(sptr)) {
249 * this will blow up if we get an invite from a server
250 * we look for channel membership in sptr below.
252 /* PROTOCOL WARNING */
255 if (parc < 3 || EmptyString(parv[2])) {
257 * should have been handled upstream, ignore it.
259 /* PROTOCOL WARNING */
262 if ('#' != *parv[2]) {
266 /* PROTOCOL WARNING */
269 if (!(acptr = FindUser(parv[1]))) {
270 sendto_one(sptr, err_str(ERR_NOSUCHNICK), me.name, parv[0], parv[1]);
273 if (!MyUser(acptr)) {
275 * just relay the message
277 sendto_one(acptr, "%s%s " TOK_INVITE " %s :%s",
278 NumNick(sptr), acptr->name, parv[2]);
282 if (is_silenced(sptr, acptr))
285 if (!(chptr = FindChannel(parv[2]))) {
287 * allow invites to non existant channels, bleah
288 * avoid JOIN, INVITE, PART abuse
290 sendto_prefix_one(acptr, sptr, ":%s " MSG_INVITE " %s :%s", sptr->name,
291 acptr->name, parv[2]);
295 if (!find_channel_member(sptr, chptr)) {
296 sendto_one(sptr, err_str(ERR_NOTONCHANNEL), me.name, parv[0],
300 if (find_channel_member(acptr, chptr)) {
301 sendto_one(sptr, err_str(ERR_USERONCHANNEL),
302 me.name, parv[0], acptr->name, chptr->chname);
305 add_invite(acptr, chptr);
306 sendto_prefix_one(acptr, sptr, ":%s " MSG_INVITE " %s :%s", sptr->name,
307 acptr->name, chptr->chname);
316 * parv[0] - sender prefix
317 * parv[1] - user to invite
318 * parv[2] - channel name
320 * - INVITE now is accepted only if who does it is chanop (this of course
321 * implies that channel must exist and he must be on it).
323 * - On the other side it IS processed even if channel is NOT invite only
324 * leaving room for other enhancements like inviting banned ppl. -- Nemesi
326 * - Invite with no parameters now lists the channels you are invited to.
329 int m_invite(struct Client* cptr, struct Client *sptr, int parc, char *parv[])
331 struct Client *acptr;
332 struct Channel *chptr;
336 * list the channels you have an invite to.
339 for (lp = sptr->user->invited; lp; lp = lp->next)
340 sendto_one(cptr, rpl_str(RPL_INVITELIST), me.name, cptr->name,
341 lp->value.chptr->chname);
342 sendto_one(cptr, rpl_str(RPL_ENDOFINVITELIST), me.name, cptr->name);
346 if (parc < 3 || *parv[2] == '\0')
347 return need_more_params(sptr, "INVITE");
349 if (!(acptr = FindUser(parv[1])))
351 sendto_one(sptr, err_str(ERR_NOSUCHNICK), me.name, parv[0], parv[1]);
355 if (is_silenced(sptr, acptr))
359 clean_channelname(parv[2]);
360 else if (IsLocalChannel(parv[2]))
363 if (*parv[2] == '0' || !IsChannelName(parv[2]))
366 if (!(chptr = FindChannel(parv[2])))
368 if (IsModelessChannel(parv[2]) || IsLocalChannel(parv[2]))
370 sendto_one(sptr, err_str(ERR_NOTONCHANNEL), me.name, parv[0], parv[2]);
374 /* Do not disallow to invite to non-existant #channels, otherwise they
375 would simply first be created, causing only MORE bandwidth usage. */
378 if (check_target_limit(sptr, acptr, acptr->name, 0))
381 sendto_one(sptr, rpl_str(RPL_INVITING), me.name, parv[0],
382 acptr->name, parv[2]);
384 if (acptr->user->away)
385 sendto_one(sptr, rpl_str(RPL_AWAY), me.name, parv[0],
386 acptr->name, acptr->user->away);
389 sendto_prefix_one(acptr, sptr, ":%s INVITE %s :%s", parv[0],
390 acptr->name, parv[2]);
395 if (!find_channel_member(sptr, chptr))
397 sendto_one(sptr, err_str(ERR_NOTONCHANNEL), me.name, parv[0],
402 if (find_channel_member(acptr, chptr))
404 sendto_one(sptr, err_str(ERR_USERONCHANNEL),
405 me.name, parv[0], acptr->name, chptr->chname);
411 if (!is_chan_op(sptr, chptr))
413 sendto_one(sptr, err_str(ERR_CHANOPRIVSNEEDED),
414 me.name, parv[0], chptr->chname);
418 /* If we get here, it was a VALID and meaningful INVITE */
420 if (check_target_limit(sptr, acptr, acptr->name, 0))
423 sendto_one(sptr, rpl_str(RPL_INVITING), me.name, parv[0],
424 acptr->name, chptr->chname);
426 if (acptr->user->away)
427 sendto_one(sptr, rpl_str(RPL_AWAY), me.name, parv[0],
428 acptr->name, acptr->user->away);
431 if (MyConnect(acptr)) {
432 add_invite(acptr, chptr);
433 sendto_prefix_one(acptr, sptr, ":%s INVITE %s :%s", parv[0],
434 acptr->name, chptr->chname);
437 sendto_highprot_butone(acptr, 10, "%s%s " TOK_INVITE " %s :%s",
438 NumNick(sptr), acptr->name, chptr->chname);