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
32 #include "irc_string.h"
33 #include "sprintf_irc.h"
37 #include "s_newconf.h"
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},
64 mapi_clist_av1 restart_clist
[] =
70 /* {{{ DECLARE_MODULE_AV1(...) */
85 * RESTART message handler.
94 mo_restart (struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
98 if (!IsOperDie(source_p
))
100 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
,
101 source_p
->name
, "die");
104 else if (parc
< 2 || EmptyString(parv
[1]))
106 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
), me
.name
,
107 source_p
->name
, "RESTART");
110 else if (strchr(parv
[1], '?') || strchr(parv
[1], '*'))
113 ":%s NOTICE %s :Argument to RESTART cannot contain wildcards",
114 me
.name
, source_p
->name
);
117 else if (!find_server(source_p
, parv
[1]))
119 sendto_one_numeric(source_p
, ERR_NOSUCHSERVER
,
120 form_str(ERR_NOSUCHSERVER
), parv
[1]);
124 is_me
= irccmp(parv
[1], me
.name
) == 0 ? 1 : 0;
125 if (!is_me
&& !ConfigFileEntry
.remote_restart
)
128 ":%s NOTICE %s :Argument to RESTART must local server name (%s)",
129 me
.name
, source_p
->name
, me
.name
);
133 return do_restart(source_p
, parv
[1], !is_me
);
142 me_restart (struct Client
*client_p
, struct Client
*source_p
, int parc
, const char **parv
)
144 if (!IsPerson(source_p
) || !ConfigFileEntry
.remote_restart
)
146 if (!find_client_shared_conf(source_p
, SHARED_DIE
))
149 return do_restart(source_p
, NULL
, 0);
155 * Restart local server or request that a remote server restart.
158 do_restart (struct Client
*source_p
, const char *target
, uint8_t remote
)
160 dlink_node
*cur
= NULL
;
161 struct Client
*target_p
= NULL
;
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
);
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
;
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
));
201 * vim: ts=8 sw=8 noet fdm=marker tw=80