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 = cli_user(sptr)->invited; lp; lp = lp->next)
133 send_reply(cptr, RPL_INVITELIST, lp->value.chptr->chname);
134 send_reply(cptr, RPL_ENDOFINVITELIST);
138 if (parc < 3 || EmptyString(parv[2]))
139 return need_more_params(sptr, "INVITE");
141 if (!(acptr = FindUser(parv[1]))) {
142 send_reply(sptr, ERR_NOSUCHNICK, parv[1]);
146 if (is_silenced(sptr, acptr))
149 clean_channelname(parv[2]);
151 if (!IsChannelPrefix(*parv[2]))
154 if (!(chptr = FindChannel(parv[2]))) {
155 if (IsModelessChannel(parv[2]) || IsLocalChannel(parv[2])) {
156 send_reply(sptr, ERR_NOTONCHANNEL, parv[2]);
160 /* Do not disallow to invite to non-existant #channels, otherwise they
161 would simply first be created, causing only MORE bandwidth usage. */
163 if (check_target_limit(sptr, acptr, cli_name(acptr), 0))
166 send_reply(sptr, RPL_INVITING, cli_name(acptr), parv[2]);
168 if (cli_user(acptr)->away)
169 send_reply(sptr, RPL_AWAY, cli_name(acptr), cli_user(acptr)->away);
171 sendcmdto_one(sptr, CMD_INVITE, acptr, "%s :%s", cli_name(acptr), parv[2]);
176 if (!find_channel_member(sptr, chptr)) {
177 send_reply(sptr, ERR_NOTONCHANNEL, chptr->chname);
181 if (find_channel_member(acptr, chptr)) {
182 send_reply(sptr, ERR_USERONCHANNEL, cli_name(acptr), chptr->chname);
186 if (!is_chan_op(sptr, chptr)) {
187 send_reply(sptr, ERR_CHANOPRIVSNEEDED, chptr->chname);
191 /* If we get here, it was a VALID and meaningful INVITE */
193 if (check_target_limit(sptr, acptr, cli_name(acptr), 0))
196 send_reply(sptr, RPL_INVITING, cli_name(acptr), chptr->chname);
198 if (cli_user(acptr)->away)
199 send_reply(sptr, RPL_AWAY, cli_name(acptr), cli_user(acptr)->away);
201 if (MyConnect(acptr))
202 add_invite(acptr, chptr);
204 sendcmdto_one(sptr, CMD_INVITE, acptr, "%s :%H", cli_name(acptr), chptr);
210 * ms_invite - server message handler
212 * parv[0] - sender prefix
213 * parv[1] - user to invite
214 * parv[2] - channel name
216 * - INVITE now is accepted only if who does it is chanop (this of course
217 * implies that channel must exist and he must be on it).
219 * - On the other side it IS processed even if channel is NOT invite only
220 * leaving room for other enhancements like inviting banned ppl. -- Nemesi
222 * - Invite with no parameters now lists the channels you are invited to.
225 int ms_invite(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
227 struct Client *acptr;
228 struct Channel *chptr;
230 if (IsServer(sptr)) {
232 * this will blow up if we get an invite from a server
233 * we look for channel membership in sptr below.
235 return protocol_violation(sptr,"Server attempting to invite");
237 if (parc < 3 || EmptyString(parv[2])) {
239 * should have been handled upstream, ignore it.
241 return need_more_params(sptr,"INVITE");
243 if ('#' != *parv[2]) {
247 return protocol_violation(sptr, "Invite to a non-standard channel %s",parv[2]);
249 if (!(acptr = FindUser(parv[1]))) {
250 send_reply(sptr, ERR_NOSUCHNICK, parv[1]);
253 if (!MyUser(acptr)) {
255 * just relay the message
257 sendcmdto_one(sptr, CMD_INVITE, acptr, "%s :%s", cli_name(acptr), parv[2]);
261 if (is_silenced(sptr, acptr))
264 if (!(chptr = FindChannel(parv[2]))) {
266 * allow invites to non existant channels, bleah
267 * avoid JOIN, INVITE, PART abuse
269 sendcmdto_one(sptr, CMD_INVITE, acptr, "%C :%s", acptr, parv[2]);
273 if (!find_channel_member(sptr, chptr)) {
274 send_reply(sptr, ERR_NOTONCHANNEL, chptr->chname);
277 if (find_channel_member(acptr, chptr)) {
278 send_reply(sptr, ERR_USERONCHANNEL, cli_name(acptr), chptr->chname);
281 add_invite(acptr, chptr);
282 sendcmdto_one(sptr, CMD_INVITE, acptr, "%s :%H", cli_name(acptr), chptr);
291 * parv[0] - sender prefix
292 * parv[1] - user to invite
293 * parv[2] - channel name
295 * - INVITE now is accepted only if who does it is chanop (this of course
296 * implies that channel must exist and he must be on it).
298 * - On the other side it IS processed even if channel is NOT invite only
299 * leaving room for other enhancements like inviting banned ppl. -- Nemesi
301 * - Invite with no parameters now lists the channels you are invited to.
304 int m_invite(struct Client* cptr, struct Client *sptr, int parc, char *parv[])
306 struct Client *acptr;
307 struct Channel *chptr;
311 * list the channels you have an invite to.
314 for (lp = sptr->user->invited; lp; lp = lp->next)
315 sendto_one(cptr, rpl_str(RPL_INVITELIST), me.name, cptr->name, /* XXX DEAD */
316 lp->value.chptr->chname);
317 sendto_one(cptr, rpl_str(RPL_ENDOFINVITELIST), me.name, cptr->name); /* XXX DEAD */
321 if (parc < 3 || *parv[2] == '\0')
322 return need_more_params(sptr, "INVITE");
324 if (!(acptr = FindUser(parv[1])))
326 sendto_one(sptr, err_str(ERR_NOSUCHNICK), me.name, parv[0], parv[1]); /* XXX DEAD */
330 if (is_silenced(sptr, acptr))
334 clean_channelname(parv[2]);
335 else if (IsLocalChannel(parv[2]))
338 if (*parv[2] == '0' || !IsChannelName(parv[2]))
341 if (!(chptr = FindChannel(parv[2])))
343 if (IsModelessChannel(parv[2]) || IsLocalChannel(parv[2]))
345 sendto_one(sptr, err_str(ERR_NOTONCHANNEL), me.name, parv[0], parv[2]); /* XXX DEAD */
349 /* Do not disallow to invite to non-existant #channels, otherwise they
350 would simply first be created, causing only MORE bandwidth usage. */
353 if (check_target_limit(sptr, acptr, acptr->name, 0))
356 sendto_one(sptr, rpl_str(RPL_INVITING), me.name, parv[0], /* XXX DEAD */
357 acptr->name, parv[2]);
359 if (acptr->user->away)
360 sendto_one(sptr, rpl_str(RPL_AWAY), me.name, parv[0], /* XXX DEAD */
361 acptr->name, acptr->user->away);
364 sendto_prefix_one(acptr, sptr, ":%s INVITE %s :%s", parv[0], /* XXX DEAD */
365 acptr->name, parv[2]);
370 if (!find_channel_member(sptr, chptr))
372 sendto_one(sptr, err_str(ERR_NOTONCHANNEL), me.name, parv[0], /* XXX DEAD */
377 if (find_channel_member(acptr, chptr))
379 sendto_one(sptr, err_str(ERR_USERONCHANNEL), /* XXX DEAD */
380 me.name, parv[0], acptr->name, chptr->chname);
386 if (!is_chan_op(sptr, chptr))
388 sendto_one(sptr, err_str(ERR_CHANOPRIVSNEEDED), /* XXX DEAD */
389 me.name, parv[0], chptr->chname);
393 /* If we get here, it was a VALID and meaningful INVITE */
395 if (check_target_limit(sptr, acptr, acptr->name, 0))
398 sendto_one(sptr, rpl_str(RPL_INVITING), me.name, parv[0], /* XXX DEAD */
399 acptr->name, chptr->chname);
401 if (acptr->user->away)
402 sendto_one(sptr, rpl_str(RPL_AWAY), me.name, parv[0], /* XXX DEAD */
403 acptr->name, acptr->user->away);
406 if (MyConnect(acptr)) {
407 add_invite(acptr, chptr);
408 sendto_prefix_one(acptr, sptr, ":%s INVITE %s :%s", parv[0], /* XXX DEAD */
409 acptr->name, chptr->chname);
412 sendto_highprot_butone(acptr, 10, "%s%s " TOK_INVITE " %s :%s", /* XXX DEAD */
413 NumNick(sptr), acptr->name, chptr->chname);