]> jfr.im git - irc/rqf/shadowircd.git/blame - modules/m_admin.c
[svn] Merge old trunk r2081:
[irc/rqf/shadowircd.git] / modules / m_admin.c
CommitLineData
212380e3 1/*
2 * ircd-ratbox: A slightly useful ircd.
3 * m_admin.c: Sends administrative information to a user.
4 *
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
8 *
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.
13 *
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.
18 *
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
23 *
24 * $Id: m_admin.c 254 2005-09-21 23:35:12Z nenolod $
25 */
26
27#include "stdinc.h"
28#include "client.h"
29#include "ircd.h"
30#include "numeric.h"
31#include "s_conf.h"
32#include "s_serv.h"
33#include "send.h"
34#include "msg.h"
35#include "parse.h"
36#include "hook.h"
37#include "modules.h"
38
39static int m_admin(struct Client *, struct Client *, int, const char **);
40static int mr_admin(struct Client *, struct Client *, int, const char **);
41static int ms_admin(struct Client *, struct Client *, int, const char **);
42static void do_admin(struct Client *source_p);
43
44static void admin_spy(struct Client *);
45
46struct Message admin_msgtab = {
47 "ADMIN", 0, 0, 0, MFLG_SLOW | MFLG_UNREG,
48 {{mr_admin, 0}, {m_admin, 0}, {ms_admin, 0}, mg_ignore, mg_ignore, {ms_admin, 0}}
49};
50
51int doing_admin_hook;
52
53mapi_clist_av1 admin_clist[] = { &admin_msgtab, NULL };
54mapi_hlist_av1 admin_hlist[] = {
55 { "doing_admin", &doing_admin_hook },
56 { NULL, NULL }
57};
58
59DECLARE_MODULE_AV1(admin, NULL, NULL, admin_clist, admin_hlist, NULL, "$Revision: 254 $");
60
61/*
62 * mr_admin - ADMIN command handler
63 * parv[0] = sender prefix
64 * parv[1] = servername
65 */
66static int
67mr_admin(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
68{
69 static time_t last_used = 0L;
70
71 if((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
72 {
73 sendto_one(source_p, form_str(RPL_LOAD2HI),
74 me.name,
75 EmptyString(source_p->name) ? "*" : source_p->name,
76 "ADMIN");
77 return 0;
78 }
79 else
80 last_used = CurrentTime;
81
82 do_admin(source_p);
83
84 return 0;
85}
86
87/*
88 * m_admin - ADMIN command handler
89 * parv[0] = sender prefix
90 * parv[1] = servername
91 */
92static int
93m_admin(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
94{
95 static time_t last_used = 0L;
96
97 if(parc > 1)
98 {
99 if((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
100 {
101 sendto_one(source_p, form_str(RPL_LOAD2HI),
102 me.name, source_p->name, "ADMIN");
103 return 0;
104 }
105 else
106 last_used = CurrentTime;
107
108 if(hunt_server(client_p, source_p, ":%s ADMIN :%s", 1, parc, parv) != HUNTED_ISME)
109 return 0;
110 }
111
112 do_admin(source_p);
113
114 return 0;
115}
116
117
118/*
119 * ms_admin - ADMIN command handler, used for OPERS as well
120 * parv[0] = sender prefix
121 * parv[1] = servername
122 */
123static int
124ms_admin(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
125{
126 if(hunt_server(client_p, source_p, ":%s ADMIN :%s", 1, parc, parv) != HUNTED_ISME)
127 return 0;
128
129 do_admin(source_p);
130
131 return 0;
132}
133
134
135/*
136 * do_admin
137 *
138 * inputs - pointer to client to report to
139 * output - none
140 * side effects - admin info is sent to client given
141 */
142static void
143do_admin(struct Client *source_p)
144{
145 const char *myname;
146 const char *nick;
147
148 if(IsPerson(source_p))
149 admin_spy(source_p);
150
151 myname = get_id(&me, source_p);
152 nick = EmptyString(source_p->name) ? "*" : get_id(source_p, source_p);
153
154 sendto_one(source_p, form_str(RPL_ADMINME), myname, nick, me.name);
155 if(AdminInfo.name != NULL)
156 sendto_one(source_p, form_str(RPL_ADMINLOC1), myname, nick, AdminInfo.name);
157 if(AdminInfo.description != NULL)
158 sendto_one(source_p, form_str(RPL_ADMINLOC2), myname, nick, AdminInfo.description);
159 if(AdminInfo.email != NULL)
160 sendto_one(source_p, form_str(RPL_ADMINEMAIL), myname, nick, AdminInfo.email);
161}
162
163/* admin_spy()
164 *
165 * input - pointer to client
166 * output - none
167 * side effects - event doing_admin is called
168 */
169static void
170admin_spy(struct Client *source_p)
171{
172 hook_data hd;
173
174 hd.client = source_p;
175 hd.arg1 = hd.arg2 = NULL;
176
177 call_hook(doing_admin_hook, &hd);
178}