Implemented initial support for zombie mode by Jan Krüger <jk@jk.gs>
[ircu2.10.12-pk.git] / ircd / m_unzombie.c
1 /*
2  * IRC - Internet Relay Chat, ircd/m_unzombie.c
3  * Copyright (C) 2011 Jan Krueger <jk@jk.gs>
4  *
5  * See file AUTHORS in IRC package for additional names of
6  * the programmers.
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 1, or (at your option)
11  * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  * $Id$
23  */
24
25 #include "config.h"
26
27 #include "client.h"
28 #include "ircd.h"
29 #include "ircd_log.h"
30 #include "ircd_reply.h"
31 #include "ircd_string.h"
32 #include "msg.h"
33 #include "numnicks.h"
34 #include "s_debug.h"
35 #include "s_misc.h"
36 #include "s_user.h"
37 #include "send.h"
38
39 #include <stdlib.h>
40 #include <string.h>
41
42 /** Handle an UNZOMBIE message from a server connection.
43  *
44  * \a parv has the following elements:
45  * \li \a parv[1] is the numnick of the client attaching to the zombie
46  * \li \a parv[2] is the numnick of the zombie
47  *
48  * See @ref m_functions for discussion of the arguments.
49  * @param[in] cptr Client that sent us the message.
50  * @param[in] sptr Original source of message.
51  * @param[in] parc Number of arguments.
52  * @param[in] parv Argument vector.
53  */
54 int ms_unzombie(struct Client* cptr, struct Client* sptr, int parc,
55                char* parv[])
56 {
57   struct Client *acptr;
58   struct Client *victim;
59
60   if (parc < 3)
61     return need_more_params(sptr, "UNZOMBIE");
62
63   if (!IsServer(sptr))
64     return protocol_violation(cptr, "UNZOMBIE from non-server %s",
65                               cli_name(sptr));
66
67   if (!(acptr = findNUser(parv[1])))
68     return 0; /* If this is colliding with a QUIT, let the QUIT win */
69
70   if (!(victim = findNUser(parv[2])))
71     /* TODO send error */
72     ;
73
74   if (!IsNotConn(victim))
75     return protocol_violation(cptr, "UNZOMBIE trying to attach to non-zombie %s",
76                               cli_name(victim));
77   assert(IsAccount(victim));
78
79   unzombie_client(cptr, sptr, acptr, victim);
80   return 0;
81 }