More RCS keyword removal...
[seven-1.x.git] / modules / core / m_die.c
blobe0b94a3b09b78ed05df718e2b282a846d01edb06
1 /* {{{ irc-seven: Cows like it.
3 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
4 * Copyright (C) 1996-2002 Hybrid Development Team
5 * Copyright (C) 2002-2005 ircd-ratbox development team
6 * Copyright (c) 2006 Elfyn McBratney.
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.
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.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to:
21 * Free Software Foundation, Inc.
22 * 51 Franklin St - Fifth Floor
23 * Boston, MA 02110-1301
24 * USA
26 * }}} */
28 /* {{{ Includes. */
29 #include "stdinc.h"
30 #include "tools.h"
31 #include "client.h"
32 #include "ircd.h"
33 #include "irc_string.h"
34 #include "numeric.h"
35 #include "commio.h"
36 #include "s_log.h"
37 #include "s_conf.h"
38 #include "s_newconf.h"
39 #include "s_serv.h"
40 #include "send.h"
41 #include "msg.h"
42 #include "parse.h"
43 #include "modules.h"
44 #include "hash.h"
45 /* }}} */
47 static int mo_die (struct Client *, struct Client *, int, const char **);
48 static int me_die (struct Client *, struct Client *, int, const char **);
50 static int do_die (struct Client *, const char *, uint8_t);
52 /* {{{ static struct Message die_msgtab = { ... } */
53 static struct Message die_msgtab =
55 "DIE", 0, 0, 0, MFLG_SLOW,
57 mg_unreg, mg_not_oper, mg_ignore,
58 mg_ignore, {me_die, 0}, {mo_die, 0},
61 /* }}} */
63 mapi_clist_av1 die_clist[] =
65 &die_msgtab,
66 NULL,
69 /* {{{ DECLARE_MODULE_AV1(...) */
70 DECLARE_MODULE_AV1
72 die,
73 NULL,
74 NULL,
75 die_clist,
76 NULL,
77 NULL,
78 "$Revision: 195 $"
80 /* }}} */
82 /* {{{ mo_die()
84 * DIE message handler.
86 * Usage:
87 * DIE <server>
89 * parv[0] - prefix
90 * parv[1] - server
92 static int
93 mo_die (struct Client *client_p, struct Client *source_p, int parc, const char **parv)
95 uint8_t is_me;
97 if (!IsOperDie(source_p))
99 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
100 source_p->name, "die");
101 return 0;
103 else if (parc < 2 || EmptyString(parv[1]))
105 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name,
106 source_p->name, "DIE");
107 return 0;
109 else if (strchr(parv[1], '?') || strchr(parv[1], '*'))
111 sendto_one(source_p,
112 ":%s NOTICE %s :Argument to DIE cannot contain wildcards",
113 me.name, source_p->name);
114 return 0;
116 else if (!find_server(source_p, parv[1]))
118 sendto_one_numeric(source_p, ERR_NOSUCHSERVER,
119 form_str(ERR_NOSUCHSERVER), parv[1]);
120 return 0;
123 is_me = irccmp(parv[1], me.name) == 0 ? 1 : 0;
124 if (!is_me && !ConfigFileEntry.remote_die)
126 sendto_one(source_p,
127 ":%s NOTICE %s :Argument to DIE must local server name (%s)",
128 me.name, source_p->name, me.name);
129 return 0;
132 return do_die(source_p, parv[1], !is_me);
134 /* }}} */
136 /* {{{ me_die()
138 * DIE ENCAP message handler.
140 * parv[0] - prefix
142 static int
143 me_die (struct Client *client_p, struct Client *source_p, int parc, const char **parv)
145 if (!IsPerson(source_p) || !ConfigFileEntry.remote_die)
146 return 0;
147 if (!find_client_shared_conf(source_p, SHARED_DIE))
148 return 0;
150 return do_die(source_p, NULL, 0);
152 /* }}} */
154 /* {{{ do_die()
156 * Restart local server or request that a remote server restart.
158 static int
159 do_die (struct Client *source_p, const char *target, uint8_t remote)
161 dlink_node *cur = NULL;
162 struct Client *target_p = NULL;
164 if (remote)
166 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
167 "%s is requesting shutdown of %s",
168 get_oper_name(source_p), target);
169 sendto_match_servs(source_p, target, CAP_ENCAP, NOCAPS,
170 "ENCAP %s DIE", target);
172 return 0;
175 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is shutting down %s...",
176 get_oper_name(source_p), me.name);
178 DLINK_FOREACH (cur, lclient_list.head)
180 target_p = cur->data;
181 sendto_one(target_p,
182 ":%s NOTICE %s :Server Terminating.",
183 me.name, target_p->name);
186 DLINK_FOREACH (cur, serv_list.head)
188 target_p = cur->data;
189 sendto_one(target_p, ":%s ERROR :Terminated by %s",
190 me.name, get_client_name(source_p, HIDE_IP));
193 ilog(L_MAIN, "Server terminated by %s", get_oper_name(source_p));
194 unlink(pidFileName);
195 exit(0);
197 /* not reached. */
198 return 0;
200 /* }}} */
203 * vim: ts=8 sw=8 noet fdm=marker tw=80