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 |
michael |
3641 |
unsigned int cnt = 0; |
47 |
|
|
unsigned 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 |
3345 |
/*! \brief Sends a network topology map and notifies irc-operators |
123 |
|
|
* about the MAP request |
124 |
|
|
* |
125 |
|
|
* \param source_p Pointer to client to report to |
126 |
|
|
*/ |
127 |
|
|
static void |
128 |
|
|
do_map(struct Client *source_p) |
129 |
|
|
{ |
130 |
|
|
sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE, |
131 |
|
|
"MAP requested by %s (%s@%s) [%s]", |
132 |
|
|
source_p->name, source_p->username, |
133 |
|
|
source_p->host, source_p->servptr->name); |
134 |
|
|
dump_map(source_p, &me, 0); |
135 |
|
|
} |
136 |
|
|
|
137 |
michael |
3266 |
/*! \brief MAP command handler |
138 |
|
|
* |
139 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
140 |
|
|
* originally comes from. This can be a local or remote client. |
141 |
|
|
* \param parc Integer holding the number of supplied arguments. |
142 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
143 |
|
|
* pointers. |
144 |
|
|
* \note Valid arguments for this command are: |
145 |
|
|
* - parv[0] = command |
146 |
michael |
1230 |
*/ |
147 |
michael |
2820 |
static int |
148 |
michael |
3156 |
m_map(struct Client *source_p, int parc, char *parv[]) |
149 |
michael |
1230 |
{ |
150 |
|
|
static time_t last_used = 0; |
151 |
|
|
|
152 |
|
|
if (ConfigServerHide.flatten_links) |
153 |
michael |
3156 |
return m_not_oper(source_p, parc, parv); |
154 |
michael |
1230 |
|
155 |
michael |
4340 |
if ((last_used + ConfigGeneral.pace_wait) > CurrentTime) |
156 |
michael |
1230 |
{ |
157 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_LOAD2HI); |
158 |
michael |
2820 |
return 0; |
159 |
michael |
1230 |
} |
160 |
|
|
|
161 |
|
|
last_used = CurrentTime; |
162 |
|
|
|
163 |
michael |
3345 |
do_map(source_p); |
164 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_MAPEND); |
165 |
michael |
2820 |
return 0; |
166 |
michael |
1230 |
} |
167 |
|
|
|
168 |
michael |
3266 |
/*! \brief MAP command handler |
169 |
|
|
* |
170 |
|
|
* \param source_p Pointer to allocated Client struct from which the message |
171 |
|
|
* originally comes from. This can be a local or remote client. |
172 |
|
|
* \param parc Integer holding the number of supplied arguments. |
173 |
|
|
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
174 |
|
|
* pointers. |
175 |
|
|
* \note Valid arguments for this command are: |
176 |
|
|
* - parv[0] = command |
177 |
michael |
1230 |
*/ |
178 |
michael |
2820 |
static int |
179 |
michael |
3156 |
mo_map(struct Client *source_p, int parc, char *parv[]) |
180 |
michael |
1230 |
{ |
181 |
michael |
3345 |
do_map(source_p); |
182 |
michael |
3109 |
sendto_one_numeric(source_p, &me, RPL_MAPEND); |
183 |
michael |
2820 |
return 0; |
184 |
michael |
1230 |
} |
185 |
|
|
|
186 |
michael |
2820 |
static struct Message map_msgtab = |
187 |
|
|
{ |
188 |
michael |
1230 |
"MAP", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
189 |
|
|
{ m_unregistered, m_map, m_ignore, m_ignore, mo_map, m_ignore } |
190 |
|
|
}; |
191 |
|
|
|
192 |
|
|
static void |
193 |
|
|
module_init(void) |
194 |
|
|
{ |
195 |
|
|
mod_add_cmd(&map_msgtab); |
196 |
|
|
} |
197 |
|
|
|
198 |
|
|
static void |
199 |
|
|
module_exit(void) |
200 |
|
|
{ |
201 |
|
|
mod_del_cmd(&map_msgtab); |
202 |
|
|
} |
203 |
|
|
|
204 |
michael |
2820 |
struct module module_entry = |
205 |
|
|
{ |
206 |
michael |
1230 |
.node = { NULL, NULL, NULL }, |
207 |
|
|
.name = NULL, |
208 |
|
|
.version = "$Revision$", |
209 |
|
|
.handle = NULL, |
210 |
|
|
.modinit = module_init, |
211 |
|
|
.modexit = module_exit, |
212 |
|
|
.flags = 0 |
213 |
|
|
}; |