ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/core/m_kick.c
Revision: 6380
Committed: Fri Aug 21 10:53:32 2015 UTC (8 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 6269 byte(s)
Log Message:
- m_kick.c: doxygen

File Contents

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

Properties

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