2 * IRC - Internet Relay Chat, ircd/m_uninvite.c
3 * Written by Philipp Kreil.
5 * See file AUTHORS in IRC package for additional names of
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 1, or (at your option)
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 * m_functions execute protocol messages on this server:
27 * cptr is always NON-NULL, pointing to a *LOCAL* client
28 * structure (with an open socket connected!). This
29 * identifies the physical socket where the message
30 * originated (or which caused the m_function to be
31 * executed--some m_functions may call others...).
33 * sptr is the source of the message, defined by the
34 * prefix part of the message if present. If not
35 * or prefix not found, then sptr==cptr.
37 * (!IsServer(cptr)) => (cptr == sptr), because
38 * prefixes are taken *only* from servers...
41 * (sptr == cptr) => the message didn't
44 * (sptr != cptr && IsServer(sptr) means
45 * the prefix specified servername. (?)
47 * (sptr != cptr && !IsServer(sptr) means
48 * that message originated from a remote
53 * (!IsServer(sptr)) means that, sptr can safely
54 * taken as defining the target structure of the
55 * message in this server.
57 * *Always* true (if 'parse' and others are working correct):
59 * 1) sptr->from == cptr (note: cptr->from == cptr)
61 * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
62 * *cannot* be a local connection, unless it's
63 * actually cptr!). [MyConnect(x) should probably
64 * be defined as (x == x->from) --msa ]
66 * parc number of variable parameter strings (if zero,
67 * parv is allowed to be NULL)
69 * parv a NULL terminated list of parameter pointers,
71 * parv[0], sender (prefix string), if not present
72 * this points to an empty string.
73 * parv[1]...parv[parc-1]
74 * pointers to additional parameters
75 * parv[parc] == NULL, *always*
77 * note: it is guaranteed that parv[0]..parv[parc-1] are all
86 #include "ircd_features.h"
88 #include "ircd_reply.h"
89 #include "ircd_string.h"
98 /* #include <assert.h> -- Now using assert in ircd_log.h */
101 * m_uninvite - generic message handler
103 * parv[0] - sender prefix
104 * parv[1] - user to uninvite
105 * parv[2] - channel name
108 int m_uninvite(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
110 struct Client *acptr;
111 struct Channel *chptr;
113 if (parc < 3 || EmptyString(parv[2]))
114 return need_more_params(sptr, "UNINVITE");
116 if (!(acptr = FindUser(parv[1]))) {
117 send_reply(sptr, ERR_NOSUCHNICK, parv[1]);
121 if (!IsChannelName(parv[2])
122 || !strIsIrcCh(parv[2])
123 || !(chptr = FindChannel(parv[2]))) {
124 send_reply(sptr, ERR_NOSUCHCHANNEL, parv[2]);
128 if (!find_channel_member(sptr, chptr)) {
129 send_reply(sptr, ERR_NOTONCHANNEL, chptr->chname);
133 if (find_channel_member(acptr, chptr)) {
134 send_reply(sptr, ERR_USERONCHANNEL, cli_name(acptr), chptr->chname);
138 if (!is_chan_op(sptr, chptr) && !is_halfop(sptr, chptr)) {
139 send_reply(sptr, ERR_CHANOPRIVSNEEDED, chptr->chname);
143 if(!IsInvited(acptr, chptr)) {
144 send_reply(sptr, ERR_USERNOTINVITED, cli_name(acptr), chptr->chname);
148 /* If we get here, it was a VALID and meaningful UNINVITE */
150 send_reply(sptr, RPL_UNINVITE, cli_name(acptr), chptr->chname);
152 if (MyConnect(acptr)) {
153 del_invite(acptr, chptr);
154 sendcmdto_one(sptr, CMD_UNINVITE, acptr, "%s %H", cli_name(acptr), chptr);
155 } else if (!IsLocalChannel(chptr->chname)) {
156 sendcmdto_one(sptr, CMD_UNINVITE, acptr, "%s %H %Tu", cli_name(acptr), chptr, chptr->creationtime);
163 * ms_uninvite - server message handler
165 * parv[0] - sender prefix
166 * parv[1] - user to invite
167 * parv[2] - channel name
168 * parv[3] - (optional) channel timestamp
171 int ms_uninvite(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
173 struct Client *acptr;
174 struct Channel *chptr;
177 if (IsServer(sptr)) {
179 * this will blow up if we get an uninvite from a server
180 * we look for channel membership in sptr below.
182 return protocol_violation(sptr,"Server attempting to uninvite");
184 if (parc < 3 || EmptyString(parv[2])) {
186 * should have been handled upstream, ignore it.
188 protocol_violation(sptr,"Too few arguments to uninvite");
189 return need_more_params(sptr,"UNINVITE");
191 if (!IsGlobalChannel(parv[2])) {
195 return protocol_violation(sptr, "Uninvite from a non-standard channel %s",parv[2]);
197 if (!(acptr = FindUser(parv[1]))) {
198 send_reply(sptr, ERR_NOSUCHNICK, parv[1]);
202 if (!(chptr = FindChannel(parv[2]))) {
203 send_reply(sptr, ERR_NOSUCHCHANNEL, parv[2]);
208 uninvite_ts = atoi(parv[3]);
209 if (uninvite_ts > chptr->creationtime)
211 } else if (IsBurstOrBurstAck(cptr))
214 if (!IsChannelService(sptr) && !find_channel_member(sptr, chptr)) {
215 send_reply(sptr, ERR_NOTONCHANNEL, chptr->chname);
219 if (find_channel_member(acptr, chptr)) {
220 send_reply(sptr, ERR_USERONCHANNEL, cli_name(acptr), chptr->chname);
224 if(!IsInvited(acptr, chptr)) {
225 send_reply(sptr, ERR_USERNOTINVITED, cli_name(acptr), chptr->chname);
229 if (MyConnect(acptr)) {
230 del_invite(acptr, chptr);
231 sendcmdto_one(sptr, CMD_UNINVITE, acptr, "%s %H", cli_name(acptr), chptr);
233 sendcmdto_one(sptr, CMD_UNINVITE, acptr, "%s %H %Tu", cli_name(acptr), chptr,
234 chptr->creationtime);