]>
jfr.im git - irc/quakenet/snircd.git/blob - ircd/m_invite.c
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.
23 * $Id: m_invite.c,v 1.25 2005/09/13 15:17:46 entrope Exp $
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
88 #include "ircd_features.h"
90 #include "ircd_reply.h"
91 #include "ircd_string.h"
100 /* #include <assert.h> -- Now using assert in ircd_log.h */
103 * m_invite - generic message handler
105 * parv[0] - sender prefix
106 * parv[1] - user to invite
107 * parv[2] - channel name
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).
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
115 * - Invite with no parameters now lists the channels you are invited to.
118 int m_invite(struct Client
* cptr
, struct Client
* sptr
, int parc
, char* parv
[])
120 struct Client
*acptr
;
121 struct Channel
*chptr
;
125 * list the channels you have an invite to.
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
);
134 if (parc
< 3 || EmptyString(parv
[2]))
135 return need_more_params(sptr
, "INVITE");
137 if (!(acptr
= FindUser(parv
[1]))) {
138 send_reply(sptr
, ERR_NOSUCHNICK
, parv
[1]);
142 if (is_silenced(sptr
, acptr
))
145 if (!IsChannelName(parv
[2])
146 || !strIsIrcCh(parv
[2])
147 || !(chptr
= FindChannel(parv
[2]))) {
148 send_reply(sptr
, ERR_NOSUCHCHANNEL
, parv
[2]);
152 if (!find_channel_member(sptr
, chptr
)) {
153 send_reply(sptr
, ERR_NOTONCHANNEL
, chptr
->chname
);
157 if (find_channel_member(acptr
, chptr
)) {
158 send_reply(sptr
, ERR_USERONCHANNEL
, cli_name(acptr
), chptr
->chname
);
162 if (!is_chan_op(sptr
, chptr
)) {
163 send_reply(sptr
, ERR_CHANOPRIVSNEEDED
, chptr
->chname
);
167 /* If we get here, it was a VALID and meaningful INVITE */
169 if (check_target_limit(sptr
, acptr
, cli_name(acptr
), 0))
172 send_reply(sptr
, RPL_INVITING
, cli_name(acptr
), chptr
->chname
);
174 if (cli_user(acptr
)->away
)
175 send_reply(sptr
, RPL_AWAY
, cli_name(acptr
), cli_user(acptr
)->away
);
177 if (MyConnect(acptr
)) {
178 add_invite(acptr
, chptr
);
179 sendcmdto_one(sptr
, CMD_INVITE
, acptr
, "%s %H", cli_name(acptr
), chptr
);
180 } else if (!IsLocalChannel(chptr
->chname
)) {
181 sendcmdto_one(sptr
, CMD_INVITE
, acptr
, "%s %H %Tu", cli_name(acptr
), chptr
,
182 chptr
->creationtime
);
185 if (!IsLocalChannel(chptr
->chname
) || MyConnect(acptr
)) {
186 if (feature_bool(FEAT_ANNOUNCE_INVITES
)) {
187 /* Announce to channel operators. */
188 sendcmdto_channel_butserv_butone(&his
, get_error_numeric(RPL_ISSUEDINVITE
)->str
,
189 NULL
, chptr
, sptr
, SKIP_NONOPS
,
190 "%H %C %C :%C has been invited by %C",
191 chptr
, acptr
, sptr
, acptr
, sptr
);
192 /* Announce to servers with channel operators. */
193 sendcmdto_channel_servers_butone(sptr
, NULL
, TOK_INVITE
, chptr
, acptr
, SKIP_NONOPS
,
194 "%s %H %Tu", cli_name(acptr
),
195 chptr
, chptr
->creationtime
);
203 * ms_invite - server message handler
205 * parv[0] - sender prefix
206 * parv[1] - user to invite
207 * parv[2] - channel name
208 * parv[3] - (optional) channel timestamp
210 * - INVITE now is accepted only if who does it is chanop (this of course
211 * implies that channel must exist and he must be on it).
213 * - On the other side it IS processed even if channel is NOT invite only
214 * leaving room for other enhancements like inviting banned ppl. -- Nemesi
216 * - Invite with no parameters now lists the channels you are invited to.
219 * - Invite with too-late timestamp, or with no timestamp from a bursting
220 * server, is silently discarded. - Entrope 19 Jan 05
222 int ms_invite(struct Client
* cptr
, struct Client
* sptr
, int parc
, char* parv
[])
224 struct Client
*acptr
;
225 struct Channel
*chptr
;
228 if (IsServer(sptr
)) {
230 * this will blow up if we get an invite from a server
231 * we look for channel membership in sptr below.
233 return protocol_violation(sptr
,"Server attempting to invite");
235 if (parc
< 3 || EmptyString(parv
[2])) {
237 * should have been handled upstream, ignore it.
239 protocol_violation(sptr
,"Too few arguments to invite");
240 return need_more_params(sptr
,"INVITE");
242 if (!IsGlobalChannel(parv
[2])) {
246 return protocol_violation(sptr
, "Invite to a non-standard channel %s",parv
[2]);
248 if (!(acptr
= FindUser(parv
[1]))) {
249 send_reply(sptr
, ERR_NOSUCHNICK
, parv
[1]);
253 if (!(chptr
= FindChannel(parv
[2]))) {
255 * allow invites to non existent channels, bleah
256 * avoid JOIN, INVITE, PART abuse
258 sendcmdto_one(sptr
, CMD_INVITE
, acptr
, "%C :%s", acptr
, parv
[2]);
263 invite_ts
= atoi(parv
[3]);
264 if (invite_ts
> chptr
->creationtime
)
266 } else if (IsBurstOrBurstAck(cptr
))
269 if (!IsChannelService(sptr
) && !find_channel_member(sptr
, chptr
)) {
270 send_reply(sptr
, ERR_NOTONCHANNEL
, chptr
->chname
);
274 if (find_channel_member(acptr
, chptr
)) {
275 send_reply(sptr
, ERR_USERONCHANNEL
, cli_name(acptr
), chptr
->chname
);
279 if (is_silenced(sptr
, acptr
))
282 if (MyConnect(acptr
)) {
283 add_invite(acptr
, chptr
);
284 sendcmdto_one(sptr
, CMD_INVITE
, acptr
, "%s %H", cli_name(acptr
), chptr
);
286 sendcmdto_one(sptr
, CMD_INVITE
, acptr
, "%s %H %Tu", cli_name(acptr
), chptr
,
287 chptr
->creationtime
);
290 if (feature_bool(FEAT_ANNOUNCE_INVITES
)) {
291 /* Announce to channel operators. */
292 sendcmdto_channel_butserv_butone(&his
, get_error_numeric(RPL_ISSUEDINVITE
)->str
,
293 NULL
, chptr
, sptr
, SKIP_NONOPS
,
294 "%H %C %C :%C has been invited by %C",
295 chptr
, acptr
, sptr
, acptr
, sptr
);
296 /* Announce to servers with channel operators. */
297 sendcmdto_channel_servers_butone(sptr
, NULL
, TOK_INVITE
, chptr
, acptr
, SKIP_NONOPS
,
298 "%s %H %Tu", cli_name(acptr
), chptr
,
299 chptr
->creationtime
);