1 /*
2  *  ircd-ratbox: A slightly useful ircd.
3  *  m_okick.c: Kicks a user from a channel with much prejudice.
4  *
5  *  Copyright (C) 2002 by the past and present ircd coders, and others.
6  *  Copyright (C) 2004 ircd-ratbox Development Team
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
21  *  USA
22  *
23  *  $Id: m_okick.c 26094 2008-09-19 15:33:46Z androsyn $
24  */
25 
26 #include "stdinc.h"
27 #include "ratbox_lib.h"
28 #include "struct.h"
29 #include "channel.h"
30 #include "client.h"
31 #include "match.h"
32 #include "ircd.h"
33 #include "numeric.h"
34 #include "send.h"
35 #include "modules.h"
36 #include "parse.h"
37 #include "hash.h"
38 #include "packet.h"
39 #include "s_serv.h"
40 
41 static int mo_okick(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
42 
43 
44 struct Message okick_msgtab = {
45 	"OKICK", 0, 0, 0, MFLG_SLOW,
46 	{mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_okick, 4}}
47 };
48 
49 mapi_clist_av1 okick_clist[] = { &okick_msgtab, NULL };
50 
51 DECLARE_MODULE_AV1(okick, NULL, NULL, okick_clist, NULL, NULL, "$Revision: 26094 $");
52 
53 /*
54 ** m_okick
55 **      parv[0] = sender prefix
56 **      parv[1] = channel
57 **      parv[2] = client to kick
58 **      parv[3] = kick comment
59 */
60 static int
mo_okick(struct Client * client_p,struct Client * source_p,int parc,const char * parv[])61 mo_okick(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
62 {
63 	struct Client *who;
64 	struct Client *target_p;
65 	struct Channel *chptr;
66 	struct membership *msptr;
67 	int chasing = 0;
68 	char *comment;
69 	char *name;
70 	char *p = NULL;
71 	char *user;
72 	static char buf[BUFSIZE];
73 
74 	if(*parv[2] == '\0')
75 	{
76 		sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, parv[0], "KICK");
77 		return 0;
78 	}
79 
80 	if(MyClient(source_p) && !IsFloodDone(source_p))
81 		flood_endgrace(source_p);
82 
83 	comment = (EmptyString(LOCAL_COPY(parv[3]))) ? LOCAL_COPY(parv[2]) : LOCAL_COPY(parv[3]);
84 	if(strlen(comment) > (size_t)REASONLEN)
85 		comment[REASONLEN] = '\0';
86 
87 	*buf = '\0';
88 	if((p = strchr(parv[1], ',')))
89 		*p = '\0';
90 
91 	name = LOCAL_COPY(parv[1]);
92 
93 	chptr = find_channel(name);
94 	if(!chptr)
95 	{
96 		sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), name);
97 		return 0;
98 	}
99 
100 
101 	if((p = strchr(parv[2], ',')))
102 		*p = '\0';
103 	user = LOCAL_COPY(parv[2]);	// strtoken(&p2, parv[2], ",");
104 	if(!(who = find_chasing(source_p, user, &chasing)))
105 	{
106 		return 0;
107 	}
108 
109 	if((target_p = find_client(user)) == NULL)
110 	{
111 		sendto_one(source_p, form_str(ERR_NOSUCHNICK), me.name, parv[0], user);
112 		return 0;
113 	}
114 
115 	if((msptr = find_channel_membership(chptr, target_p)) == NULL)
116 	{
117 		sendto_one(source_p, form_str(ERR_USERNOTINCHANNEL),
118 			   me.name, parv[0], parv[1], parv[2]);
119 		return 0;
120 	}
121 
122 	sendto_channel_local(ALL_MEMBERS, chptr, ":%s KICK %s %s :%s",
123 			     me.name, chptr->chname, who->name, comment);
124 	sendto_server(&me, chptr, NOCAPS, NOCAPS,
125 		      ":%s KICK %s %s :%s", me.name, chptr->chname, who->name, comment);
126 	remove_user_from_channel(msptr);
127 	return 0;
128 }
129