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: 8280
Committed: Tue Feb 20 19:30:33 2018 UTC (8 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 5715 byte(s)
Log Message:
- Update copyright years

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 2001-2018 ircd-hybrid development team
5 *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
20 */
21
22 /*! \file m_map.c
23 * \brief Includes required functions for processing the MAP command.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "client.h"
29 #include "modules.h"
30 #include "numeric.h"
31 #include "send.h"
32 #include "conf.h"
33 #include "ircd.h"
34 #include "parse.h"
35
36
37 static void dump_map(struct Client *client,
38 struct Client *server,
39 unsigned int prompt_length)
40 {
41 dlink_node *node;
42 static char prompt[64];
43 char buf[IRCD_BUFSIZE];
44 char *p = prompt + prompt_length;
45 unsigned int cnt = 0;
46
47 *p = '\0';
48
49 if (prompt_length > 60)
50 sendto_one_numeric(client, &me, RPL_MAPMORE, prompt, server->name);
51 else
52 {
53 unsigned int bufpos = snprintf(buf, sizeof(buf), "%s", server->name);
54
55 if (HasUMode(client, UMODE_OPER))
56 bufpos += snprintf(buf + bufpos, sizeof(buf) - bufpos, "[%s]", server->id);
57
58 buf[bufpos++] = ' ';
59
60 for (int dashes = 50 - bufpos - prompt_length; dashes > 0; --dashes)
61 buf[bufpos++] = '-';
62
63 buf[bufpos++] = ' ';
64 buf[bufpos++] = '|';
65
66 bufpos += snprintf(buf + bufpos, sizeof(buf) - bufpos, " Users: %5d (%1.2f%%)",
67 dlink_list_length(&server->serv->client_list), 100 *
68 (float)dlink_list_length(&server->serv->client_list) /
69 (float)dlink_list_length(&global_client_list));
70 sendto_one_numeric(client, &me, RPL_MAP, prompt, buf);
71 }
72
73 if (prompt_length > 0)
74 {
75 *(p - 1) = ' ';
76
77 if (*(p - 2) == '`')
78 *(p - 2) = ' ';
79 }
80
81 if (prompt_length > 60)
82 return;
83 strcpy(p, "|-");
84
85 DLINK_FOREACH(node, server->serv->server_list.head)
86 {
87 struct Client *target_p = node->data;
88
89 if (IsHidden(target_p) && !HasUMode(client, UMODE_OPER))
90 continue;
91
92 if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services)
93 if (!HasUMode(client, UMODE_OPER))
94 continue;
95
96 ++cnt;
97 }
98
99 DLINK_FOREACH(node, server->serv->server_list.head)
100 {
101 struct Client *target_p = node->data;
102
103 if (IsHidden(target_p) && !HasUMode(client, UMODE_OPER))
104 continue;
105
106 if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services)
107 if (!HasUMode(client, UMODE_OPER))
108 continue;
109
110 if (--cnt == 0)
111 *p = '`';
112 dump_map(client, target_p, prompt_length + 2);
113 }
114
115 if (prompt_length > 0)
116 *(p - 1) = '-';
117 }
118
119 /*! \brief Sends a network topology map and notifies irc-operators
120 * about the MAP request
121 *
122 * \param source_p Pointer to client to report to
123 */
124 static void
125 do_map(struct Client *source_p)
126 {
127 sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE,
128 "MAP requested by %s (%s@%s) [%s]",
129 source_p->name, source_p->username,
130 source_p->host, source_p->servptr->name);
131 dump_map(source_p, &me, 0);
132 }
133
134 /*! \brief MAP command handler
135 *
136 * \param source_p Pointer to allocated Client struct from which the message
137 * originally comes from. This can be a local or remote client.
138 * \param parc Integer holding the number of supplied arguments.
139 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
140 * pointers.
141 * \note Valid arguments for this command are:
142 * - parv[0] = command
143 */
144 static int
145 m_map(struct Client *source_p, int parc, char *parv[])
146 {
147 static uintmax_t last_used = 0;
148
149 if (ConfigServerHide.flatten_links)
150 return m_not_oper(source_p, parc, parv);
151
152 if ((last_used + ConfigGeneral.pace_wait) > CurrentTime)
153 {
154 sendto_one_numeric(source_p, &me, RPL_LOAD2HI, "MAP");
155 return 0;
156 }
157
158 last_used = CurrentTime;
159
160 do_map(source_p);
161 sendto_one_numeric(source_p, &me, RPL_MAPEND);
162 return 0;
163 }
164
165 /*! \brief MAP command handler
166 *
167 * \param source_p Pointer to allocated Client struct from which the message
168 * originally comes from. This can be a local or remote client.
169 * \param parc Integer holding the number of supplied arguments.
170 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
171 * pointers.
172 * \note Valid arguments for this command are:
173 * - parv[0] = command
174 */
175 static int
176 mo_map(struct Client *source_p, int parc, char *parv[])
177 {
178 do_map(source_p);
179 sendto_one_numeric(source_p, &me, RPL_MAPEND);
180 return 0;
181 }
182
183 static struct Message map_msgtab =
184 {
185 .cmd = "MAP",
186 .args_max = MAXPARA,
187 .handlers[UNREGISTERED_HANDLER] = m_unregistered,
188 .handlers[CLIENT_HANDLER] = m_map,
189 .handlers[SERVER_HANDLER] = m_ignore,
190 .handlers[ENCAP_HANDLER] = m_ignore,
191 .handlers[OPER_HANDLER] = mo_map
192 };
193
194 static void
195 module_init(void)
196 {
197 mod_add_cmd(&map_msgtab);
198 }
199
200 static void
201 module_exit(void)
202 {
203 mod_del_cmd(&map_msgtab);
204 }
205
206 struct module module_entry =
207 {
208 .version = "$Revision$",
209 .modinit = module_init,
210 .modexit = module_exit,
211 };

Properties

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