ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_admin.c
Revision: 442
Committed: Sat Feb 11 23:14:21 2006 UTC (20 years, 6 months ago) by adx
Content type: text/x-csrc
File size: 6440 byte(s)
Log Message:
+ massive rewrite of module init/deinit/version headers,
  we are introducing a new module manager which deals with static
  and dynamic modules exactly the same way. (New possibilities
  include loading/unloading statically compiled modules and
  mixing static/dynamic ones in one build.)

File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * m_admin.c: Sends administrative information to a user.
4     *
5     * Copyright (C) 2002 by the past and present ircd coders, and others.
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20     * USA
21     *
22 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26     #include "handlers.h"
27     #include "client.h"
28     #include "ircd.h"
29     #include "numeric.h"
30     #include "s_conf.h"
31     #include "s_serv.h"
32     #include "send.h"
33     #include "msg.h"
34     #include "parse.h"
35     #include "modules.h"
36    
37 michael 347 static void m_admin(struct Client *, struct Client *, int, char *[]);
38     static void mr_admin(struct Client *, struct Client *, int, char *[]);
39     static void ms_admin(struct Client *, struct Client *, int, char *[]);
40 adx 30 static void do_admin(struct Client *);
41    
42     struct Message admin_msgtab = {
43     "ADMIN", 0, 0, 0, 0, MFLG_SLOW | MFLG_UNREG, 0,
44 michael 345 { mr_admin, m_admin, ms_admin, m_ignore, ms_admin, m_ignore }
45 adx 30 };
46    
47 michael 347 static struct Callback *admin_cb = NULL;
48 adx 30
49     static void *
50     va_admin(va_list args)
51     {
52     do_admin(va_arg(args, struct Client *));
53     return NULL;
54     }
55    
56 adx 442 INIT_MODULE(m_admin, "$Revision$")
57 adx 30 {
58     admin_cb = register_callback("doing_admin", va_admin);
59     mod_add_cmd(&admin_msgtab);
60     }
61    
62 adx 442 CLEANUP_MODULE
63 adx 30 {
64     mod_del_cmd(&admin_msgtab);
65     uninstall_hook(admin_cb, va_admin);
66     }
67    
68 michael 345 /*! \brief ADMIN command handler (called for unregistered clients only)
69     *
70     * \param client_p Pointer to allocated Client struct with physical connection
71     * to this server, i.e. with an open socket connected.
72     * \param source_p Pointer to allocated Client struct from which the message
73     * originally comes from. This can be a local or remote client.
74     * \param parc Integer holding the number of supplied arguments.
75     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
76     * pointers.
77     * \note Valid arguments for this command are:
78     * - parv[0] = sender prefix
79 michael 347 * - parv[1] = name of target (rejected for unregistered clients)
80 adx 30 */
81     static void
82     mr_admin(struct Client *client_p, struct Client *source_p,
83     int parc, char *parv[])
84     {
85     static time_t last_used = 0;
86 adx 270
87     if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime)
88 adx 30 {
89     sendto_one(source_p, form_str(RPL_LOAD2HI),
90     me.name, EmptyString(parv[0]) ? "*" : parv[0]);
91     return;
92     }
93    
94 michael 347 last_used = CurrentTime;
95    
96 adx 30 #ifdef STATIC_MODULES
97     do_admin(client_p);
98     #else
99     execute_callback(admin_cb, source_p, parc, parv);
100     #endif
101     }
102    
103 michael 345 /*! \brief ADMIN command handler (called for local clients only)
104     *
105     * \param client_p Pointer to allocated Client struct with physical connection
106     * to this server, i.e. with an open socket connected.
107     * \param source_p Pointer to allocated Client struct from which the message
108     * originally comes from. This can be a local or remote client.
109     * \param parc Integer holding the number of supplied arguments.
110     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
111     * pointers.
112     * \note Valid arguments for this command are:
113     * - parv[0] = sender prefix
114 michael 347 * - parv[1] = name of target (optional; string can be a nick or server
115     * and can also include wildcards)
116 adx 30 */
117     static void
118     m_admin(struct Client *client_p, struct Client *source_p,
119     int parc, char *parv[])
120     {
121     static time_t last_used = 0;
122    
123 adx 270 if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime)
124 adx 30 {
125     sendto_one(source_p,form_str(RPL_LOAD2HI),
126     me.name, source_p->name);
127     return;
128     }
129    
130 michael 347 last_used = CurrentTime;
131    
132 adx 30 if (!ConfigFileEntry.disable_remote)
133 michael 347 if (hunt_server(client_p, source_p, ":%s ADMIN :%s", 1,
134     parc, parv) != HUNTED_ISME)
135 adx 30 return;
136    
137     #ifdef STATIC_MODULES
138     do_admin(client_p);
139     #else
140     execute_callback(admin_cb, source_p, parc, parv);
141     #endif
142     }
143    
144 michael 345 /*! \brief ADMIN command handler (called for remote clients and servers)
145     *
146     * \param client_p Pointer to allocated Client struct with physical connection
147     * to this server, i.e. with an open socket connected.
148     * \param source_p Pointer to allocated Client struct from which the message
149     * originally comes from. This can be a local or remote client.
150     * \param parc Integer holding the number of supplied arguments.
151     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
152     * pointers.
153     * \note Valid arguments for this command are:
154     * - parv[0] = sender prefix
155 michael 347 * - parv[1] = name of target (optional; string can be a nick or server
156     * and can also include wildcards)
157 adx 30 */
158     static void
159     ms_admin(struct Client *client_p, struct Client *source_p,
160     int parc, char *parv[])
161     {
162 michael 347 if (hunt_server(client_p, source_p, ":%s ADMIN :%s", 1,
163     parc, parv) != HUNTED_ISME)
164 adx 30 return;
165    
166     if (IsClient(source_p))
167     #ifdef STATIC_MODULES
168     do_admin(source_p);
169     #else
170     execute_callback(admin_cb, source_p, parc, parv);
171     #endif
172     }
173    
174     /* do_admin()
175     *
176     * inputs - pointer to client to report to
177     * output - none
178     * side effects - admin info is sent to client given
179     */
180     static void
181     do_admin(struct Client *source_p)
182     {
183     const char *me_name;
184     const char *nick;
185    
186     me_name = ID_or_name(&me, source_p->from);
187     nick = ID_or_name(source_p, source_p->from);
188    
189     sendto_one(source_p, form_str(RPL_ADMINME),
190 michael 347 me_name, nick, me.name);
191 adx 30 if (AdminInfo.name != NULL)
192     sendto_one(source_p, form_str(RPL_ADMINLOC1),
193 michael 347 me_name, nick, AdminInfo.name);
194 adx 30 if (AdminInfo.description != NULL)
195     sendto_one(source_p, form_str(RPL_ADMINLOC2),
196 michael 347 me_name, nick, AdminInfo.description);
197 adx 30 if (AdminInfo.email != NULL)
198     sendto_one(source_p, form_str(RPL_ADMINEMAIL),
199 michael 347 me_name, nick, AdminInfo.email);
200 adx 30 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision