ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/core/m_kick.c
Revision: 3204
Committed: Mon Mar 24 19:42:47 2014 UTC (11 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 5470 byte(s)
Log Message:
- m_kick.c: incorporate some of Adam's cleanups.

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2820 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 2820 * Copyright (c) 1997-2014 ircd-hybrid development team
5 adx 30 *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19     * USA
20     */
21    
22 michael 2820 /*! \file m_kick.c
23     * \brief Includes required functions for processing the KICK command.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28 michael 1011 #include "list.h"
29 adx 30 #include "channel.h"
30     #include "channel_mode.h"
31     #include "client.h"
32     #include "irc_string.h"
33     #include "ircd.h"
34     #include "numeric.h"
35     #include "send.h"
36     #include "modules.h"
37     #include "parse.h"
38     #include "hash.h"
39     #include "packet.h"
40     #include "s_serv.h"
41    
42    
43     /* m_kick()
44 michael 3096 * parv[0] = command
45 adx 30 * parv[1] = channel
46     * parv[2] = client to kick
47     * parv[3] = kick comment
48     */
49 michael 2820 static int
50 michael 3156 m_kick(struct Client *source_p, int parc, char *parv[])
51 adx 30 {
52 michael 3198 char reason[KICKLEN + 1] = "";
53 michael 3196 struct Client *target_p = NULL;
54 michael 3198 struct Channel *chptr = NULL;
55     struct Membership *ms_source = NULL;
56     struct Membership *ms_target = NULL;
57 adx 30
58 michael 885 if (EmptyString(parv[2]))
59 adx 30 {
60 michael 3109 sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "KICK");
61 michael 2820 return 0;
62 adx 30 }
63    
64 michael 3204 if (!IsFloodDone(source_p))
65 adx 30 flood_endgrace(source_p);
66    
67 michael 3198 if ((chptr = hash_find_channel(parv[1])) == NULL)
68 adx 30 {
69 michael 3198 sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, parv[1]);
70 michael 2820 return 0;
71 adx 30 }
72    
73 michael 3204 if ((ms_source = find_channel_link(source_p, chptr)) == NULL)
74 adx 30 {
75 michael 3204 sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->chname);
76     return 0;
77     }
78 adx 30
79 michael 3204 if (!has_member_flags(ms_source, CHFL_CHANOP|CHFL_HALFOP))
80     {
81     sendto_one_numeric(source_p, &me, ERR_CHANOPRIVSNEEDED, chptr->chname);
82     return 0;
83 adx 30 }
84    
85 michael 3198 if ((target_p = find_chasing(source_p, parv[2])) == NULL)
86 michael 3204 return 0; /* find_chasing sends ERR_NOSUCHNICK */
87    
88     if (!(ms_target = find_channel_link(target_p, chptr)))
89     {
90     sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->chname);
91 michael 2820 return 0;
92 michael 3204 }
93 adx 30
94 michael 3204 #ifdef HALFOPS
95     /* half ops cannot kick other halfops on private channels */
96     if (has_member_flags(ms_source, CHFL_HALFOP) && !has_member_flags(ms_source, CHFL_CHANOP))
97 adx 30 {
98 michael 3204 if (((chptr->mode.mode & MODE_PRIVATE) && has_member_flags(ms_target,
99     CHFL_CHANOP|CHFL_HALFOP)) || has_member_flags(ms_target, CHFL_CHANOP))
100 adx 30 {
101 michael 3204 sendto_one_numeric(source_p, &me, ERR_CHANOPRIVSNEEDED, chptr->chname);
102     return 0;
103 adx 30 }
104 michael 3204 }
105 adx 30 #endif
106 michael 3204 if (!EmptyString(parv[3]))
107     strlcpy(reason, parv[3], sizeof(reason));
108     else
109     strlcpy(reason, source_p->name, sizeof(reason));
110 adx 30
111 michael 3204 sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s KICK %s %s :%s",
112     source_p->name, source_p->username,
113     source_p->host, chptr->chname,
114     target_p->name, reason);
115     sendto_server(source_p, NOCAPS, NOCAPS, ":%s KICK %s %s :%s",
116     source_p->id, chptr->chname,
117     target_p->id, reason);
118     remove_user_from_channel(ms_target);
119     return 0;
120     }
121 adx 30
122 michael 3204 /* ms_kick()
123     * parv[0] = command
124     * parv[1] = channel
125     * parv[2] = client to kick
126     * parv[3] = kick comment
127     */
128     static int
129     ms_kick(struct Client *source_p, int parc, char *parv[])
130     {
131     char reason[KICKLEN + 1] = "";
132     struct Client *target_p = NULL;
133     struct Channel *chptr = NULL;
134     struct Membership *ms_target = NULL;
135    
136     if (EmptyString(parv[2]))
137     return 0;
138    
139     if ((chptr = hash_find_channel(parv[1])) == NULL)
140     return 0;
141    
142     if ((target_p = hash_find_id(parv[2])) == NULL || !IsClient(target_p))
143     return 0;
144    
145     if ((ms_target = find_channel_link(target_p, chptr)) == NULL)
146     return 0;
147    
148     if (!EmptyString(parv[3]))
149     strlcpy(reason, parv[3], sizeof(reason));
150 adx 30 else
151 michael 3204 strlcpy(reason, source_p->name, sizeof(reason));
152 michael 3109
153 michael 3204 if (IsServer(source_p))
154     sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s KICK %s %s :%s",
155     source_p->name, chptr->chname,
156     target_p->name, reason);
157     else
158     sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s KICK %s %s :%s",
159     source_p->name, source_p->username,
160     source_p->host, chptr->chname,
161     target_p->name, reason);
162    
163     sendto_server(source_p, NOCAPS, NOCAPS, ":%s KICK %s %s :%s",
164     source_p->id, chptr->chname,
165     target_p->id, reason);
166     remove_user_from_channel(ms_target);
167 michael 2820 return 0;
168 adx 30 }
169 michael 1230
170 michael 2820 static struct Message kick_msgtab =
171     {
172 michael 1230 "KICK", 0, 0, 3, MAXPARA, MFLG_SLOW, 0,
173 michael 3204 { m_unregistered, m_kick, ms_kick, m_ignore, m_kick, m_ignore }
174 michael 1230 };
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 michael 2820 struct module module_entry =
189     {
190 michael 1230 .node = { NULL, NULL, NULL },
191     .name = NULL,
192     .version = "$Revision$",
193     .handle = NULL,
194     .modinit = module_init,
195     .modexit = module_exit,
196     .flags = MODULE_FLAG_CORE
197     };

Properties

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