More RCS keyword removal...
[seven-1.x.git] / modules / core / m_kill.c
blob78e890df4cb394c3393c5a50dd6aa3e59a75ec3d
1 /*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_kill.c: Kills a user.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
25 #include "stdinc.h"
26 #include "client.h"
27 #include "hash.h" /* for find_client() */
28 #include "ircd.h"
29 #include "numeric.h"
30 #include "sprintf_irc.h"
31 #include "s_log.h"
32 #include "s_serv.h"
33 #include "s_conf.h"
34 #include "send.h"
35 #include "whowas.h"
36 #include "irc_string.h"
37 #include "msg.h"
38 #include "parse.h"
39 #include "modules.h"
40 #include "s_newconf.h"
42 static char buf[BUFSIZE];
44 static int ms_kill(struct Client *, struct Client *, int, const char **);
45 static int mo_kill(struct Client *, struct Client *, int, const char **);
46 static void relay_kill(struct Client *, struct Client *, struct Client *,
47 const char *, const char *);
49 static struct Message kill_msgtab = {
50 "KILL", 0, 0, 0, MFLG_SLOW,
51 {mg_unreg, mg_not_oper, {ms_kill, 2}, {ms_kill, 2}, mg_ignore, {mo_kill, 2}}
54 mapi_clist_av1 kill_clist[] = { &kill_msgtab, NULL };
56 DECLARE_MODULE_AV1(kill, NULL, NULL, kill_clist, NULL, NULL, "$Revision: 108 $");
59 ** mo_kill
60 ** parv[0] = sender prefix
61 ** parv[1] = kill victim
62 ** parv[2] = kill path
64 static int
65 mo_kill(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
67 struct Client *target_p;
68 const char *inpath = client_p->name;
69 const char *user;
70 const char *reason;
72 user = parv[1];
74 if(!IsOperKill(source_p))
76 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "kill");
77 return 0;
80 if(!EmptyString(parv[2]))
82 char *s;
83 s = LOCAL_COPY(parv[2]);
84 if(strlen(s) > (size_t) KILLLEN)
85 s[KILLLEN] = '\0';
86 reason = s;
88 else
89 reason = "<No reason given>";
91 if((target_p = find_named_person(user)) == NULL)
94 ** If the user has recently changed nick, automatically
95 ** rewrite the KILL for this new nickname--this keeps
96 ** servers in synch when nick change and kill collide
98 if((target_p = get_history(user, (long) KILLCHASETIMELIMIT)) == NULL)
100 if (strchr(user, '.'))
101 sendto_one_numeric(source_p, ERR_CANTKILLSERVER, form_str(ERR_CANTKILLSERVER));
102 else
103 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
104 form_str(ERR_NOSUCHNICK), user);
105 return 0;
107 sendto_one(source_p, ":%s NOTICE %s :KILL changed from %s to %s",
108 me.name, parv[0], user, target_p->name);
111 if (MyClient(source_p) && IsService(target_p))
113 sendto_one(source_p, form_str(ERR_ISCHANSERVICE),
114 me.name, source_p->name, target_p->name, "*");
115 return 0;
118 if(MyConnect(target_p))
119 sendto_one(target_p, ":%s!%s@%s KILL %s :%s",
120 source_p->name, source_p->username, source_p->host,
121 target_p->name, reason);
123 /* Do not change the format of this message. There's no point in changing messages
124 * that have been around for ever, for no reason..
126 * If target is local, send the message netwide. Global kills will cause all servers
127 * to send out snotes locally in ms_kill. --spb */
128 sendto_realops_snomask(SNO_GENERAL, MyClient(target_p) ? L_NETWIDE : L_ALL,
129 "Received KILL message for %s. From %s Path: %s (%s)",
130 target_p->name, parv[0], me.name, reason);
132 ilog(L_KILL, "%c %s %s!%s@%s %s %s",
133 MyConnect(target_p) ? 'L' : 'G', get_oper_name(source_p),
134 target_p->name, target_p->username, target_p->host, target_p->user->server, reason);
137 ** And pass on the message to other servers. Note, that if KILL
138 ** was changed, the message has to be sent to all links, also
139 ** back.
140 ** Suicide kills are NOT passed on --SRB
142 if(!MyConnect(target_p))
144 relay_kill(client_p, source_p, target_p, inpath, reason);
146 ** Set FLAGS_KILLED. This prevents exit_one_client from sending
147 ** the unnecessary QUIT for this. (This flag should never be
148 ** set in any other place)
150 target_p->flags |= FLAGS_KILLED;
153 ircsprintf(buf, "Killed by %s (%s)", source_p->name, reason);
155 exit_client(client_p, target_p, source_p, buf);
157 return 0;
161 * ms_kill
162 * parv[0] = sender prefix
163 * parv[1] = kill victim
164 * parv[2] = kill path and reason
166 static int
167 ms_kill(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
169 struct Client *target_p;
170 const char *user;
171 const char *reason;
172 char default_reason[] = "<No reason given>";
173 const char *path;
174 int chasing = 0;
176 *buf = '\0';
178 user = parv[1];
180 if(EmptyString(parv[2]))
182 reason = default_reason;
184 /* hyb6 takes the nick of the killer from the path *sigh* --fl_ */
185 path = source_p->name;
187 else
189 char *s = LOCAL_COPY(parv[2]), *t;
190 t = strchr(s, ' ');
192 if(t)
194 *t = '\0';
195 t++;
196 reason = t;
198 else
199 reason = default_reason;
201 path = s;
204 if((target_p = find_person(user)) == NULL)
207 * If the user has recently changed nick, but only if its
208 * not an uid, automatically rewrite the KILL for this new nickname.
209 * --this keeps servers in synch when nick change and kill collide
211 if(IsDigit(*user) || (!(target_p = get_history(user, (long) KILLCHASETIMELIMIT))))
213 sendto_one_numeric(source_p, ERR_NOSUCHNICK,
214 form_str(ERR_NOSUCHNICK), IsDigit(*user) ? "*" : user);
215 return 0;
217 sendto_one_notice(source_p, ":KILL changed from %s to %s", user, target_p->name);
218 chasing = 1;
221 if(IsServer(target_p) || IsMe(target_p))
223 sendto_one_numeric(source_p, ERR_CANTKILLSERVER, form_str(ERR_CANTKILLSERVER));
224 return 0;
227 if(MyConnect(target_p))
229 if(IsServer(source_p))
231 sendto_one(target_p, ":%s KILL %s :%s",
232 source_p->name, target_p->name, reason);
234 else
235 sendto_one(target_p, ":%s!%s@%s KILL %s :%s",
236 source_p->name, source_p->username, source_p->host,
237 target_p->name, reason);
240 /* Be warned, this message must be From %s, or it confuses clients
241 * so dont change it to From: or the case or anything! -- fl -- db */
242 /* path must contain at least 2 !'s, or bitchx falsely declares it
243 * local --fl
245 if(IsOper(source_p)) /* send it normally */
247 /* Send this from the server that originated the kill, for consistency with
248 * local kill messages. --spb */
249 sendto_realops_snomask_from(IsService(source_p) ? SNO_SKILL : SNO_GENERAL, L_ALL,
250 source_p->servptr,
251 "Received KILL message for %s. From %s Path: %s!%s!%s!%s %s",
252 target_p->name, parv[0], source_p->user->server,
253 source_p->host, source_p->username, source_p->name, reason);
255 ilog(L_KILL, "%c %s %s!%s@%s %s %s",
256 MyConnect(target_p) ? 'O' : 'R', get_oper_name(source_p),
257 target_p->name, target_p->username, target_p->host,
258 target_p->user->server, reason);
260 else
262 sendto_realops_snomask(SNO_SKILL, L_ALL,
263 "Received KILL message for %s. From %s %s",
264 target_p->name, parv[0], reason);
266 ilog(L_KILL, "S %s %s!%s@%s %s %s",
267 source_p->name, target_p->name, target_p->username,
268 target_p->host, target_p->user->server, reason);
271 relay_kill(client_p, source_p, target_p, path, reason);
273 /* FLAGS_KILLED prevents a quit being sent out */
274 target_p->flags |= FLAGS_KILLED;
276 ircsprintf(buf, "Killed (%s %s)", source_p->name, reason);
278 exit_client(client_p, target_p, source_p, buf);
280 return 0;
283 static void
284 relay_kill(struct Client *one, struct Client *source_p,
285 struct Client *target_p, const char *inpath, const char *reason)
287 struct Client *client_p;
288 dlink_node *ptr;
289 char buffer[BUFSIZE];
291 if(MyClient(source_p))
292 ircsnprintf(buffer, sizeof(buffer),
293 "%s!%s!%s!%s (%s)",
294 me.name, source_p->host, source_p->username, source_p->name, reason);
295 else
296 ircsnprintf(buffer, sizeof(buffer), "%s %s", inpath, reason);
298 DLINK_FOREACH(ptr, serv_list.head)
300 client_p = ptr->data;
302 if(!client_p || client_p == one)
303 continue;
305 sendto_one(client_p, ":%s KILL %s :%s",
306 get_id(source_p, client_p), get_id(target_p, client_p), buffer);