Remove cruft left behind by removed stats_p_hook.
[seven-1.x.git] / modules / m_restart.c
bloba55c425a106e1187b0e9f3c7fd079abc93c1bab5
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 "client.h"
31 #include "common.h"
32 #include "irc_string.h"
33 #include "sprintf_irc.h"
34 #include "ircd.h"
35 #include "numeric.h"
36 #include "s_conf.h"
37 #include "s_newconf.h"
38 #include "s_log.h"
39 #include "s_serv.h"
40 #include "restart.h"
41 #include "send.h"
42 #include "msg.h"
43 #include "parse.h"
44 #include "modules.h"
45 #include "hash.h"
46 /* }}} */
48 static int mo_restart (struct Client *, struct Client *, int, const char **);
49 static int me_restart (struct Client *, struct Client *, int, const char **);
51 static int do_restart (struct Client *, const char *, uint8_t);
53 /* {{{ struct Message restart_msgtab = { ... } */
54 struct Message restart_msgtab =
56 "RESTART", 0, 0, 0, MFLG_SLOW,
58 mg_unreg, mg_not_oper, mg_ignore,
59 mg_ignore, {me_restart, 0}, {mo_restart, 0},
62 /* }}} */
64 mapi_clist_av1 restart_clist[] =
66 &restart_msgtab,
67 NULL,
70 /* {{{ DECLARE_MODULE_AV1(...) */
71 DECLARE_MODULE_AV1
73 restart,
74 NULL,
75 NULL,
76 restart_clist,
77 NULL,
78 NULL,
79 "$Revision: 195 $"
81 /* }}} */
83 /* {{{ mo_restart()
85 * RESTART message handler.
87 * Usage:
88 * RESTART <target>
90 * parv[0] - prefix
91 * parv[1] - target
93 static int
94 mo_restart (struct Client *client_p, struct Client *source_p, int parc, const char **parv)
96 uint8_t is_me;
98 if (!IsOperDie(source_p))
100 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
101 source_p->name, "die");
102 return 0;
104 else if (parc < 2 || EmptyString(parv[1]))
106 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name,
107 source_p->name, "RESTART");
108 return 0;
110 else if (strchr(parv[1], '?') || strchr(parv[1], '*'))
112 sendto_one(source_p,
113 ":%s NOTICE %s :Argument to RESTART cannot contain wildcards",
114 me.name, source_p->name);
115 return 0;
117 else if (!find_server(source_p, parv[1]))
119 sendto_one_numeric(source_p, ERR_NOSUCHSERVER,
120 form_str(ERR_NOSUCHSERVER), parv[1]);
121 return 0;
124 is_me = irccmp(parv[1], me.name) == 0 ? 1 : 0;
125 if (!is_me && !ConfigFileEntry.remote_restart)
127 sendto_one(source_p,
128 ":%s NOTICE %s :Argument to RESTART must local server name (%s)",
129 me.name, source_p->name, me.name);
130 return 0;
133 return do_restart(source_p, parv[1], !is_me);
135 /* }}} */
137 /* {{{ me_restart()
139 * parv[0] - prefix
141 static int
142 me_restart (struct Client *client_p, struct Client *source_p, int parc, const char **parv)
144 if (!IsPerson(source_p) || !ConfigFileEntry.remote_restart)
145 return 0;
146 if (!find_client_shared_conf(source_p, SHARED_DIE))
147 return 0;
149 return do_restart(source_p, NULL, 0);
151 /* }}} */
153 /* {{{ do_restart()
155 * Restart local server or request that a remote server restart.
157 static int
158 do_restart (struct Client *source_p, const char *target, uint8_t remote)
160 dlink_node *cur = NULL;
161 struct Client *target_p = NULL;
162 char buf[BUFSIZE];
164 if (remote)
166 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
167 "%s is requesting restart of %s",
168 get_oper_name(source_p), target);
169 sendto_match_servs(source_p, target, CAP_ENCAP, NOCAPS,
170 "ENCAP %s RESTART", target);
172 return 0;
175 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is restarting %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 Restarting.",
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 :Restart by %s",
190 me.name, get_client_name(source_p, HIDE_IP));
193 ircsprintf(buf, "Server RESTART by %s", get_client_name(source_p, HIDE_IP));
194 restart(buf);
196 return 0;
198 /* }}} */
201 * vim: ts=8 sw=8 noet fdm=marker tw=80