| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
* |
| 4 |
* Copyright (c) 1997-2021 ircd-hybrid development team |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation; either version 2 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 19 |
* USA |
| 20 |
*/ |
| 21 |
|
| 22 |
/*! \file m_kick.c |
| 23 |
* \brief Includes required functions for processing the KICK command. |
| 24 |
* \version $Id$ |
| 25 |
*/ |
| 26 |
|
| 27 |
#include "stdinc.h" |
| 28 |
#include "list.h" |
| 29 |
#include "channel.h" |
| 30 |
#include "channel_mode.h" |
| 31 |
#include "client.h" |
| 32 |
#include "conf.h" |
| 33 |
#include "irc_string.h" |
| 34 |
#include "ircd.h" |
| 35 |
#include "numeric.h" |
| 36 |
#include "send.h" |
| 37 |
#include "modules.h" |
| 38 |
#include "parse.h" |
| 39 |
#include "hash.h" |
| 40 |
#include "packet.h" |
| 41 |
#include "server.h" |
| 42 |
|
| 43 |
|
| 44 |
/*! \brief KICK command handler |
| 45 |
* |
| 46 |
* \param source_p Pointer to allocated Client struct from which the message |
| 47 |
* originally comes from. This can be a local or remote client. |
| 48 |
* \param parc Integer holding the number of supplied arguments. |
| 49 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 50 |
* pointers. |
| 51 |
* \note Valid arguments for this command are: |
| 52 |
* - parv[0] = command |
| 53 |
* - parv[1] = channel name |
| 54 |
* - parv[2] = client to kick |
| 55 |
* - parv[3] = reason |
| 56 |
*/ |
| 57 |
static void |
| 58 |
m_kick(struct Client *source_p, int parc, char *parv[]) |
| 59 |
{ |
| 60 |
struct Channel *channel = hash_find_channel(parv[1]); |
| 61 |
if (channel == NULL) |
| 62 |
{ |
| 63 |
sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[1]); |
| 64 |
return; |
| 65 |
} |
| 66 |
|
| 67 |
struct ChannelMember *member_source = member_find_link(source_p, channel); |
| 68 |
if (member_source == NULL) |
| 69 |
{ |
| 70 |
sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, channel->name); |
| 71 |
return; |
| 72 |
} |
| 73 |
|
| 74 |
if (member_has_flags(member_source, CHFL_CHANOP | CHFL_HALFOP) == false) |
| 75 |
{ |
| 76 |
sendto_one_numeric(source_p, &me, ERR_CHANOPRIVSNEEDED, channel->name); |
| 77 |
return; |
| 78 |
} |
| 79 |
|
| 80 |
struct Client *target_p = find_chasing(source_p, parv[2]); |
| 81 |
if (target_p == NULL) |
| 82 |
return; /* find_chasing sends ERR_NOSUCHNICK */ |
| 83 |
|
| 84 |
struct ChannelMember *member_target = member_find_link(target_p, channel); |
| 85 |
if (member_target == NULL) |
| 86 |
{ |
| 87 |
sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, channel->name); |
| 88 |
return; |
| 89 |
} |
| 90 |
|
| 91 |
if (member_has_flags(member_source, CHFL_CHANOP) == false) |
| 92 |
{ |
| 93 |
if (member_has_flags(member_target, CHFL_CHANOP | CHFL_HALFOP) == true) |
| 94 |
{ |
| 95 |
sendto_one_numeric(source_p, &me, ERR_CHANOPRIVSNEEDED, channel->name); |
| 96 |
return; |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
char reason[KICKLEN + 1]; |
| 101 |
if (!EmptyString(parv[3])) |
| 102 |
strlcpy(reason, parv[3], sizeof(reason)); |
| 103 |
else |
| 104 |
strlcpy(reason, source_p->name, sizeof(reason)); |
| 105 |
|
| 106 |
sendto_channel_local(NULL, channel, 0, 0, 0, ":%s!%s@%s KICK %s %s :%s", |
| 107 |
source_p->name, source_p->username, |
| 108 |
source_p->host, channel->name, |
| 109 |
target_p->name, reason); |
| 110 |
sendto_server(source_p, 0, 0, ":%s KICK %s %s :%s", |
| 111 |
source_p->id, channel->name, |
| 112 |
target_p->id, reason); |
| 113 |
remove_user_from_channel(member_target); |
| 114 |
} |
| 115 |
|
| 116 |
/*! \brief KICK command handler |
| 117 |
* |
| 118 |
* \param source_p Pointer to allocated Client struct from which the message |
| 119 |
* originally comes from. This can be a local or remote client. |
| 120 |
* \param parc Integer holding the number of supplied arguments. |
| 121 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 122 |
* pointers. |
| 123 |
* \note Valid arguments for this command are: |
| 124 |
* - parv[0] = command |
| 125 |
* - parv[1] = channel name |
| 126 |
* - parv[2] = client to kick |
| 127 |
* - parv[3] = reason |
| 128 |
*/ |
| 129 |
static void |
| 130 |
ms_kick(struct Client *source_p, int parc, char *parv[]) |
| 131 |
{ |
| 132 |
struct Channel *channel = hash_find_channel(parv[1]); |
| 133 |
if (channel == NULL) |
| 134 |
return; |
| 135 |
|
| 136 |
struct Client *target_p = find_person(source_p, parv[2]); |
| 137 |
if (target_p == NULL) |
| 138 |
return; |
| 139 |
|
| 140 |
struct ChannelMember *member_target = member_find_link(target_p, channel); |
| 141 |
if (member_target == NULL) |
| 142 |
return; |
| 143 |
|
| 144 |
char reason[KICKLEN + 1]; |
| 145 |
if (!EmptyString(parv[3])) |
| 146 |
strlcpy(reason, parv[3], sizeof(reason)); |
| 147 |
else |
| 148 |
strlcpy(reason, source_p->name, sizeof(reason)); |
| 149 |
|
| 150 |
if (IsClient(source_p)) |
| 151 |
sendto_channel_local(NULL, channel, 0, 0, 0, ":%s!%s@%s KICK %s %s :%s", |
| 152 |
source_p->name, source_p->username, |
| 153 |
source_p->host, channel->name, |
| 154 |
target_p->name, reason); |
| 155 |
else |
| 156 |
sendto_channel_local(NULL, channel, 0, 0, 0, ":%s KICK %s %s :%s", |
| 157 |
IsHidden(source_p) || ConfigServerHide.hide_servers ? me.name : source_p->name, |
| 158 |
channel->name, target_p->name, reason); |
| 159 |
|
| 160 |
sendto_server(source_p, 0, 0, ":%s KICK %s %s :%s", |
| 161 |
source_p->id, channel->name, |
| 162 |
target_p->id, reason); |
| 163 |
remove_user_from_channel(member_target); |
| 164 |
} |
| 165 |
|
| 166 |
static struct Message kick_msgtab = |
| 167 |
{ |
| 168 |
.cmd = "KICK", |
| 169 |
.handlers[UNREGISTERED_HANDLER] = { .handler = m_unregistered }, |
| 170 |
.handlers[CLIENT_HANDLER] = { .handler = m_kick, .args_min = 3, .end_grace_period = true }, |
| 171 |
.handlers[SERVER_HANDLER] = { .handler = ms_kick, .args_min = 3 }, |
| 172 |
.handlers[ENCAP_HANDLER] = { .handler = m_ignore }, |
| 173 |
.handlers[OPER_HANDLER] = { .handler = m_kick, .args_min = 3, .end_grace_period = true } |
| 174 |
}; |
| 175 |
|
| 176 |
static void |
| 177 |
module_init(void) |
| 178 |
{ |
| 179 |
mod_add_cmd(&kick_msgtab); |
| 180 |
} |
| 181 |
|
| 182 |
static void |
| 183 |
module_exit(void) |
| 184 |
{ |
| 185 |
mod_del_cmd(&kick_msgtab); |
| 186 |
} |
| 187 |
|
| 188 |
struct module module_entry = |
| 189 |
{ |
| 190 |
.version = "$Revision$", |
| 191 |
.modinit = module_init, |
| 192 |
.modexit = module_exit, |
| 193 |
.is_core = true |
| 194 |
}; |