2 * IRC - Internet Relay Chat, ircd/m_kick.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
88 #include "ircd_reply.h"
89 #include "ircd_string.h"
94 #include "ircd_features.h"
99 * m_kick - generic message handler
101 * parv[0] = sender prefix
103 * parv[2] = client to kick
104 * parv[parc-1] = kick comment
106 int m_kick(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
109 struct Channel *chptr;
110 struct Membership *member = 0;
111 struct Membership* member2;
112 char *name, *comment;
114 ClrFlag(sptr, FLAG_TS8);
116 if (parc < 3 || *parv[1] == '\0')
117 return need_more_params(sptr, "KICK");
122 if (!(chptr = get_channel(sptr, name, CGT_NO_CREATE)))
123 return send_reply(sptr, ERR_NOSUCHCHANNEL, name);
125 if (!(member2 = find_member_link(chptr, sptr)) || IsZombie(member2)
126 || !IsChanOp(member2))
127 return send_reply(sptr, ERR_CHANOPRIVSNEEDED, name);
129 if (!(who = find_chasing(sptr, parv[2], 0)))
130 return 0; /* find_chasing sends the reply for us */
132 /* Don't allow the channel service to be kicked */
133 if (IsChannelService(who))
134 return send_reply(sptr, ERR_ISCHANSERVICE, cli_name(who), chptr->chname);
136 /* Prevent kicking opers from local channels -DM- */
137 if (IsLocalChannel(chptr->chname) && HasPriv(who, PRIV_DEOP_LCHAN))
138 return send_reply(sptr, ERR_ISOPERLCHAN, cli_name(who), chptr->chname);
140 /* check if kicked user is actually on the channel */
141 if (!(member = find_member_link(chptr, who)) || IsZombie(member))
142 return send_reply(sptr, ERR_USERNOTINCHANNEL, cli_name(who), chptr->chname);
144 /* Don't allow to kick member with a higher or equal op-level */
145 if ((OpLevel(member) <= OpLevel(member2)) && feature_bool(FEAT_OPLEVELS))
146 return send_reply(sptr, ERR_NOTLOWEROPLEVEL, cli_name(who), chptr->chname,
147 OpLevel(member2), OpLevel(member), "kick",
148 OpLevel(member) == OpLevel(member2) ? "the same" : "a higher");
150 /* We rely on ircd_snprintf to truncate the comment */
151 comment = EmptyString(parv[parc - 1]) ? parv[0] : parv[parc - 1];
153 if (!IsLocalChannel(name))
154 sendcmdto_serv_butone(sptr, CMD_KICK, cptr, "%H %C :%s", chptr, who,
157 if (IsDelayedJoin(member)) {
158 /* If it's a delayed join, only send the KICK to the person doing
159 * the kicking and the victim */
161 sendcmdto_one(sptr, CMD_KICK, who, "%H %C :%s", chptr, who, comment);
162 sendcmdto_one(sptr, CMD_KICK, sptr, "%H %C :%s", chptr, who, comment);
163 CheckDelayedJoins(chptr);
165 sendcmdto_channel_butserv_butone(sptr, CMD_KICK, chptr, NULL, 0, "%H %C :%s", chptr, who,
168 make_zombie(member, who, cptr, sptr, chptr);
174 * ms_kick - server message handler
176 * parv[0] = sender prefix
178 * parv[2] = client to kick
179 * parv[parc-1] = kick comment
181 int ms_kick(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
184 struct Channel *chptr;
185 struct Membership *member = 0, *sptr_link = 0;
186 char *name, *comment;
188 ClrFlag(sptr, FLAG_TS8);
190 if (parc < 3 || *parv[1] == '\0')
191 return need_more_params(sptr, "KICK");
194 comment = parv[parc - 1];
196 /* figure out who gets kicked from what */
197 if (IsLocalChannel(name) ||
198 !(chptr = get_channel(sptr, name, CGT_NO_CREATE)) ||
199 !(who = findNUser(parv[2])))
202 /* We go ahead and pass on the KICK for users not on the channel */
203 if (!(member = find_member_link(chptr, who)) || IsZombie(member))
206 /* Send HACK notice, but not for servers in BURST */
207 /* 2002-10-17: Don't send HACK if the users local server is kicking them */
208 if (IsServer(sptr) &&
209 !IsBurstOrBurstAck(sptr) &&
211 sendto_opmask_butone(0, SNO_HACK4, "HACK: %C KICK %H %C %s", sptr, chptr,
214 /* Unless someone accepted it downstream (or the user isn't on the channel
215 * here), if kicker is not on channel, or if kicker is not a channel
216 * operator, bounce the kick
218 if (!IsServer(sptr) && member && cli_from(who) != cptr &&
219 (!(sptr_link = find_member_link(chptr, sptr)) || !IsChanOp(sptr_link))) {
220 sendto_opmask_butone(0, SNO_HACK2, "HACK: %C KICK %H %C %s", sptr, chptr,
223 sendcmdto_one(who, CMD_JOIN, cptr, "%H", chptr);
225 /* Reop/revoice member */
226 if (IsChanOp(member) || HasVoice(member)) {
229 modebuf_init(&mbuf, sptr, cptr, chptr,
230 (MODEBUF_DEST_SERVER | /* Send mode to a server */
231 MODEBUF_DEST_DEOP | /* Deop the source */
232 MODEBUF_DEST_BOUNCE)); /* And bounce the MODE */
234 if (IsChanOp(member))
235 modebuf_mode_client(&mbuf, MODE_DEL | MODE_CHANOP, who);
236 if (HasVoice(member))
237 modebuf_mode_client(&mbuf, MODE_DEL | MODE_VOICE, who);
239 modebuf_flush(&mbuf);
242 /* Propagate kick... */
243 sendcmdto_serv_butone(sptr, CMD_KICK, cptr, "%H %C :%s", chptr, who,
246 if (member) { /* and tell the channel about it */
247 sendcmdto_channel_butserv_butone(IsServer(sptr) ? &me : sptr, CMD_KICK,
248 chptr, NULL, 0, "%H %C :%s", chptr, who,
251 make_zombie(member, who, cptr, sptr, chptr);