* note: it is guaranteed that parv[0]..parv[parc-1] are all
* non-NULL pointers.
*/
-#if 0
-/*
- * No need to include handlers.h here the signatures must match
- * and we don't need to force a rebuild of all the handlers everytime
- * we add a new one to the list. --Bleep
- */
-#include "handlers.h"
-#endif /* 0 */
+#include "config.h"
+
#include "channel.h"
#include "client.h"
#include "hash.h"
#include "ircd.h"
+#include "ircd_log.h"
#include "ircd_reply.h"
#include "ircd_string.h"
#include "msg.h"
#include "numeric.h"
#include "numnicks.h"
#include "send.h"
+#include "ircd_features.h"
-#include <assert.h>
+/* #include <assert.h> -- Now using assert in ircd_log.h */
/*
* m_kick - generic message handler
* parv[2] = client to kick
* parv[parc-1] = kick comment
*/
-int m_kick(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
+int m_kick(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
{
- struct Client* who;
- struct Channel* chptr;
- struct Membership* member = 0;
- char* channel_name;
+ struct Client *who;
+ struct Channel *chptr;
+ struct Membership *member = 0;
+ struct Membership* member2;
+ char *name, *comment;
- sptr->flags &= ~FLAGS_TS8;
+ ClrFlag(sptr, FLAG_TS8);
if (parc < 3 || *parv[1] == '\0')
return need_more_params(sptr, "KICK");
- channel_name = parv[1];
+ name = parv[1];
- if (IsLocalChannel(channel_name) && !MyUser(sptr))
- return 0;
-
- if (IsModelessChannel(channel_name)) {
- sendto_one(sptr, err_str(ERR_CHANOPRIVSNEEDED), me.name, parv[0],
- channel_name);
- return 0;
- }
+ /* simple checks */
+ if (!(chptr = get_channel(sptr, name, CGT_NO_CREATE)))
+ return send_reply(sptr, ERR_NOSUCHCHANNEL, name);
- chptr = get_channel(sptr, channel_name, CGT_NO_CREATE);
- if (!chptr) {
- sendto_one(sptr, err_str(ERR_NOSUCHCHANNEL), me.name, parv[0], channel_name);
- return 0;
- }
+ if (!(member2 = find_member_link(chptr, sptr)) || IsZombie(member2)
+ || !IsChanOp(member2))
+ return send_reply(sptr, ERR_CHANOPRIVSNEEDED, name);
- if (!IsServer(cptr) && !is_chan_op(sptr, chptr)) {
- sendto_one(sptr, err_str(ERR_CHANOPRIVSNEEDED),
- me.name, parv[0], chptr->chname);
- return 0;
- }
+ if (!(who = find_chasing(sptr, parv[2], 0)))
+ return 0; /* find_chasing sends the reply for us */
- if (MyUser(sptr)) {
- if (!(who = find_chasing(sptr, parv[2], 0)))
- return 0; /* No such user left! */
- }
- else if (!(who = findNUser(parv[2])))
- return 0; /* No such user left! */
+ /* Don't allow the channel service to be kicked */
+ if (IsChannelService(who))
+ return send_reply(sptr, ERR_ISCHANSERVICE, cli_name(who), chptr->chname);
- /*
- * if the user is +k, prevent a kick from local user
- */
- if (IsChannelService(who) && MyUser(sptr)) {
- sendto_one(sptr, err_str(ERR_ISCHANSERVICE), me.name,
- parv[0], who->name, chptr->chname);
- return 0;
- }
+ /* Prevent kicking opers from local channels -DM- */
+ if (IsLocalChannel(chptr->chname) && HasPriv(who, PRIV_DEOP_LCHAN))
+ return send_reply(sptr, ERR_ISOPERLCHAN, cli_name(who), chptr->chname);
-#ifdef NO_OPER_DEOP_LCHAN
- /*
- * Prevent kicking opers from local channels -DM-
- */
- if (IsOperOnLocalChannel(who, chptr->chname)) {
- sendto_one(sptr, err_str(ERR_ISOPERLCHAN), me.name,
- parv[0], who->name, chptr->chname);
- return 0;
- }
-#endif
+ /* check if kicked user is actually on the channel */
+ if (!(member = find_member_link(chptr, who)) || IsZombie(member))
+ return send_reply(sptr, ERR_USERNOTINCHANNEL, cli_name(who), chptr->chname);
- /*
- * Servers can now send kicks without hacks during a netburst - they
- * are kicking users from a +i channel.
- * - Isomer 25-11-1999
+ /* Don't allow to kick member with a higher op-level,
+ * or members with the same op-level unless both are MAXOPLEVEL.
*/
- if (IsServer(sptr)
-#if defined(NO_INVITE_NETRIDE)
- && !IsBurstOrBurstAck(sptr)
-#endif
- ) {
- send_hack_notice(cptr, sptr, parc, parv, 1, 3);
- }
-
- if (IsServer(sptr) ||
- ((member = find_member_link(chptr, who)) && !IsZombie(member)))
- {
- struct Membership* sptr_link = find_member_link(chptr, sptr);
- if (who->from != cptr &&
- ((sptr_link && IsDeopped(sptr_link)) || (!sptr_link && IsUser(sptr))))
- {
- /*
- * Bounce here:
- * cptr must be a server (or cptr == sptr and
- * sptr->flags can't have DEOPPED set
- * when CHANOP is set).
- */
- sendto_one(cptr, "%s%s " TOK_JOIN " %s", NumNick(who), chptr->chname);
- if (IsChanOp(member))
- {
- sendto_one(cptr, "%s " TOK_MODE " %s +o %s%s " TIME_T_FMT,
- NumServ(&me), chptr->chname, NumNick(who), chptr->creationtime);
- }
- if (HasVoice(member))
- {
- sendto_one(cptr, "%s " TOK_MODE " %s +v %s%s " TIME_T_FMT,
- NumServ(&me), chptr->chname, NumNick(who), chptr->creationtime);
- }
- }
- else
- {
- char* comment = (EmptyString(parv[parc - 1])) ? parv[0] : parv[parc - 1];
- if (strlen(comment) > TOPICLEN)
- comment[TOPICLEN] = '\0';
-
- if (!IsLocalChannel(channel_name))
- {
- sendto_highprot_butone(cptr, 10, "%s%s " TOK_KICK " %s %s%s :%s",
- NumNick(sptr), chptr->chname, NumNick(who), comment);
- }
- if (member) {
- sendto_channel_butserv(chptr, sptr,
- ":%s KICK %s %s :%s", parv[0], chptr->chname, who->name, comment);
- make_zombie(member, who, cptr, sptr, chptr);
- }
- }
- }
- else if (MyUser(sptr))
- sendto_one(sptr, err_str(ERR_USERNOTINCHANNEL),
- me.name, parv[0], who->name, chptr->chname);
+ if (OpLevel(member) < OpLevel(member2)
+ || (OpLevel(member) == OpLevel(member2)
+ && OpLevel(member) < MAXOPLEVEL))
+ return send_reply(sptr, ERR_NOTLOWEROPLEVEL, cli_name(who), chptr->chname,
+ OpLevel(member2), OpLevel(member), "kick",
+ OpLevel(member) == OpLevel(member2) ? "the same" : "a higher");
+
+ /* We rely on ircd_snprintf to truncate the comment */
+ comment = EmptyString(parv[parc - 1]) ? parv[0] : parv[parc - 1];
+
+ if (!IsLocalChannel(name))
+ sendcmdto_serv_butone(sptr, CMD_KICK, cptr, "%H %C :%s", chptr, who,
+ comment);
+
+ if (IsDelayedJoin(member)) {
+ /* If it's a delayed join, only send the KICK to the person doing
+ * the kicking and the victim */
+ if (MyUser(who))
+ sendcmdto_one(sptr, CMD_KICK, who, "%H %C :%s", chptr, who, comment);
+ sendcmdto_one(who, CMD_JOIN, sptr, "%H", chptr);
+ sendcmdto_one(sptr, CMD_KICK, sptr, "%H %C :%s", chptr, who, comment);
+ CheckDelayedJoins(chptr);
+ } else
+ sendcmdto_channel_butserv_butone(sptr, CMD_KICK, chptr, NULL, 0, "%H %C :%s", chptr, who,
+ comment);
+
+ make_zombie(member, who, cptr, sptr, chptr);
return 0;
}
* parv[2] = client to kick
* parv[parc-1] = kick comment
*/
-int ms_kick(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
+int ms_kick(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
{
- struct Client* who;
- struct Channel* chptr;
- struct Membership* member = 0;
- char* channel_name;
+ struct Client *who;
+ struct Channel *chptr;
+ struct Membership *member = 0, *sptr_link = 0;
+ char *name, *comment;
- sptr->flags &= ~FLAGS_TS8;
+ ClrFlag(sptr, FLAG_TS8);
if (parc < 3 || *parv[1] == '\0')
return need_more_params(sptr, "KICK");
- channel_name = parv[1];
-
- if (IsLocalChannel(channel_name) && !MyUser(sptr))
- return 0;
-
- if (IsModelessChannel(channel_name)) {
- sendto_one(sptr, err_str(ERR_CHANOPRIVSNEEDED), me.name, parv[0],
- channel_name);
- return 0;
- }
-
- chptr = get_channel(sptr, channel_name, CGT_NO_CREATE);
- if (!chptr) {
- sendto_one(sptr, err_str(ERR_NOSUCHCHANNEL), me.name, parv[0], channel_name);
- return 0;
- }
-
- if (!IsServer(cptr) && !is_chan_op(sptr, chptr)) {
- sendto_one(sptr, err_str(ERR_CHANOPRIVSNEEDED),
- me.name, parv[0], chptr->chname);
- return 0;
- }
-
- if (MyUser(sptr)) {
- if (!(who = find_chasing(sptr, parv[2], 0)))
- return 0; /* No such user left! */
- }
- else if (!(who = findNUser(parv[2])))
- return 0; /* No such user left! */
-
- /*
- * if the user is +k, prevent a kick from local user
- */
- if (IsChannelService(who) && MyUser(sptr)) {
- sendto_one(sptr, err_str(ERR_ISCHANSERVICE), me.name,
- parv[0], who->name, chptr->chname);
- return 0;
- }
+ name = parv[1];
+ comment = parv[parc - 1];
-#ifdef NO_OPER_DEOP_LCHAN
- /*
- * Prevent kicking opers from local channels -DM-
- */
- if (IsOperOnLocalChannel(who, chptr->chname)) {
- sendto_one(sptr, err_str(ERR_ISOPERLCHAN), me.name,
- parv[0], who->name, chptr->chname);
+ /* figure out who gets kicked from what */
+ if (IsLocalChannel(name) ||
+ !(chptr = get_channel(sptr, name, CGT_NO_CREATE)) ||
+ !(who = findNUser(parv[2])))
return 0;
- }
-#endif
-#if defined(NO_INVITE_NETRIDE)
- /*
- * Servers can now send kicks without hacks during a netburst - they
- * are kicking users from a +i channel.
- * - Isomer 25-11-1999
- */
- if (IsServer(sptr) && !IsBurstOrBurstAck(sptr)) {
-#else
- if (IsServer(sptr)) {
-#endif
- send_hack_notice(cptr, sptr, parc, parv, 1, 3);
- }
-
- if (IsServer(sptr) ||
- ((member = find_member_link(chptr, who)) && !IsZombie(member)))
+ /* We go ahead and pass on the KICK for users not on the channel */
+ member = find_member_link(chptr, who);
+ if (member && IsZombie(member))
{
- struct Membership* sptr_link = find_member_link(chptr, sptr);
- if (who->from != cptr &&
- ((sptr_link && IsDeopped(sptr_link)) || (!sptr_link && IsUser(sptr))))
- {
- /*
- * Bounce here:
- * cptr must be a server (or cptr == sptr and
- * sptr->flags can't have DEOPPED set
- * when CHANOP is set).
- */
- sendto_one(cptr, "%s%s " TOK_JOIN " %s", NumNick(who), chptr->chname);
- if (IsChanOp(member))
- {
- sendto_one(cptr, "%s " TOK_MODE " %s +o %s%s " TIME_T_FMT,
- NumServ(&me), chptr->chname, NumNick(who), chptr->creationtime);
- }
- if (HasVoice(member))
- {
- sendto_one(cptr, "%s " TOK_MODE " %s +v %s%s " TIME_T_FMT,
- NumServ(&me), chptr->chname, NumNick(who), chptr->creationtime);
- }
- }
- else
+ /* We might get a KICK from a zombie's own server because the user
+ * net-rode during a burst (which always generates a KICK) *and*
+ * was kicked via another server. In that case, we must remove
+ * the user from the channel.
+ */
+ if (sptr == cli_user(who)->server)
{
- char* comment = (EmptyString(parv[parc - 1])) ? parv[0] : parv[parc - 1];
- if (strlen(comment) > TOPICLEN)
- comment[TOPICLEN] = '\0';
-
- if (!IsLocalChannel(channel_name)) {
- if (IsServer(sptr)) {
- sendto_highprot_butone(cptr, 10, "%s " TOK_KICK " %s %s%s :%s",
- NumServ(sptr), chptr->chname, NumNick(who),
- comment);
- }
- else {
- sendto_highprot_butone(cptr, 10, "%s%s " TOK_KICK " %s %s%s :%s",
- NumNick(sptr), chptr->chname, NumNick(who),
- comment);
- }
- }
- if (member) {
- sendto_channel_butserv(chptr, sptr,
- ":%s KICK %s %s :%s", parv[0], chptr->chname, who->name, comment);
- make_zombie(member, who, cptr, sptr, chptr);
- }
+ remove_user_from_channel(who, chptr);
}
+ /* Otherwise, we treat zombies like they are not channel members. */
+ member = 0;
}
- else if (MyUser(sptr))
- sendto_one(sptr, err_str(ERR_USERNOTINCHANNEL),
- me.name, parv[0], who->name, chptr->chname);
-
- return 0;
-}
-
-
-#if 0
-/*
- * m_kick
- *
- * parv[0] = sender prefix
- * parv[1] = channel
- * parv[2] = client to kick
- * parv[parc-1] = kick comment
- */
-int m_kick(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
-{
- struct Client* who;
- struct Channel* chptr;
- struct Membership* member = 0;
- char* channel_name;
-
- sptr->flags &= ~FLAGS_TS8;
-
- if (parc < 3 || *parv[1] == '\0')
- return need_more_params(sptr, "KICK");
-
- channel_name = parv[1];
-
- if (IsLocalChannel(channel_name) && !MyUser(sptr))
- return 0;
-
- if (IsModelessChannel(channel_name)) {
- sendto_one(sptr, err_str(ERR_CHANOPRIVSNEEDED), me.name, parv[0],
- channel_name);
- return 0;
- }
-
- chptr = get_channel(sptr, channel_name, CGT_NO_CREATE);
- if (!chptr) {
- sendto_one(sptr, err_str(ERR_NOSUCHCHANNEL), me.name, parv[0], channel_name);
- return 0;
- }
-
- if (!IsServer(cptr) && !is_chan_op(sptr, chptr)) {
- sendto_one(sptr, err_str(ERR_CHANOPRIVSNEEDED),
- me.name, parv[0], chptr->chname);
- return 0;
- }
-
- if (MyUser(sptr)) {
- if (!(who = find_chasing(sptr, parv[2], 0)))
- return 0; /* No such user left! */
- }
- else if (!(who = findNUser(parv[2])))
- return 0; /* No such user left! */
- /*
- * if the user is +k, prevent a kick from local user
+ /* Send HACK notice, but not for servers in BURST */
+ /* 2002-10-17: Don't send HACK if the users local server is kicking them */
+ if (IsServer(sptr) &&
+ !IsBurstOrBurstAck(sptr) &&
+ sptr!=cli_user(who)->server)
+ sendto_opmask_butone(0, SNO_HACK4, "HACK: %C KICK %H %C %s", sptr, chptr,
+ who, comment);
+
+ /* Unless someone accepted it downstream (or the user isn't on the channel
+ * here), if kicker is not on channel, or if kicker is not a channel
+ * operator, bounce the kick
*/
- if (IsChannelService(who) && MyUser(sptr)) {
- sendto_one(sptr, err_str(ERR_ISCHANSERVICE), me.name,
- parv[0], who->name, chptr->chname);
- return 0;
- }
+ if (!IsServer(sptr) && member && cli_from(who) != cptr &&
+ (!(sptr_link = find_member_link(chptr, sptr)) || !IsChanOp(sptr_link))) {
+ sendto_opmask_butone(0, SNO_HACK2, "HACK: %C KICK %H %C %s", sptr, chptr,
+ who, comment);
-#ifdef NO_OPER_DEOP_LCHAN
- /*
- * Prevent kicking opers from local channels -DM-
- */
- if (IsOperOnLocalChannel(who, chptr->chname)) {
- sendto_one(sptr, err_str(ERR_ISOPERLCHAN), me.name,
- parv[0], who->name, chptr->chname);
- return 0;
- }
-#endif
+ sendcmdto_one(who, CMD_JOIN, cptr, "%H", chptr);
- /*
- * Servers can now send kicks without hacks during a netburst - they
- * are kicking users from a +i channel.
- * - Isomer 25-11-1999
- */
- if (IsServer(sptr)
-#if defined(NO_INVITE_NETRIDE)
- && !IsBurstOrBurstAck(sptr)
-#endif
- ) {
- send_hack_notice(cptr, sptr, parc, parv, 1, 3);
- }
+ /* Reop/revoice member */
+ if (IsChanOp(member) || HasVoice(member)) {
+ struct ModeBuf mbuf;
+
+ modebuf_init(&mbuf, sptr, cptr, chptr,
+ (MODEBUF_DEST_SERVER | /* Send mode to a server */
+ MODEBUF_DEST_DEOP | /* Deop the source */
+ MODEBUF_DEST_BOUNCE)); /* And bounce the MODE */
- if (IsServer(sptr) ||
- ((member = find_member_link(chptr, who)) && !IsZombie(member)))
- {
- struct Membership* sptr_link = find_member_link(chptr, sptr);
- if (who->from != cptr &&
- ((sptr_link && IsDeopped(sptr_link)) || (!sptr_link && IsUser(sptr))))
- {
- /*
- * Bounce here:
- * cptr must be a server (or cptr == sptr and
- * sptr->flags can't have DEOPPED set
- * when CHANOP is set).
- */
- sendto_one(cptr, "%s%s " TOK_JOIN " %s", NumNick(who), chptr->chname);
if (IsChanOp(member))
- {
- sendto_one(cptr, "%s " TOK_MODE " %s +o %s%s " TIME_T_FMT,
- NumServ(&me), chptr->chname, NumNick(who), chptr->creationtime);
- }
+ modebuf_mode_client(&mbuf, MODE_DEL | MODE_CHANOP, who, OpLevel(member));
if (HasVoice(member))
- {
- sendto_one(cptr, "%s " TOK_MODE " %s +v %s%s " TIME_T_FMT,
- NumServ(&me), chptr->chname, NumNick(who), chptr->creationtime);
- }
+ modebuf_mode_client(&mbuf, MODE_DEL | MODE_VOICE, who, MAXOPLEVEL + 1);
+
+ modebuf_flush(&mbuf);
}
- else
- {
- char* comment = (EmptyString(parv[parc - 1])) ? parv[0] : parv[parc - 1];
- if (strlen(comment) > TOPICLEN)
- comment[TOPICLEN] = '\0';
-
- if (!IsLocalChannel(channel_name))
- {
- sendto_highprot_butone(cptr, 10, "%s%s " TOK_KICK " %s %s%s :%s",
- NumNick(sptr), chptr->chname, NumNick(who), comment);
- }
- if (member) {
- sendto_channel_butserv(chptr, sptr,
- ":%s KICK %s %s :%s", parv[0], chptr->chname, who->name, comment);
- make_zombie(member, who, cptr, sptr, chptr);
+ } else {
+ /* Propagate kick... */
+ sendcmdto_serv_butone(sptr, CMD_KICK, cptr, "%H %C :%s", chptr, who,
+ comment);
+
+ if (member) { /* and tell the channel about it */
+ if (IsDelayedJoin(member)) {
+ if (MyUser(who))
+ sendcmdto_one(IsServer(sptr) ? &his : sptr, CMD_KICK,
+ who, "%H %C :%s", chptr, who, comment);
+ } else {
+ sendcmdto_channel_butserv_butone(IsServer(sptr) ? &his : sptr, CMD_KICK,
+ chptr, NULL, 0, "%H %C :%s", chptr, who,
+ comment);
}
+
+ make_zombie(member, who, cptr, sptr, chptr);
}
}
- else if (MyUser(sptr))
- sendto_one(sptr, err_str(ERR_USERNOTINCHANNEL),
- me.name, parv[0], who->name, chptr->chname);
return 0;
}
-#endif /* 0 */
-