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: 8751
Committed: Tue Jan 1 11:06:50 2019 UTC (7 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 5727 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-2019 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)
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))
90 if (!HasUMode(client, UMODE_OPER))
91 continue;
92
93 if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services)
94 if (!HasUMode(client, UMODE_OPER))
95 continue;
96
97 ++cnt;
98 }
99
100 DLINK_FOREACH(node, server->serv->server_list.head)
101 {
102 struct Client *target_p = node->data;
103
104 if (IsHidden(target_p))
105 if (!HasUMode(client, UMODE_OPER))
106 continue;
107
108 if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services)
109 if (!HasUMode(client, UMODE_OPER))
110 continue;
111
112 if (--cnt == 0)
113 *p = '`';
114 dump_map(client, target_p, prompt_length + 2);
115 }
116
117 if (prompt_length)
118 *(p - 1) = '-';
119 }
120
121 /*! \brief Sends a network topology map and notifies irc-operators
122 * about the MAP request
123 *
124 * \param source_p Pointer to client to report to
125 */
126 static void
127 do_map(struct Client *source_p)
128 {
129 sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE,
130 "MAP requested by %s (%s@%s) [%s]",
131 source_p->name, source_p->username,
132 source_p->host, source_p->servptr->name);
133 dump_map(source_p, &me, 0);
134 }
135
136 /*! \brief MAP command handler
137 *
138 * \param source_p Pointer to allocated Client struct from which the message
139 * originally comes from. This can be a local or remote client.
140 * \param parc Integer holding the number of supplied arguments.
141 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
142 * pointers.
143 * \note Valid arguments for this command are:
144 * - parv[0] = command
145 */
146 static int
147 m_map(struct Client *source_p, int parc, char *parv[])
148 {
149 static uintmax_t last_used = 0;
150
151 if (ConfigServerHide.flatten_links)
152 return m_not_oper(source_p, parc, parv);
153
154 if ((last_used + ConfigGeneral.pace_wait) > CurrentTime)
155 {
156 sendto_one_numeric(source_p, &me, RPL_LOAD2HI, "MAP");
157 return 0;
158 }
159
160 last_used = CurrentTime;
161
162 do_map(source_p);
163 sendto_one_numeric(source_p, &me, RPL_MAPEND);
164 return 0;
165 }
166
167 /*! \brief MAP command handler
168 *
169 * \param source_p Pointer to allocated Client struct from which the message
170 * originally comes from. This can be a local or remote client.
171 * \param parc Integer holding the number of supplied arguments.
172 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
173 * pointers.
174 * \note Valid arguments for this command are:
175 * - parv[0] = command
176 */
177 static int
178 mo_map(struct Client *source_p, int parc, char *parv[])
179 {
180 do_map(source_p);
181 sendto_one_numeric(source_p, &me, RPL_MAPEND);
182 return 0;
183 }
184
185 static struct Message map_msgtab =
186 {
187 .cmd = "MAP",
188 .args_max = MAXPARA,
189 .handlers[UNREGISTERED_HANDLER] = m_unregistered,
190 .handlers[CLIENT_HANDLER] = m_map,
191 .handlers[SERVER_HANDLER] = m_ignore,
192 .handlers[ENCAP_HANDLER] = m_ignore,
193 .handlers[OPER_HANDLER] = mo_map
194 };
195
196 static void
197 module_init(void)
198 {
199 mod_add_cmd(&map_msgtab);
200 }
201
202 static void
203 module_exit(void)
204 {
205 mod_del_cmd(&map_msgtab);
206 }
207
208 struct module module_entry =
209 {
210 .version = "$Revision$",
211 .modinit = module_init,
212 .modexit = module_exit,
213 };

Properties

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