ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_map.c
Revision: 3300
Committed: Sat Apr 12 18:26:22 2014 UTC (12 years, 3 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/modules/m_map.c
File size: 5237 byte(s)
Log Message:
- doxygen

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2820 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 2820 * Copyright (c) 2001-2014 ircd-hybrid development team
5 adx 30 *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19     * USA
20     */
21    
22 michael 2820 /*! \file m_map.c
23     * \brief Includes required functions for processing the MAP command.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28     #include "client.h"
29     #include "modules.h"
30     #include "numeric.h"
31     #include "send.h"
32 michael 1309 #include "conf.h"
33 adx 30 #include "ircd.h"
34 michael 1243 #include "parse.h"
35 adx 30
36 michael 889
37 michael 1851 static void dump_map(struct Client *client,
38     struct Client *server,
39     unsigned int prompt_length)
40 adx 30 {
41 michael 1851 dlink_node *ptr = NULL;
42     struct Client *target_p = NULL;
43     static char prompt[64];
44 michael 2989 static char buf[IRCD_BUFSIZE];
45 michael 1851 char *p = prompt + prompt_length;
46     int cnt = 0;
47 michael 2989 int bufpos = 0;
48 adx 30
49 michael 1851 *p = '\0';
50 adx 30
51 michael 1851 if (prompt_length > 60)
52 michael 3109 sendto_one_numeric(client, &me, RPL_MAPMORE, prompt, server->name);
53 michael 1851 else
54 adx 30 {
55 michael 2989 int dashes;
56 adx 30
57 michael 2989 bufpos += snprintf(buf + bufpos, sizeof(buf) - bufpos, "%s", server->name);
58    
59 michael 1851 if (HasUMode(client, UMODE_OPER) && server->id[0])
60 michael 2989 bufpos += snprintf(buf + bufpos, sizeof(buf) - bufpos, "[%s]", server->id);
61 michael 889
62 michael 2989 buf[bufpos++] = ' ';
63     dashes = 50 - bufpos - prompt_length;
64     for (; dashes > 0; --dashes)
65     buf[bufpos++] = '-';
66     buf[bufpos++] = ' ';
67     buf[bufpos++] = '|';
68    
69     bufpos += snprintf(buf + bufpos, sizeof(buf) - bufpos, " Users %5d (%1.2f%%)",
70     dlink_list_length(&server->serv->client_list), 100 *
71     (float)dlink_list_length(&server->serv->client_list) /
72     (float)Count.total);
73 michael 3109 sendto_one_numeric(client, &me, RPL_MAP, prompt, buf);
74 michael 1851 }
75 michael 889
76 michael 1851 if (prompt_length > 0)
77     {
78     *(p - 1) = ' ';
79 adx 30
80 michael 1851 if (*(p - 2) == '`')
81     *(p - 2) = ' ';
82     }
83 adx 30
84 michael 1851 if (prompt_length > 60)
85     return;
86     strcpy(p, "|-");
87 adx 30
88 michael 1851 DLINK_FOREACH(ptr, server->serv->server_list.head)
89 adx 30 {
90 michael 1851 target_p = ptr->data;
91 adx 30
92 michael 2751 if (IsHidden(target_p) && !HasUMode(client, UMODE_OPER))
93     continue;
94    
95 michael 1851 if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services)
96     if (!HasUMode(client, UMODE_OPER))
97     continue;
98 adx 30
99 michael 1851 ++cnt;
100 adx 30 }
101    
102 michael 1851 DLINK_FOREACH(ptr, server->serv->server_list.head)
103 adx 30 {
104 michael 1851 target_p = ptr->data;
105 adx 30
106 michael 2751 if (IsHidden(target_p) && !HasUMode(client, UMODE_OPER))
107     continue;
108    
109 michael 1851 if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services)
110     if (!HasUMode(client, UMODE_OPER))
111     continue;
112 michael 889
113 michael 1851 if (--cnt == 0)
114     *p = '`';
115     dump_map(client, target_p, prompt_length + 2);
116     }
117 michael 889
118 michael 1851 if (prompt_length > 0)
119     *(p - 1) = '-';
120 adx 30 }
121 michael 1230
122 michael 3266 /*! \brief MAP command handler
123     *
124     * \param source_p Pointer to allocated Client struct from which the message
125     * originally comes from. This can be a local or remote client.
126     * \param parc Integer holding the number of supplied arguments.
127     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
128     * pointers.
129     * \note Valid arguments for this command are:
130     * - parv[0] = command
131 michael 1230 */
132 michael 2820 static int
133 michael 3156 m_map(struct Client *source_p, int parc, char *parv[])
134 michael 1230 {
135     static time_t last_used = 0;
136    
137     if (ConfigServerHide.flatten_links)
138 michael 3156 return m_not_oper(source_p, parc, parv);
139 michael 1230
140     if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
141     {
142 michael 3109 sendto_one_numeric(source_p, &me, RPL_LOAD2HI);
143 michael 2820 return 0;
144 michael 1230 }
145    
146     last_used = CurrentTime;
147    
148 michael 1851 dump_map(source_p, &me, 0);
149 michael 3109 sendto_one_numeric(source_p, &me, RPL_MAPEND);
150 michael 2820 return 0;
151 michael 1230 }
152    
153 michael 3266 /*! \brief MAP command handler
154     *
155     * \param source_p Pointer to allocated Client struct from which the message
156     * originally comes from. This can be a local or remote client.
157     * \param parc Integer holding the number of supplied arguments.
158     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
159     * pointers.
160     * \note Valid arguments for this command are:
161     * - parv[0] = command
162 michael 1230 */
163 michael 2820 static int
164 michael 3156 mo_map(struct Client *source_p, int parc, char *parv[])
165 michael 1230 {
166 michael 1851 dump_map(source_p, &me, 0);
167 michael 3109 sendto_one_numeric(source_p, &me, RPL_MAPEND);
168 michael 2820 return 0;
169 michael 1230 }
170    
171 michael 2820 static struct Message map_msgtab =
172     {
173 michael 1230 "MAP", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
174     { m_unregistered, m_map, m_ignore, m_ignore, mo_map, m_ignore }
175     };
176    
177     static void
178     module_init(void)
179     {
180     mod_add_cmd(&map_msgtab);
181     }
182    
183     static void
184     module_exit(void)
185     {
186     mod_del_cmd(&map_msgtab);
187     }
188    
189 michael 2820 struct module module_entry =
190     {
191 michael 1230 .node = { NULL, NULL, NULL },
192     .name = NULL,
193     .version = "$Revision$",
194     .handle = NULL,
195     .modinit = module_init,
196     .modexit = module_exit,
197     .flags = 0
198     };

Properties

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