ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/core/m_kick.c
Revision: 8752
Committed: Tue Jan 1 11:07:01 2019 UTC (5 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 6269 byte(s)
Log Message:
- Update copyright years

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2019 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 int
58 m_kick(struct Client *source_p, int parc, char *parv[])
59 {
60 char reason[KICKLEN + 1] = "";
61 struct Client *target_p = NULL;
62 struct Channel *chptr = NULL;
63 struct Membership *member_source = NULL;
64 struct Membership *member_target = NULL;
65
66 if (EmptyString(parv[2]))
67 {
68 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "KICK");
69 return 0;
70 }
71
72 if ((chptr = hash_find_channel(parv[1])) == NULL)
73 {
74 sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[1]);
75 return 0;
76 }
77
78 if ((member_source = find_channel_link(source_p, chptr)) == NULL)
79 {
80 sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->name);
81 return 0;
82 }
83
84 if (!has_member_flags(member_source, CHFL_CHANOP | CHFL_HALFOP))
85 {
86 sendto_one_numeric(source_p, &me, ERR_CHANOPRIVSNEEDED, chptr->name);
87 return 0;
88 }
89
90 if ((target_p = find_chasing(source_p, parv[2])) == NULL)
91 return 0; /* find_chasing sends ERR_NOSUCHNICK */
92
93 if ((member_target = find_channel_link(target_p, chptr)) == NULL)
94 {
95 sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->name);
96 return 0;
97 }
98
99 if (has_member_flags(member_source, CHFL_HALFOP) && !has_member_flags(member_source, CHFL_CHANOP))
100 {
101 if (has_member_flags(member_target, CHFL_CHANOP | CHFL_HALFOP))
102 {
103 sendto_one_numeric(source_p, &me, ERR_CHANOPRIVSNEEDED, chptr->name);
104 return 0;
105 }
106 }
107
108 if (!EmptyString(parv[3]))
109 strlcpy(reason, parv[3], sizeof(reason));
110 else
111 strlcpy(reason, source_p->name, sizeof(reason));
112
113 sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s!%s@%s KICK %s %s :%s",
114 source_p->name, source_p->username,
115 source_p->host, chptr->name,
116 target_p->name, reason);
117 sendto_server(source_p, 0, 0, ":%s KICK %s %s :%s",
118 source_p->id, chptr->name,
119 target_p->id, reason);
120 remove_user_from_channel(member_target);
121 return 0;
122 }
123
124 /*! \brief KICK command handler
125 *
126 * \param source_p Pointer to allocated Client struct from which the message
127 * originally comes from. This can be a local or remote client.
128 * \param parc Integer holding the number of supplied arguments.
129 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
130 * pointers.
131 * \note Valid arguments for this command are:
132 * - parv[0] = command
133 * - parv[1] = channel name
134 * - parv[2] = client to kick
135 * - parv[3] = reason
136 */
137 static int
138 ms_kick(struct Client *source_p, int parc, char *parv[])
139 {
140 char reason[KICKLEN + 1] = "";
141 struct Client *target_p = NULL;
142 struct Channel *chptr = NULL;
143 struct Membership *member_target = NULL;
144
145 if (EmptyString(parv[2]))
146 return 0;
147
148 if ((chptr = hash_find_channel(parv[1])) == NULL)
149 return 0;
150
151 if ((target_p = find_person(source_p, parv[2])) == NULL)
152 return 0;
153
154 if ((member_target = find_channel_link(target_p, chptr)) == NULL)
155 return 0;
156
157 if (!EmptyString(parv[3]))
158 strlcpy(reason, parv[3], sizeof(reason));
159 else
160 strlcpy(reason, source_p->name, sizeof(reason));
161
162 if (IsClient(source_p))
163 sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s!%s@%s KICK %s %s :%s",
164 source_p->name, source_p->username,
165 source_p->host, chptr->name,
166 target_p->name, reason);
167 else
168 sendto_channel_local(NULL, chptr, 0, 0, 0, ":%s KICK %s %s :%s",
169 IsHidden(source_p) || ConfigServerHide.hide_servers ? me.name : source_p->name,
170 chptr->name, target_p->name, reason);
171
172 sendto_server(source_p, 0, 0, ":%s KICK %s %s :%s",
173 source_p->id, chptr->name,
174 target_p->id, reason);
175 remove_user_from_channel(member_target);
176 return 0;
177 }
178
179 static struct Message kick_msgtab =
180 {
181 .cmd = "KICK",
182 .args_min = 3,
183 .args_max = MAXPARA,
184 .flags = MFLG_ENDGRACE,
185 .handlers[UNREGISTERED_HANDLER] = m_unregistered,
186 .handlers[CLIENT_HANDLER] = m_kick,
187 .handlers[SERVER_HANDLER] = ms_kick,
188 .handlers[ENCAP_HANDLER] = m_ignore,
189 .handlers[OPER_HANDLER] = m_kick
190 };
191
192 static void
193 module_init(void)
194 {
195 mod_add_cmd(&kick_msgtab);
196 }
197
198 static void
199 module_exit(void)
200 {
201 mod_del_cmd(&kick_msgtab);
202 }
203
204 struct module module_entry =
205 {
206 .version = "$Revision$",
207 .modinit = module_init,
208 .modexit = module_exit,
209 .is_core = true
210 };

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision